Skip to content

Commit 9f7ad18

Browse files
committed
reduce cyclomatic complexity
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 40ebcd6 commit 9f7ad18

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

pkg/compose/create.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -301,35 +301,9 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
301301
}
302302

303303
var networkConfig *network.NetworkingConfig
304-
305304
for _, id := range service.NetworksByPriority() {
306-
net := p.Networks[id]
307-
config := service.Networks[id]
308-
var ipam *network.EndpointIPAMConfig
309-
var (
310-
ipv4Address string
311-
ipv6Address string
312-
)
313-
if config != nil {
314-
ipv4Address = config.Ipv4Address
315-
ipv6Address = config.Ipv6Address
316-
ipam = &network.EndpointIPAMConfig{
317-
IPv4Address: ipv4Address,
318-
IPv6Address: ipv6Address,
319-
LinkLocalIPs: config.LinkLocalIPs,
320-
}
321-
}
322-
networkConfig = &network.NetworkingConfig{
323-
EndpointsConfig: map[string]*network.EndpointSettings{
324-
net.Name: {
325-
Aliases: getAliases(service, config),
326-
IPAddress: ipv4Address,
327-
IPv6Gateway: ipv6Address,
328-
IPAMConfig: ipam,
329-
},
330-
},
331-
}
332-
break //nolint:staticcheck
305+
networkConfig = s.createNetworkConfig(p, service, id)
306+
break
333307
}
334308

335309
tmpfs := map[string]string{}
@@ -409,6 +383,35 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
409383
return &containerConfig, &hostConfig, networkConfig, nil
410384
}
411385

386+
func (s *composeService) createNetworkConfig(p *types.Project, service types.ServiceConfig, networkID string) *network.NetworkingConfig {
387+
net := p.Networks[networkID]
388+
config := service.Networks[networkID]
389+
var ipam *network.EndpointIPAMConfig
390+
var (
391+
ipv4Address string
392+
ipv6Address string
393+
)
394+
if config != nil {
395+
ipv4Address = config.Ipv4Address
396+
ipv6Address = config.Ipv6Address
397+
ipam = &network.EndpointIPAMConfig{
398+
IPv4Address: ipv4Address,
399+
IPv6Address: ipv6Address,
400+
LinkLocalIPs: config.LinkLocalIPs,
401+
}
402+
}
403+
return &network.NetworkingConfig{
404+
EndpointsConfig: map[string]*network.EndpointSettings{
405+
net.Name: {
406+
Aliases: getAliases(service, config),
407+
IPAddress: ipv4Address,
408+
IPv6Gateway: ipv6Address,
409+
IPAMConfig: ipam,
410+
},
411+
},
412+
}
413+
}
414+
412415
// copy/pasted from https://github.com/docker/cli/blob/9de1b162f/cli/command/container/opts.go#L673-L697 + RelativePath
413416
// TODO find so way to share this code with docker/cli
414417
func parseSecurityOpts(p *types.Project, securityOpts []string) ([]string, bool, error) {

0 commit comments

Comments
 (0)