mirror of https://github.com/docker/cli.git
Merge pull request #6397 from thaJeztah/compose_clean
cli/compose/convert: split exported AddStackLabel from implementation
This commit is contained in:
commit
5dd52a9efa
|
@ -42,6 +42,11 @@ func NewNamespace(name string) Namespace {
|
|||
|
||||
// AddStackLabel returns labels with the namespace label added
|
||||
func AddStackLabel(namespace Namespace, labels map[string]string) map[string]string {
|
||||
return addStackLabel(namespace, labels)
|
||||
}
|
||||
|
||||
// addStackLabel returns labels with the namespace label added
|
||||
func addStackLabel(namespace Namespace, labels map[string]string) map[string]string {
|
||||
if labels == nil {
|
||||
labels = make(map[string]string)
|
||||
}
|
||||
|
@ -67,7 +72,7 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
|
|||
}
|
||||
|
||||
createOpts := client.NetworkCreateOptions{
|
||||
Labels: AddStackLabel(namespace, nw.Labels),
|
||||
Labels: addStackLabel(namespace, nw.Labels),
|
||||
Driver: nw.Driver,
|
||||
Options: nw.DriverOpts,
|
||||
Internal: nw.Internal,
|
||||
|
@ -75,22 +80,19 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
|
|||
}
|
||||
|
||||
if nw.Ipam.Driver != "" || len(nw.Ipam.Config) > 0 {
|
||||
createOpts.IPAM = &network.IPAM{}
|
||||
}
|
||||
|
||||
if nw.Ipam.Driver != "" {
|
||||
createOpts.IPAM.Driver = nw.Ipam.Driver
|
||||
createOpts.IPAM = &network.IPAM{
|
||||
Driver: nw.Ipam.Driver,
|
||||
}
|
||||
for _, ipamConfig := range nw.Ipam.Config {
|
||||
config := network.IPAMConfig{
|
||||
createOpts.IPAM.Config = append(createOpts.IPAM.Config, network.IPAMConfig{
|
||||
Subnet: ipamConfig.Subnet,
|
||||
})
|
||||
}
|
||||
createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
|
||||
}
|
||||
|
||||
networkName := namespace.Scope(internalName)
|
||||
if nw.Name != "" {
|
||||
networkName = nw.Name
|
||||
networkName := nw.Name
|
||||
if nw.Name == "" {
|
||||
networkName = namespace.Scope(internalName)
|
||||
}
|
||||
result[networkName] = createOpts
|
||||
}
|
||||
|
@ -171,7 +173,7 @@ func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileO
|
|||
return swarmFileObject{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: name,
|
||||
Labels: AddStackLabel(namespace, obj.Labels),
|
||||
Labels: addStackLabel(namespace, obj.Labels),
|
||||
},
|
||||
Data: []byte{},
|
||||
}
|
||||
|
@ -192,7 +194,7 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
|
|||
return swarmFileObject{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: name,
|
||||
Labels: AddStackLabel(namespace, obj.Labels),
|
||||
Labels: addStackLabel(namespace, obj.Labels),
|
||||
},
|
||||
Data: data,
|
||||
}, nil
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestAddStackLabel(t *testing.T) {
|
|||
labels := map[string]string{
|
||||
"something": "labeled",
|
||||
}
|
||||
actual := AddStackLabel(Namespace{name: "foo"}, labels)
|
||||
actual := addStackLabel(Namespace{name: "foo"}, labels)
|
||||
expected := map[string]string{
|
||||
"something": "labeled",
|
||||
LabelNamespace: "foo",
|
||||
|
|
|
@ -119,7 +119,7 @@ func Service(
|
|||
serviceSpec := swarm.ServiceSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
Name: name,
|
||||
Labels: AddStackLabel(namespace, service.Deploy.Labels),
|
||||
Labels: addStackLabel(namespace, service.Deploy.Labels),
|
||||
},
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{
|
||||
|
@ -131,7 +131,7 @@ func Service(
|
|||
DNSConfig: dnsConfig,
|
||||
Healthcheck: healthcheck,
|
||||
Env: convertEnvironment(service.Environment),
|
||||
Labels: AddStackLabel(namespace, service.Labels),
|
||||
Labels: addStackLabel(namespace, service.Labels),
|
||||
Dir: service.WorkingDir,
|
||||
User: service.User,
|
||||
Mounts: mounts,
|
||||
|
|
|
@ -80,7 +80,7 @@ func handleVolumeToMount(
|
|||
return result, nil
|
||||
}
|
||||
|
||||
result.VolumeOptions.Labels = AddStackLabel(namespace, stackVolume.Labels)
|
||||
result.VolumeOptions.Labels = addStackLabel(namespace, stackVolume.Labels)
|
||||
if stackVolume.Driver != "" || stackVolume.DriverOpts != nil {
|
||||
result.VolumeOptions.DriverConfig = &mount.Driver{
|
||||
Name: stackVolume.Driver,
|
||||
|
|
Loading…
Reference in New Issue