From 36eb40263d90dfc726bb00e9bf21fd7f1330855f Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Thu, 3 Nov 2016 17:40:48 -0600 Subject: [PATCH] Always use a default network if no other networks are set. also add network labels. Signed-off-by: Daniel Nephin Upstream-commit: 644d30369a348db4d904d86958c2b57a0de36990 Component: engine --- components/engine/cli/command/stack/deploy.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/engine/cli/command/stack/deploy.go b/components/engine/cli/command/stack/deploy.go index b92662c3c5..bb3e73e6e1 100644 --- a/components/engine/cli/command/stack/deploy.go +++ b/components/engine/cli/command/stack/deploy.go @@ -150,6 +150,9 @@ func createNetworks( existingNetworkMap[network.Name] = network } + // TODO: only add default network if it's used + networks["default"] = composetypes.NetworkConfig{} + for internalName, network := range networks { if network.External.Name != "" { continue @@ -161,8 +164,7 @@ func createNetworks( } createOpts := types.NetworkCreate{ - // TODO: support network labels from compose file - Labels: getStackLabels(namespace, nil), + Labels: getStackLabels(namespace, network.Labels), Driver: network.Driver, Options: network.DriverOpts, } @@ -191,6 +193,16 @@ func convertNetworks( namespace string, name string, ) []swarm.NetworkAttachmentConfig { + if len(networks) == 0 { + return []swarm.NetworkAttachmentConfig{ + { + // TODO: only do this name mangling in one function + Target: namespace + "_" + "default", + Aliases: []string{name}, + }, + } + } + nets := []swarm.NetworkAttachmentConfig{} for networkName, network := range networks { nets = append(nets, swarm.NetworkAttachmentConfig{