reduce cyclomatic complexity

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2022-12-21 09:06:12 +01:00 committed by Nicolas De loof
parent 40ebcd6203
commit 9f7ad18d62
1 changed files with 31 additions and 28 deletions

View File

@ -301,35 +301,9 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
} }
var networkConfig *network.NetworkingConfig var networkConfig *network.NetworkingConfig
for _, id := range service.NetworksByPriority() { for _, id := range service.NetworksByPriority() {
net := p.Networks[id] networkConfig = s.createNetworkConfig(p, service, id)
config := service.Networks[id] break
var ipam *network.EndpointIPAMConfig
var (
ipv4Address string
ipv6Address string
)
if config != nil {
ipv4Address = config.Ipv4Address
ipv6Address = config.Ipv6Address
ipam = &network.EndpointIPAMConfig{
IPv4Address: ipv4Address,
IPv6Address: ipv6Address,
LinkLocalIPs: config.LinkLocalIPs,
}
}
networkConfig = &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
net.Name: {
Aliases: getAliases(service, config),
IPAddress: ipv4Address,
IPv6Gateway: ipv6Address,
IPAMConfig: ipam,
},
},
}
break //nolint:staticcheck
} }
tmpfs := map[string]string{} tmpfs := map[string]string{}
@ -409,6 +383,35 @@ func (s *composeService) getCreateOptions(ctx context.Context, p *types.Project,
return &containerConfig, &hostConfig, networkConfig, nil return &containerConfig, &hostConfig, networkConfig, nil
} }
func (s *composeService) createNetworkConfig(p *types.Project, service types.ServiceConfig, networkID string) *network.NetworkingConfig {
net := p.Networks[networkID]
config := service.Networks[networkID]
var ipam *network.EndpointIPAMConfig
var (
ipv4Address string
ipv6Address string
)
if config != nil {
ipv4Address = config.Ipv4Address
ipv6Address = config.Ipv6Address
ipam = &network.EndpointIPAMConfig{
IPv4Address: ipv4Address,
IPv6Address: ipv6Address,
LinkLocalIPs: config.LinkLocalIPs,
}
}
return &network.NetworkingConfig{
EndpointsConfig: map[string]*network.EndpointSettings{
net.Name: {
Aliases: getAliases(service, config),
IPAddress: ipv4Address,
IPv6Gateway: ipv6Address,
IPAMConfig: ipam,
},
},
}
}
// copy/pasted from https://github.com/docker/cli/blob/9de1b162f/cli/command/container/opts.go#L673-L697 + RelativePath // copy/pasted from https://github.com/docker/cli/blob/9de1b162f/cli/command/container/opts.go#L673-L697 + RelativePath
// TODO find so way to share this code with docker/cli // TODO find so way to share this code with docker/cli
func parseSecurityOpts(p *types.Project, securityOpts []string) ([]string, bool, error) { func parseSecurityOpts(p *types.Project, securityOpts []string) ([]string, bool, error) {