Browse code

Handle cleanup DNS for attachable container

Attachable containers they are tasks with no service associated
their cleanup was not done properly so it was possible to have
a leak of their name resolution if that was the last container
on the network.
Cleanupservicebindings was not able to do the cleanup because there
is no service, while also the notification of the delete arrives
after that the network is already being cleaned

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>

Flavio Crisciani authored on 2017/10/13 13:41:29
Showing 4 changed files
... ...
@@ -341,6 +341,7 @@ func (c *controller) clusterAgentInit() {
341 341
 			// should still be present when cleaning up
342 342
 			// service bindings
343 343
 			c.agentClose()
344
+			c.cleanupServiceDiscovery("")
344 345
 			c.cleanupServiceBindings("")
345 346
 
346 347
 			c.agentStopComplete()
... ...
@@ -995,6 +995,10 @@ func (n *network) delete(force bool) error {
995 995
 		logrus.Errorf("Failed leaving network %s from the agent cluster: %v", n.Name(), err)
996 996
 	}
997 997
 
998
+	// Cleanup the service discovery for this network
999
+	c.cleanupServiceDiscovery(n.ID())
1000
+
1001
+	// Cleanup the load balancer
998 1002
 	c.cleanupServiceBindings(n.ID())
999 1003
 
1000 1004
 removeFromStore:
... ...
@@ -499,7 +499,10 @@ func (nDB *NetworkDB) deleteNodeNetworkEntries(nid, node string) {
499 499
 					// without doing a delete of all the objects
500 500
 					entry.ltime++
501 501
 				}
502
-				nDB.createOrUpdateEntry(nid, tname, key, entry)
502
+
503
+				if !oldEntry.deleting {
504
+					nDB.createOrUpdateEntry(nid, tname, key, entry)
505
+				}
503 506
 			} else {
504 507
 				// the local node is leaving the network, all the entries of remote nodes can be safely removed
505 508
 				nDB.deleteEntry(nid, tname, key)
... ...
@@ -161,6 +161,19 @@ func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int
161 161
 	return int(lb.fwMark)
162 162
 }
163 163
 
164
+// cleanupServiceDiscovery when the network is being deleted, erase all the associated service discovery records
165
+func (c *controller) cleanupServiceDiscovery(cleanupNID string) {
166
+	c.Lock()
167
+	defer c.Unlock()
168
+	if cleanupNID == "" {
169
+		logrus.Debugf("cleanupServiceDiscovery for all networks")
170
+		c.svcRecords = make(map[string]svcInfo)
171
+		return
172
+	}
173
+	logrus.Debugf("cleanupServiceDiscovery for network:%s", cleanupNID)
174
+	delete(c.svcRecords, cleanupNID)
175
+}
176
+
164 177
 func (c *controller) cleanupServiceBindings(cleanupNID string) {
165 178
 	var cleanupFuncs []func()
166 179
 
... ...
@@ -184,15 +197,6 @@ func (c *controller) cleanupServiceBindings(cleanupNID string) {
184 184
 				continue
185 185
 			}
186 186
 
187
-			// The network is being deleted, erase all the associated service discovery records
188
-			// TODO(fcrisciani) separate the Load Balancer from the Service discovery, this operation
189
-			// can be done safely here, but the rmServiceBinding is still keeping consistency in the
190
-			// data structures that are tracking the endpoint to IP mapping.
191
-			c.Lock()
192
-			logrus.Debugf("cleanupServiceBindings erasing the svcRecords for %s", nid)
193
-			delete(c.svcRecords, nid)
194
-			c.Unlock()
195
-
196 187
 			for eid, ip := range lb.backEnds {
197 188
 				epID := eid
198 189
 				epIP := ip