Add compose support of attachable in networks

This fix tries to address the issue raised in 29975 where
it was not possible to specify `attachable` flag for networks
in compose format.

NOTE: Compose format aleady supports `labels` in networks.

This fix adds the support of `attachable` for compose v3.1 format.

Additiona unit tests have been updated and added.

This fix fixes 29975.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
Yong Tang
2017-02-04 13:55:28 -08:00
parent bba31c3f04
commit 1a677699ae
6 changed files with 50 additions and 9 deletions

View File

@ -61,10 +61,11 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
}
createOpts := types.NetworkCreate{
Labels: AddStackLabel(namespace, network.Labels),
Driver: network.Driver,
Options: network.DriverOpts,
Internal: network.Internal,
Labels: AddStackLabel(namespace, network.Labels),
Driver: network.Driver,
Options: network.DriverOpts,
Internal: network.Internal,
Attachable: network.Attachable,
}
if network.Ipam.Driver != "" || len(network.Ipam.Config) > 0 {

View File

@ -30,9 +30,10 @@ func TestAddStackLabel(t *testing.T) {
func TestNetworks(t *testing.T) {
namespace := Namespace{name: "foo"}
serviceNetworks := map[string]struct{}{
"normal": {},
"outside": {},
"default": {},
"normal": {},
"outside": {},
"default": {},
"attachablenet": {},
}
source := networkMap{
"normal": composetypes.NetworkConfig{
@ -58,6 +59,10 @@ func TestNetworks(t *testing.T) {
Name: "special",
},
},
"attachablenet": composetypes.NetworkConfig{
Driver: "overlay",
Attachable: true,
},
}
expected := map[string]types.NetworkCreate{
"default": {
@ -83,6 +88,13 @@ func TestNetworks(t *testing.T) {
"something": "labeled",
},
},
"attachablenet": {
Driver: "overlay",
Attachable: true,
Labels: map[string]string{
LabelNamespace: "foo",
},
},
}
networks, externals := Networks(namespace, source, serviceNetworks)