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
|
// AddStackLabel returns labels with the namespace label added
|
||||||
func AddStackLabel(namespace Namespace, labels map[string]string) map[string]string {
|
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 {
|
if labels == nil {
|
||||||
labels = make(map[string]string)
|
labels = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
@ -67,7 +72,7 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
|
||||||
}
|
}
|
||||||
|
|
||||||
createOpts := client.NetworkCreateOptions{
|
createOpts := client.NetworkCreateOptions{
|
||||||
Labels: AddStackLabel(namespace, nw.Labels),
|
Labels: addStackLabel(namespace, nw.Labels),
|
||||||
Driver: nw.Driver,
|
Driver: nw.Driver,
|
||||||
Options: nw.DriverOpts,
|
Options: nw.DriverOpts,
|
||||||
Internal: nw.Internal,
|
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 {
|
if nw.Ipam.Driver != "" || len(nw.Ipam.Config) > 0 {
|
||||||
createOpts.IPAM = &network.IPAM{}
|
createOpts.IPAM = &network.IPAM{
|
||||||
}
|
Driver: nw.Ipam.Driver,
|
||||||
|
}
|
||||||
if nw.Ipam.Driver != "" {
|
for _, ipamConfig := range nw.Ipam.Config {
|
||||||
createOpts.IPAM.Driver = nw.Ipam.Driver
|
createOpts.IPAM.Config = append(createOpts.IPAM.Config, network.IPAMConfig{
|
||||||
}
|
Subnet: ipamConfig.Subnet,
|
||||||
for _, ipamConfig := range nw.Ipam.Config {
|
})
|
||||||
config := network.IPAMConfig{
|
|
||||||
Subnet: ipamConfig.Subnet,
|
|
||||||
}
|
}
|
||||||
createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
networkName := namespace.Scope(internalName)
|
networkName := nw.Name
|
||||||
if nw.Name != "" {
|
if nw.Name == "" {
|
||||||
networkName = nw.Name
|
networkName = namespace.Scope(internalName)
|
||||||
}
|
}
|
||||||
result[networkName] = createOpts
|
result[networkName] = createOpts
|
||||||
}
|
}
|
||||||
|
@ -171,7 +173,7 @@ func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileO
|
||||||
return swarmFileObject{
|
return swarmFileObject{
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: name,
|
Name: name,
|
||||||
Labels: AddStackLabel(namespace, obj.Labels),
|
Labels: addStackLabel(namespace, obj.Labels),
|
||||||
},
|
},
|
||||||
Data: []byte{},
|
Data: []byte{},
|
||||||
}
|
}
|
||||||
|
@ -192,7 +194,7 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
|
||||||
return swarmFileObject{
|
return swarmFileObject{
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: name,
|
Name: name,
|
||||||
Labels: AddStackLabel(namespace, obj.Labels),
|
Labels: addStackLabel(namespace, obj.Labels),
|
||||||
},
|
},
|
||||||
Data: data,
|
Data: data,
|
||||||
}, nil
|
}, nil
|
||||||
|
|
|
@ -30,7 +30,7 @@ func TestAddStackLabel(t *testing.T) {
|
||||||
labels := map[string]string{
|
labels := map[string]string{
|
||||||
"something": "labeled",
|
"something": "labeled",
|
||||||
}
|
}
|
||||||
actual := AddStackLabel(Namespace{name: "foo"}, labels)
|
actual := addStackLabel(Namespace{name: "foo"}, labels)
|
||||||
expected := map[string]string{
|
expected := map[string]string{
|
||||||
"something": "labeled",
|
"something": "labeled",
|
||||||
LabelNamespace: "foo",
|
LabelNamespace: "foo",
|
||||||
|
|
|
@ -119,7 +119,7 @@ func Service(
|
||||||
serviceSpec := swarm.ServiceSpec{
|
serviceSpec := swarm.ServiceSpec{
|
||||||
Annotations: swarm.Annotations{
|
Annotations: swarm.Annotations{
|
||||||
Name: name,
|
Name: name,
|
||||||
Labels: AddStackLabel(namespace, service.Deploy.Labels),
|
Labels: addStackLabel(namespace, service.Deploy.Labels),
|
||||||
},
|
},
|
||||||
TaskTemplate: swarm.TaskSpec{
|
TaskTemplate: swarm.TaskSpec{
|
||||||
ContainerSpec: &swarm.ContainerSpec{
|
ContainerSpec: &swarm.ContainerSpec{
|
||||||
|
@ -131,7 +131,7 @@ func Service(
|
||||||
DNSConfig: dnsConfig,
|
DNSConfig: dnsConfig,
|
||||||
Healthcheck: healthcheck,
|
Healthcheck: healthcheck,
|
||||||
Env: convertEnvironment(service.Environment),
|
Env: convertEnvironment(service.Environment),
|
||||||
Labels: AddStackLabel(namespace, service.Labels),
|
Labels: addStackLabel(namespace, service.Labels),
|
||||||
Dir: service.WorkingDir,
|
Dir: service.WorkingDir,
|
||||||
User: service.User,
|
User: service.User,
|
||||||
Mounts: mounts,
|
Mounts: mounts,
|
||||||
|
|
|
@ -80,7 +80,7 @@ func handleVolumeToMount(
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
result.VolumeOptions.Labels = AddStackLabel(namespace, stackVolume.Labels)
|
result.VolumeOptions.Labels = addStackLabel(namespace, stackVolume.Labels)
|
||||||
if stackVolume.Driver != "" || stackVolume.DriverOpts != nil {
|
if stackVolume.Driver != "" || stackVolume.DriverOpts != nil {
|
||||||
result.VolumeOptions.DriverConfig = &mount.Driver{
|
result.VolumeOptions.DriverConfig = &mount.Driver{
|
||||||
Name: stackVolume.Driver,
|
Name: stackVolume.Driver,
|
||||||
|
|
Loading…
Reference in New Issue