Ver Fonte

Merge pull request #1985 from fcrisciani/fix-attachable-cnt

Handle cleanup DNS for attachable container
Madhu Venugopal há 7 anos atrás
pai
commit
e5ebc4bbdd

+ 1 - 0
libnetwork/controller.go

@@ -341,6 +341,7 @@ func (c *controller) clusterAgentInit() {
 			// should still be present when cleaning up
 			// should still be present when cleaning up
 			// service bindings
 			// service bindings
 			c.agentClose()
 			c.agentClose()
+			c.cleanupServiceDiscovery("")
 			c.cleanupServiceBindings("")
 			c.cleanupServiceBindings("")
 
 
 			c.agentStopComplete()
 			c.agentStopComplete()

+ 4 - 0
libnetwork/network.go

@@ -995,6 +995,10 @@ func (n *network) delete(force bool) error {
 		logrus.Errorf("Failed leaving network %s from the agent cluster: %v", n.Name(), err)
 		logrus.Errorf("Failed leaving network %s from the agent cluster: %v", n.Name(), err)
 	}
 	}
 
 
+	// Cleanup the service discovery for this network
+	c.cleanupServiceDiscovery(n.ID())
+
+	// Cleanup the load balancer
 	c.cleanupServiceBindings(n.ID())
 	c.cleanupServiceBindings(n.ID())
 
 
 removeFromStore:
 removeFromStore:

+ 4 - 1
libnetwork/networkdb/networkdb.go

@@ -499,7 +499,10 @@ func (nDB *NetworkDB) deleteNodeNetworkEntries(nid, node string) {
 					// without doing a delete of all the objects
 					// without doing a delete of all the objects
 					entry.ltime++
 					entry.ltime++
 				}
 				}
-				nDB.createOrUpdateEntry(nid, tname, key, entry)
+
+				if !oldEntry.deleting {
+					nDB.createOrUpdateEntry(nid, tname, key, entry)
+				}
 			} else {
 			} else {
 				// the local node is leaving the network, all the entries of remote nodes can be safely removed
 				// the local node is leaving the network, all the entries of remote nodes can be safely removed
 				nDB.deleteEntry(nid, tname, key)
 				nDB.deleteEntry(nid, tname, key)

+ 13 - 9
libnetwork/service_common.go

@@ -161,6 +161,19 @@ func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int
 	return int(lb.fwMark)
 	return int(lb.fwMark)
 }
 }
 
 
+// cleanupServiceDiscovery when the network is being deleted, erase all the associated service discovery records
+func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
+	c.Lock()
+	defer c.Unlock()
+	if cleanupNID == "" {
+		logrus.Debugf("cleanupServiceDiscovery for all networks")
+		c.svcRecords = make(map[string]svcInfo)
+		return
+	}
+	logrus.Debugf("cleanupServiceDiscovery for network:%s", cleanupNID)
+	delete(c.svcRecords, cleanupNID)
+}
+
 func (c *controller) cleanupServiceBindings(cleanupNID string) {
 func (c *controller) cleanupServiceBindings(cleanupNID string) {
 	var cleanupFuncs []func()
 	var cleanupFuncs []func()
 
 
@@ -184,15 +197,6 @@ func (c *controller) cleanupServiceBindings(cleanupNID string) {
 				continue
 				continue
 			}
 			}
 
 
-			// The network is being deleted, erase all the associated service discovery records
-			// TODO(fcrisciani) separate the Load Balancer from the Service discovery, this operation
-			// can be done safely here, but the rmServiceBinding is still keeping consistency in the
-			// data structures that are tracking the endpoint to IP mapping.
-			c.Lock()
-			logrus.Debugf("cleanupServiceBindings erasing the svcRecords for %s", nid)
-			delete(c.svcRecords, nid)
-			c.Unlock()
-
 			for eid, ip := range lb.backEnds {
 			for eid, ip := range lb.backEnds {
 				epID := eid
 				epID := eid
 				epIP := ip
 				epIP := ip