Merge "Delete pods from registry in CNI daemon" into stable/queens

This commit is contained in:
Zuul 2018-02-22 22:38:16 +00:00 committed by Gerrit Code Review
commit 2aaffdf0a7
2 changed files with 21 additions and 2 deletions

View File

@ -256,7 +256,8 @@ class CNIDaemonWatcherService(cotyledon.Service):
def run(self):
self.pipeline = h_cni.CNIPipeline()
self.pipeline.register(h_cni.CallbackHandler(self.on_done))
self.pipeline.register(h_cni.CallbackHandler(self.on_done,
self.on_deleted))
self.watcher = k_watcher.Watcher(self.pipeline)
self.watcher.add(
"%(base)s/pods?fieldSelector=spec.nodeName=%(node_name)s" % {
@ -283,6 +284,18 @@ class CNIDaemonWatcherService(cotyledon.Service):
pod_dict['vif'] = vif_dict
self.registry[pod_name] = pod_dict
def on_deleted(self, pod):
pod_name = pod['metadata']['name']
try:
if pod_name in self.registry:
# NOTE(dulek): del on dict is atomic as long as we use standard
# types as keys. This is the case, so we don't
# need to lock here.
del self.registry[pod_name]
except KeyError:
# This means someone else removed it. It's odd but safe to ignore.
pass
def terminate(self):
if self.watcher:
self.watcher.stop()

View File

@ -92,12 +92,18 @@ class DelHandler(CNIHandlerBase):
class CallbackHandler(CNIHandlerBase):
def __init__(self, on_vif):
def __init__(self, on_vif, on_del=None):
super(CallbackHandler, self).__init__(None, on_vif)
self._del_callback = on_del
def on_vif(self, pod, vif):
self._callback(pod, vif)
def on_deleted(self, pod):
LOG.debug("Got pod %s deletion event.", pod['metadata']['name'])
if self._del_callback:
self._del_callback(pod)
class CNIPipeline(k_dis.EventPipeline):