Browse Source

Run on_finalize() for ADDED events

In case of Kuryr being restarted when a resource is already deleted, an
ADDED event will be detected by the handler. If that resource had
finalizers, Kuryr needs to run on_finalize() too. This commit makes sure
we check for deletionTimestamp on ADDED events too.

Change-Id: Ia98311a4afc840b3db87f02555a45e9e639ce742
changes/84/714684/1
Michał Dulko 2 years ago
parent
commit
20eea68027
  1. 19
      kuryr_kubernetes/handlers/k8s_base.py

19
kuryr_kubernetes/handlers/k8s_base.py

@ -64,21 +64,28 @@ class ResourceEventHandler(dispatch.EventConsumer, health.HealthHandler):
def consumes(self):
return {object_kind: self.OBJECT_KIND}
def _check_finalize(self, obj):
deletion_timestamp = None
try:
deletion_timestamp = obj['metadata']['deletionTimestamp']
except (KeyError, TypeError):
pass
return deletion_timestamp
def __call__(self, event):
event_type = event.get('type')
obj = event.get('object')
if 'MODIFIED' == event_type:
deletion_timestamp = None
try:
deletion_timestamp = obj['metadata']['deletionTimestamp']
except (KeyError, TypeError):
pass
if deletion_timestamp:
if self._check_finalize(obj):
self.on_finalize(obj)
return
self.on_modified(obj)
self.on_present(obj)
elif 'ADDED' == event_type:
if self._check_finalize(obj):
self.on_finalize(obj)
return
self.on_added(obj)
self.on_present(obj)
elif 'DELETED' == event_type:

Loading…
Cancel
Save