@@ -42,6 +42,11 @@ func NewNamespace(name string) Namespace {
4242
4343// AddStackLabel returns labels with the namespace label added
4444func 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,30 +72,27 @@ 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 ,
7479 Attachable : nw .Attachable ,
7580 }
7681
7782 if nw .Ipam .Driver != "" || len (nw .Ipam .Config ) > 0 {
78- createOpts .IPAM = & network.IPAM {}
79- }
80-
81- if nw .Ipam .Driver != "" {
82- createOpts .IPAM .Driver = nw .Ipam .Driver
83- }
84- for _ , ipamConfig := range nw .Ipam .Config {
85- config := network.IPAMConfig {
86- Subnet : ipamConfig .Subnet ,
83+ createOpts .IPAM = & network.IPAM {
84+ Driver : nw .Ipam .Driver ,
85+ }
86+ for _ , ipamConfig := range nw .Ipam .Config {
87+ createOpts .IPAM .Config = append (createOpts .IPAM .Config , network.IPAMConfig {
88+ Subnet : ipamConfig .Subnet ,
89+ })
8790 }
88- createOpts .IPAM .Config = append (createOpts .IPAM .Config , config )
8991 }
9092
91- networkName := namespace . Scope ( internalName )
92- if nw .Name ! = "" {
93- networkName = nw . Name
93+ networkName := nw . Name
94+ if nw .Name = = "" {
95+ networkName = namespace . Scope ( internalName )
9496 }
9597 result [networkName ] = createOpts
9698 }
@@ -171,7 +173,7 @@ func driverObjectConfig(namespace Namespace, name string, obj composetypes.FileO
171173 return swarmFileObject {
172174 Annotations : swarm.Annotations {
173175 Name : name ,
174- Labels : AddStackLabel (namespace , obj .Labels ),
176+ Labels : addStackLabel (namespace , obj .Labels ),
175177 },
176178 Data : []byte {},
177179 }
@@ -192,7 +194,7 @@ func fileObjectConfig(namespace Namespace, name string, obj composetypes.FileObj
192194 return swarmFileObject {
193195 Annotations : swarm.Annotations {
194196 Name : name ,
195- Labels : AddStackLabel (namespace , obj .Labels ),
197+ Labels : addStackLabel (namespace , obj .Labels ),
196198 },
197199 Data : data ,
198200 }, nil
0 commit comments