mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #29994 from vdemeester/29974-fix-external-network
[1.13.x] Few stack deploy network fixes
This commit is contained in:
commit
25879cfa54
1 changed files with 21 additions and 9 deletions
|
@ -9,9 +9,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"golang.org/x/net/context"
|
|
||||||
|
|
||||||
"github.com/aanand/compose-file/loader"
|
"github.com/aanand/compose-file/loader"
|
||||||
composetypes "github.com/aanand/compose-file/types"
|
composetypes "github.com/aanand/compose-file/types"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
|
@ -25,6 +22,8 @@ import (
|
||||||
"github.com/docker/docker/opts"
|
"github.com/docker/docker/opts"
|
||||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -123,7 +122,8 @@ func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deplo
|
||||||
|
|
||||||
namespace := namespace{name: opts.namespace}
|
namespace := namespace{name: opts.namespace}
|
||||||
|
|
||||||
networks, externalNetworks := convertNetworks(namespace, config.Networks)
|
serviceNetworks := getServicesDeclaredNetworks(config.Services)
|
||||||
|
networks, externalNetworks := convertNetworks(namespace, config.Networks, serviceNetworks)
|
||||||
if err := validateExternalNetworks(ctx, dockerCli, externalNetworks); err != nil {
|
if err := validateExternalNetworks(ctx, dockerCli, externalNetworks); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -136,6 +136,19 @@ func deployCompose(ctx context.Context, dockerCli *command.DockerCli, opts deplo
|
||||||
}
|
}
|
||||||
return deployServices(ctx, dockerCli, services, namespace, opts.sendRegistryAuth)
|
return deployServices(ctx, dockerCli, services, namespace, opts.sendRegistryAuth)
|
||||||
}
|
}
|
||||||
|
func getServicesDeclaredNetworks(serviceConfigs []composetypes.ServiceConfig) map[string]struct{} {
|
||||||
|
serviceNetworks := map[string]struct{}{}
|
||||||
|
for _, serviceConfig := range serviceConfigs {
|
||||||
|
if len(serviceConfig.Networks) == 0 {
|
||||||
|
serviceNetworks["default"] = struct{}{}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for network := range serviceConfig.Networks {
|
||||||
|
serviceNetworks[network] = struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return serviceNetworks
|
||||||
|
}
|
||||||
|
|
||||||
func propertyWarnings(properties map[string]string) string {
|
func propertyWarnings(properties map[string]string) string {
|
||||||
var msgs []string
|
var msgs []string
|
||||||
|
@ -182,18 +195,17 @@ func getConfigFile(filename string) (*composetypes.ConfigFile, error) {
|
||||||
func convertNetworks(
|
func convertNetworks(
|
||||||
namespace namespace,
|
namespace namespace,
|
||||||
networks map[string]composetypes.NetworkConfig,
|
networks map[string]composetypes.NetworkConfig,
|
||||||
|
servicesNetworks map[string]struct{},
|
||||||
) (map[string]types.NetworkCreate, []string) {
|
) (map[string]types.NetworkCreate, []string) {
|
||||||
if networks == nil {
|
if networks == nil {
|
||||||
networks = make(map[string]composetypes.NetworkConfig)
|
networks = make(map[string]composetypes.NetworkConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: only add default network if it's used
|
|
||||||
networks["default"] = composetypes.NetworkConfig{}
|
|
||||||
|
|
||||||
externalNetworks := []string{}
|
externalNetworks := []string{}
|
||||||
result := make(map[string]types.NetworkCreate)
|
result := make(map[string]types.NetworkCreate)
|
||||||
|
|
||||||
for internalName, network := range networks {
|
for internalName := range servicesNetworks {
|
||||||
|
network := networks[internalName]
|
||||||
if network.External.External {
|
if network.External.External {
|
||||||
externalNetworks = append(externalNetworks, network.External.Name)
|
externalNetworks = append(externalNetworks, network.External.Name)
|
||||||
continue
|
continue
|
||||||
|
@ -310,7 +322,7 @@ func convertServiceNetworks(
|
||||||
}
|
}
|
||||||
target := namespace.scope(networkName)
|
target := namespace.scope(networkName)
|
||||||
if networkConfig.External.External {
|
if networkConfig.External.External {
|
||||||
target = networkName
|
target = networkConfig.External.Name
|
||||||
}
|
}
|
||||||
nets = append(nets, swarm.NetworkAttachmentConfig{
|
nets = append(nets, swarm.NetworkAttachmentConfig{
|
||||||
Target: target,
|
Target: target,
|
||||||
|
|
Loading…
Add table
Reference in a new issue