Remove daemon.VXSubnets duplicate code
Refactor daemon.V4Subnets and daemon.V6Subnets to limit duplication Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
c956d25bfc
commit
3c5932086a
3 changed files with 16 additions and 30 deletions
|
@ -89,8 +89,7 @@ var errSwarmCertificatesExpired = errors.New("Swarm certificates have expired. T
|
|||
// NetworkSubnetsProvider exposes functions for retrieving the subnets
|
||||
// of networks managed by Docker, so they can be filtered.
|
||||
type NetworkSubnetsProvider interface {
|
||||
V4Subnets() []net.IPNet
|
||||
V6Subnets() []net.IPNet
|
||||
Subnets() ([]net.IPNet, []net.IPNet)
|
||||
}
|
||||
|
||||
// Config provides values for Cluster.
|
||||
|
|
|
@ -162,8 +162,7 @@ func (c *Cluster) resolveSystemAddrViaSubnetCheck() (net.IP, error) {
|
|||
var systemInterface string
|
||||
|
||||
// List Docker-managed subnets
|
||||
v4Subnets := c.config.NetworkSubnetsProvider.V4Subnets()
|
||||
v6Subnets := c.config.NetworkSubnetsProvider.V6Subnets()
|
||||
v4Subnets, v6Subnets := c.config.NetworkSubnetsProvider.Subnets()
|
||||
|
||||
ifaceLoop:
|
||||
for _, intf := range interfaces {
|
||||
|
|
|
@ -878,40 +878,28 @@ func (daemon *Daemon) Unmount(container *container.Container) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// V4Subnets returns the IPv4 subnets of networks that are managed by Docker.
|
||||
func (daemon *Daemon) V4Subnets() []net.IPNet {
|
||||
var subnets []net.IPNet
|
||||
// Subnets return the IPv4 and IPv6 subnets of networks that are manager by Docker.
|
||||
func (daemon *Daemon) Subnets() ([]net.IPNet, []net.IPNet) {
|
||||
var v4Subnets []net.IPNet
|
||||
var v6Subnets []net.IPNet
|
||||
|
||||
managedNetworks := daemon.netController.Networks()
|
||||
|
||||
for _, managedNetwork := range managedNetworks {
|
||||
v4Infos, _ := managedNetwork.Info().IpamInfo()
|
||||
for _, v4Info := range v4Infos {
|
||||
if v4Info.IPAMData.Pool != nil {
|
||||
subnets = append(subnets, *v4Info.IPAMData.Pool)
|
||||
v4infos, v6infos := managedNetwork.Info().IpamInfo()
|
||||
for _, info := range v4infos {
|
||||
if info.IPAMData.Pool != nil {
|
||||
v4Subnets = append(v4Subnets, *info.IPAMData.Pool)
|
||||
}
|
||||
}
|
||||
for _, info := range v6infos {
|
||||
if info.IPAMData.Pool != nil {
|
||||
v6Subnets = append(v6Subnets, *info.IPAMData.Pool)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return subnets
|
||||
}
|
||||
|
||||
// V6Subnets returns the IPv6 subnets of networks that are managed by Docker.
|
||||
func (daemon *Daemon) V6Subnets() []net.IPNet {
|
||||
var subnets []net.IPNet
|
||||
|
||||
managedNetworks := daemon.netController.Networks()
|
||||
|
||||
for _, managedNetwork := range managedNetworks {
|
||||
_, v6Infos := managedNetwork.Info().IpamInfo()
|
||||
for _, v6Info := range v6Infos {
|
||||
if v6Info.IPAMData.Pool != nil {
|
||||
subnets = append(subnets, *v6Info.IPAMData.Pool)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return subnets
|
||||
return v4Subnets, v6Subnets
|
||||
}
|
||||
|
||||
// GraphDriverName returns the name of the graph driver used by the layer.Store
|
||||
|
|
Loading…
Reference in a new issue