Skip to content

Commit f8d33f4

Browse files
committed
cli/compose/convert: split exported AddStackLabel from implementation
This function is currently only used within the package; create a non-exported version of it, to make it clear it's not used elsewhere. This patch keeps the exported function for now, but we can decide if we need to keep it in future. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b3cd9d4 commit f8d33f4

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

cli/compose/convert/compose.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func NewNamespace(name string) Namespace {
4242

4343
// AddStackLabel returns labels with the namespace label added
4444
func AddStackLabel(namespace Namespace, labels map[string]string) map[string]string {
45+
return addStackLabel(namespace, labels)
46+
}
47+
48+
// addStackLabel returns labels with the namespace label added
49+
func addStackLabel(namespace Namespace, labels map[string]string) map[string]string {
4550
if labels == nil {
4651
labels = make(map[string]string)
4752
}
@@ -67,7 +72,7 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
6772
}
6873

6974
createOpts := client.NetworkCreateOptions{
70-
Labels: AddStackLabel(namespace, nw.Labels),
75+
Labels: addStackLabel(namespace, nw.Labels),
7176
Driver: nw.Driver,
7277
Options: nw.DriverOpts,
7378
Internal: nw.Internal,
@@ -171,7 +176,7 @@ func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileO
171176
return swarmFileObject{
172177
Annotations: swarm.Annotations{
173178
Name: name,
174-
Labels: AddStackLabel(namespace, obj.Labels),
179+
Labels: addStackLabel(namespace, obj.Labels),
175180
},
176181
Data: []byte{},
177182
}
@@ -192,7 +197,7 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
192197
return swarmFileObject{
193198
Annotations: swarm.Annotations{
194199
Name: name,
195-
Labels: AddStackLabel(namespace, obj.Labels),
200+
Labels: addStackLabel(namespace, obj.Labels),
196201
},
197202
Data: data,
198203
}, nil

cli/compose/convert/compose_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestAddStackLabel(t *testing.T) {
3030
labels := map[string]string{
3131
"something": "labeled",
3232
}
33-
actual := AddStackLabel(Namespace{name: "foo"}, labels)
33+
actual := addStackLabel(Namespace{name: "foo"}, labels)
3434
expected := map[string]string{
3535
"something": "labeled",
3636
LabelNamespace: "foo",

cli/compose/convert/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func Service(
119119
serviceSpec := swarm.ServiceSpec{
120120
Annotations: swarm.Annotations{
121121
Name: name,
122-
Labels: AddStackLabel(namespace, service.Deploy.Labels),
122+
Labels: addStackLabel(namespace, service.Deploy.Labels),
123123
},
124124
TaskTemplate: swarm.TaskSpec{
125125
ContainerSpec: &swarm.ContainerSpec{
@@ -131,7 +131,7 @@ func Service(
131131
DNSConfig: dnsConfig,
132132
Healthcheck: healthcheck,
133133
Env: convertEnvironment(service.Environment),
134-
Labels: AddStackLabel(namespace, service.Labels),
134+
Labels: addStackLabel(namespace, service.Labels),
135135
Dir: service.WorkingDir,
136136
User: service.User,
137137
Mounts: mounts,

cli/compose/convert/volume.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func handleVolumeToMount(
8080
return result, nil
8181
}
8282

83-
result.VolumeOptions.Labels = AddStackLabel(namespace, stackVolume.Labels)
83+
result.VolumeOptions.Labels = addStackLabel(namespace, stackVolume.Labels)
8484
if stackVolume.Driver != "" || stackVolume.DriverOpts != nil {
8585
result.VolumeOptions.DriverConfig = &mount.Driver{
8686
Name: stackVolume.Driver,

0 commit comments

Comments
 (0)