Bläddra i källkod

Merge pull request #1265 from aboch/hn

Refresh special driver networks if present in store
Santhosh Manohar 9 år sedan
förälder
incheckning
bfbe9237d4
4 ändrade filer med 20 tillägg och 6 borttagningar
  1. 2 0
      libnetwork/controller.go
  2. 2 2
      libnetwork/endpoint.go
  3. 7 4
      libnetwork/network.go
  4. 9 0
      libnetwork/store.go

+ 2 - 0
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

+ 2 - 2
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
 	}
 

+ 7 - 4
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"
+}

+ 9 - 0
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
+}