mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Simplify hasUserDefinedIPAddress, and centralize validation
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
20dde01848
commit
ebe0174f22
1 changed files with 14 additions and 12 deletions
|
@ -592,9 +592,9 @@ func (daemon *Daemon) getNetworkSandbox(container *container.Container) libnetwo
|
||||||
return sb
|
return sb
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasUserDefinedIPAddress returns whether the passed endpoint configuration contains IP address configuration
|
// hasUserDefinedIPAddress returns whether the passed IPAM configuration contains IP address configuration
|
||||||
func hasUserDefinedIPAddress(epConfig *networktypes.EndpointSettings) bool {
|
func hasUserDefinedIPAddress(ipamConfig *networktypes.EndpointIPAMConfig) bool {
|
||||||
return epConfig != nil && epConfig.IPAMConfig != nil && (len(epConfig.IPAMConfig.IPv4Address) > 0 || len(epConfig.IPAMConfig.IPv6Address) > 0)
|
return ipamConfig != nil && (len(ipamConfig.IPv4Address) > 0 || len(ipamConfig.IPv6Address) > 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// User specified ip address is acceptable only for networks with user specified subnets.
|
// User specified ip address is acceptable only for networks with user specified subnets.
|
||||||
|
@ -602,9 +602,18 @@ func validateNetworkingConfig(n libnetwork.Network, epConfig *networktypes.Endpo
|
||||||
if n == nil || epConfig == nil {
|
if n == nil || epConfig == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if !hasUserDefinedIPAddress(epConfig) {
|
if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
||||||
|
if hasUserDefinedIPAddress(epConfig.IPAMConfig) && !enableIPOnPredefinedNetwork() {
|
||||||
|
return runconfig.ErrUnsupportedNetworkAndIP
|
||||||
|
}
|
||||||
|
if len(epConfig.Aliases) > 0 && !serviceDiscoveryOnDefaultNetwork() {
|
||||||
|
return runconfig.ErrUnsupportedNetworkAndAlias
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasUserDefinedIPAddress(epConfig.IPAMConfig) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig()
|
_, _, nwIPv4Configs, nwIPv6Configs := n.Info().IpamConfig()
|
||||||
for _, s := range []struct {
|
for _, s := range []struct {
|
||||||
ipConfigured bool
|
ipConfigured bool
|
||||||
|
@ -653,14 +662,7 @@ func cleanOperationalData(es *network.EndpointSettings) {
|
||||||
|
|
||||||
func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error {
|
func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error {
|
||||||
|
|
||||||
if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
if containertypes.NetworkMode(n.Name()).IsUserDefined() {
|
||||||
if hasUserDefinedIPAddress(endpointConfig) && !enableIPOnPredefinedNetwork() {
|
|
||||||
return runconfig.ErrUnsupportedNetworkAndIP
|
|
||||||
}
|
|
||||||
if endpointConfig != nil && len(endpointConfig.Aliases) > 0 && !serviceDiscoveryOnDefaultNetwork() {
|
|
||||||
return runconfig.ErrUnsupportedNetworkAndAlias
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
addShortID := true
|
addShortID := true
|
||||||
shortID := stringid.TruncateID(container.ID)
|
shortID := stringid.TruncateID(container.ID)
|
||||||
for _, alias := range endpointConfig.Aliases {
|
for _, alias := range endpointConfig.Aliases {
|
||||||
|
|
Loading…
Add table
Reference in a new issue