Skip to content

Commit

Permalink
Merge pull request moby#30742 from yongtang/29975-compose-network-att…
Browse files Browse the repository at this point in the history
…achable

Add compose support of `attachable` in networks
  • Loading branch information
LK4D4 authored Feb 6, 2017
2 parents 0113128 + cf4b7a5 commit e06ae6f
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 9 deletions.
9 changes: 5 additions & 4 deletions cli/compose/convert/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 15 additions & 3 deletions cli/compose/convert/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -58,6 +59,10 @@ func TestNetworks(t *testing.T) {
Name: "special",
},
},
"attachablenet": composetypes.NetworkConfig{
Driver: "overlay",
Attachable: true,
},
}
expected := map[string]types.NetworkCreate{
"default": {
Expand All @@ -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)
Expand Down
26 changes: 26 additions & 0 deletions cli/compose/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,29 @@ type servicesByName []types.ServiceConfig
func (sbn servicesByName) Len() int { return len(sbn) }
func (sbn servicesByName) Swap(i, j int) { sbn[i], sbn[j] = sbn[j], sbn[i] }
func (sbn servicesByName) Less(i, j int) bool { return sbn[i].Name < sbn[j].Name }

func TestLoadAttachableNetwork(t *testing.T) {
config, err := loadYAML(`
version: "3.1"
networks:
mynet1:
driver: overlay
attachable: true
mynet2:
driver: bridge
`)
assert.NoError(t, err)

expected := map[string]types.NetworkConfig{
"mynet1": {
Driver: "overlay",
Attachable: true,
},
"mynet2": {
Driver: "bridge",
Attachable: false,
},
}

assert.Equal(t, expected, config.Networks)
}
Loading

0 comments on commit e06ae6f

Please sign in to comment.