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>
This commit is contained in:
Sebastiaan van Stijn
2025-08-29 14:31:50 +02:00
parent f8d33f4602
commit 580c3aa218

View File

@ -80,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
}
for _, ipamConfig := range nw.Ipam.Config {
config := network.IPAMConfig{
Subnet: ipamConfig.Subnet,
createOpts.IPAM = &network.IPAM{
Driver: nw.Ipam.Driver,
}
for _, ipamConfig := range nw.Ipam.Config {
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
}