@@ -274,25 +274,30 @@ func (c *controller) networkWatchLoop(nw *netWatch, ep *endpoint, ecCh <-chan da
274274 continue
275275 }
276276
277- if _ , ok := nw .remoteEps [lEp .ID ()]; ok {
278- delete (delEpMap , lEp .ID ())
279- continue
277+ if ep , ok := nw .remoteEps [lEp .ID ()]; ok {
278+ // On a container rename EP ID will remain
279+ // the same but the name will change. service
280+ // records should reflect the change.
281+ // Keep old EP entry in the delEpMap and add
282+ // EP from the store (which has the new name)
283+ // into the new list
284+ if lEp .name == ep .name {
285+ delete (delEpMap , lEp .ID ())
286+ continue
287+ }
280288 }
281-
282289 nw .remoteEps [lEp .ID ()] = lEp
283290 addEp = append (addEp , lEp )
284-
285291 }
286292 c .Unlock ()
287293
288- for _ , lEp := range addEp {
289- ep .getNetwork ().updateSvcRecord (lEp , c .getLocalEps (nw ), true )
290- }
291-
292294 for _ , lEp := range delEpMap {
293295 ep .getNetwork ().updateSvcRecord (lEp , c .getLocalEps (nw ), false )
294296
295297 }
298+ for _ , lEp := range addEp {
299+ ep .getNetwork ().updateSvcRecord (lEp , c .getLocalEps (nw ), true )
300+ }
296301 }
297302 }
298303}
@@ -378,21 +383,21 @@ func (c *controller) processEndpointDelete(nmap map[string]*netWatch, ep *endpoi
378383 c .Unlock ()
379384}
380385
381- func (c * controller ) watchLoop (nmap map [ string ] * netWatch ) {
386+ func (c * controller ) watchLoop () {
382387 for {
383388 select {
384389 case ep := <- c .watchCh :
385- c .processEndpointCreate (nmap , ep )
390+ c .processEndpointCreate (c . nmap , ep )
386391 case ep := <- c .unWatchCh :
387- c .processEndpointDelete (nmap , ep )
392+ c .processEndpointDelete (c . nmap , ep )
388393 }
389394 }
390395}
391396
392397func (c * controller ) startWatch () {
393398 c .watchCh = make (chan * endpoint )
394399 c .unWatchCh = make (chan * endpoint )
395- nmap : = make (map [string ]* netWatch )
400+ c . nmap = make (map [string ]* netWatch )
396401
397- go c .watchLoop (nmap )
402+ go c .watchLoop ()
398403}
0 commit comments