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.
@@ -64,21 +64,28 @@ class ResourceEventHandler(dispatch.EventConsumer, health.HealthHandler):
def consumes(self):
return {object_kind: self.OBJECT_KIND}
- def __call__(self, event):
- event_type = event.get('type')
- obj = event.get('object')
- if 'MODIFIED' == event_type:
+ def _check_finalize(self, obj):
deletion_timestamp = None
try:
deletion_timestamp = obj['metadata']['deletionTimestamp']
except (KeyError, TypeError):
pass
- if deletion_timestamp:
+
+ return deletion_timestamp
+
+ def __call__(self, event):
+ event_type = event.get('type')
+ obj = event.get('object')
+ if 'MODIFIED' == event_type:
+ 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:
