Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport 17.06] Handle cleanup DNS for attachable container #1989

Merged
merged 1 commit into from
Oct 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ func (c *controller) clusterAgentInit() {
// should still be present when cleaning up
// service bindings
c.agentClose()
c.cleanupServiceDiscovery("")
c.cleanupServiceBindings("")

c.agentStopComplete()
Expand Down
4 changes: 4 additions & 0 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,10 @@ func (n *network) delete(force bool) error {
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())

removeFromStore:
Expand Down
5 changes: 4 additions & 1 deletion networkdb/networkdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ func (nDB *NetworkDB) deleteNodeNetworkEntries(nid, node string) {
// without doing a delete of all the objects
entry.ltime++
}
nDB.createOrUpdateEntry(nid, tname, key, entry)

if !oldEntry.deleting {
nDB.createOrUpdateEntry(nid, tname, key, entry)
}
} else {
// the local node is leaving the network, all the entries of remote nodes can be safely removed
nDB.deleteEntry(nid, tname, key)
Expand Down
22 changes: 13 additions & 9 deletions service_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,19 @@ func (c *controller) getLBIndex(sid, nid string, ingressPorts []*PortConfig) int
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) {
var cleanupFuncs []func()

Expand All @@ -184,15 +197,6 @@ func (c *controller) cleanupServiceBindings(cleanupNID string) {
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 {
epID := eid
epIP := ip
Expand Down