Skip to content

Commit 580c3aa

Browse files
committed
cli/compose/convert: Networks: use struct-literal for IPAM config
Use a struct-literal for the IPAM config, and combine some of the checks. Also use the Name field as a default, and only construct a scoped name if the given name is empty (instead of the reverse). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent f8d33f4 commit 580c3aa

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

cli/compose/convert/compose.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,19 @@ func Networks(namespace Namespace, networks networkMap, servicesNetworks map[str
8080
}
8181

8282
if nw.Ipam.Driver != "" || len(nw.Ipam.Config) > 0 {
83-
createOpts.IPAM = &network.IPAM{}
84-
}
85-
86-
if nw.Ipam.Driver != "" {
87-
createOpts.IPAM.Driver = nw.Ipam.Driver
88-
}
89-
for _, ipamConfig := range nw.Ipam.Config {
90-
config := network.IPAMConfig{
91-
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+
})
9290
}
93-
createOpts.IPAM.Config = append(createOpts.IPAM.Config, config)
9491
}
9592

96-
networkName := namespace.Scope(internalName)
97-
if nw.Name != "" {
98-
networkName = nw.Name
93+
networkName := nw.Name
94+
if nw.Name == "" {
95+
networkName = namespace.Scope(internalName)
9996
}
10097
result[networkName] = createOpts
10198
}

0 commit comments

Comments
 (0)