Fix named network in compose file

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin
2018-03-12 15:15:27 -04:00
parent ca88e5e9df
commit b4c108a385
6 changed files with 60 additions and 11 deletions
+6 -1
View File
@@ -87,7 +87,12 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
}
createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
}
result[internalName] = createOpts
networkName := namespace.Scope(internalName)
if network.Name != "" {
networkName = network.Name
}
result[networkName] = createOpts
}
return result, externalNetworks
+12 -5
View File
@@ -35,6 +35,7 @@ func TestNetworks(t *testing.T) {
"outside": {},
"default": {},
"attachablenet": {},
"named": {},
}
source := networkMap{
"normal": composetypes.NetworkConfig{
@@ -62,14 +63,17 @@ func TestNetworks(t *testing.T) {
Driver: "overlay",
Attachable: true,
},
"named": composetypes.NetworkConfig{
Name: "othername",
},
}
expected := map[string]types.NetworkCreate{
"default": {
"foo_default": {
Labels: map[string]string{
LabelNamespace: "foo",
},
},
"normal": {
"foo_normal": {
Driver: "overlay",
IPAM: &network.IPAM{
Driver: "driver",
@@ -87,18 +91,21 @@ func TestNetworks(t *testing.T) {
"something": "labeled",
},
},
"attachablenet": {
"foo_attachablenet": {
Driver: "overlay",
Attachable: true,
Labels: map[string]string{
LabelNamespace: "foo",
},
},
"othername": {
Labels: map[string]string{LabelNamespace: "foo"},
},
}
networks, externals := Networks(namespace, source, serviceNetworks)
assert.Check(t, is.DeepEqual(expected, networks))
assert.Check(t, is.DeepEqual([]string{"special"}, externals))
assert.DeepEqual(t, expected, networks)
assert.DeepEqual(t, []string{"special"}, externals)
}
func TestSecrets(t *testing.T) {
+1 -1
View File
@@ -229,7 +229,7 @@ func convertServiceNetworks(
aliases = network.Aliases
}
target := namespace.Scope(networkName)
if networkConfig.External.External {
if networkConfig.Name != "" {
target = networkConfig.Name
}
netAttachConfig := swarm.NetworkAttachmentConfig{
+38
View File
@@ -10,6 +10,7 @@ import (
"time"
"github.com/docker/cli/cli/compose/types"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/sirupsen/logrus"
@@ -1357,3 +1358,40 @@ networks:
assert.ErrorContains(t, err, "network.external.name and network.name conflict; only use network.name")
assert.ErrorContains(t, err, "foo")
}
func TestLoadNetworkWithName(t *testing.T) {
config, err := loadYAML(`
version: '3.5'
services:
hello-world:
image: redis:alpine
networks:
- network1
- network3
networks:
network1:
name: network2
network3:
`)
assert.NilError(t, err)
expected := &types.Config{
Filename: "filename.yml",
Version: "3.5",
Services: types.Services{
{
Name: "hello-world",
Image: "redis:alpine",
Networks: map[string]*types.ServiceNetworkConfig{
"network1": nil,
"network3": nil,
},
},
},
Networks: map[string]types.NetworkConfig{
"network1": {Name: "network2"},
"network3": {},
},
}
assert.DeepEqual(t, config, expected, cmpopts.EquateEmpty())
}