diff --git a/libnetwork/controller.go b/libnetwork/controller.go index 3655707bf6..b19f51d707 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -203,6 +203,8 @@ func New(cfgOptions ...config.Option) (NetworkController, error) { } } + c.WalkNetworks(populateSpecial) + // Reserve pools first before doing cleanup. Otherwise the // cleanups of endpoint/network and sandbox below will // generate many unnecessary warnings diff --git a/libnetwork/endpoint.go b/libnetwork/endpoint.go index 1c9bf8291c..3fa1b6dc3e 100644 --- a/libnetwork/endpoint.go +++ b/libnetwork/endpoint.go @@ -987,7 +987,7 @@ func (ep *endpoint) assignAddress(ipam ipamapi.Ipam, assignIPv4, assignIPv6 bool var err error n := ep.getNetwork() - if n.Type() == "host" || n.Type() == "null" { + if n.hasSpecialDriver() { return nil } @@ -1067,7 +1067,7 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error { func (ep *endpoint) releaseAddress() { n := ep.getNetwork() - if n.Type() == "host" || n.Type() == "null" { + if n.hasSpecialDriver() { return } diff --git a/libnetwork/network.go b/libnetwork/network.go index c4e988fadd..1bf003ebf3 100644 --- a/libnetwork/network.go +++ b/libnetwork/network.go @@ -1123,8 +1123,7 @@ func (n *network) getController() *controller { } func (n *network) ipamAllocate() error { - // For now also exclude bridge from using new ipam - if n.Type() == "host" || n.Type() == "null" { + if n.hasSpecialDriver() { return nil } @@ -1295,8 +1294,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error { } func (n *network) ipamRelease() { - // For now exclude host and null - if n.Type() == "host" || n.Type() == "null" { + if n.hasSpecialDriver() { return } ipam, _, err := n.getController().getIPAMDriver(n.ipamType) @@ -1504,3 +1502,8 @@ func (n *network) TableEventRegister(tableName string) error { n.driverTables = append(n.driverTables, tableName) return nil } + +// Special drivers are ones which do not need to perform any network plumbing +func (n *network) hasSpecialDriver() bool { + return n.Type() == "host" || n.Type() == "null" +} diff --git a/libnetwork/store.go b/libnetwork/store.go index 714d56bd5a..b622836498 100644 --- a/libnetwork/store.go +++ b/libnetwork/store.go @@ -464,3 +464,12 @@ func (c *controller) networkCleanup() { } } } + +var populateSpecial NetworkWalker = func(nw Network) bool { + if n := nw.(*network); n.hasSpecialDriver() { + if err := n.getController().addNetwork(n); err != nil { + log.Warnf("Failed to populate network %q with driver %q", nw.Name(), nw.Type()) + } + } + return false +}