Skip to content

Commit

Permalink
Fix drop of events on objects being deleted
Browse files Browse the repository at this point in the history
Don't expand a path selection to validate the events against,
because this path selection does not include the objects being
deleted, which cause the event to be unduely dropped.

Use instead a event's path match against the selector expression.
  • Loading branch information
cvaroqui committed Nov 4, 2019
1 parent c68a416 commit bbcf7aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
23 changes: 11 additions & 12 deletions lib/osvcd_lsnr.py
Expand Up @@ -506,26 +506,25 @@ def filter_event(self, event, thr):
# root and no selector => fast path
return event
namespaces = thr.get_namespaces()
paths = self.object_selector(thr.selector if thr.selector is not None else "**", namespaces=namespaces)
if event.get("kind") == "patch":
return self.filter_patch_event(event, thr, paths, namespaces)
return self.filter_patch_event(event, thr, namespaces)
else:
return self.filter_event_event(event, thr, paths)
return self.filter_event_event(event, thr, namespaces)

def filter_event_event(self, event, thr, paths):
def filter_event_event(self, event, thr, namespaces):
def valid(change):
try:
path = event["data"]["path"]
except KeyError:
return True
if thr.selector and path not in paths:
if thr.selector and not self.match_object_selector(thr.selector, namespaces=namespaces, path=path):
return False
return False
if valid(event):
return event
return None

def filter_patch_event(self, event, thr, paths, namespaces):
def filter_patch_event(self, event, thr, namespaces):
def filter_change(change):
try:
key, value = change
Expand All @@ -551,9 +550,9 @@ def filter_change(change):
if key_len == 2:
if value is None:
return change
value = dict((k, v) for k, v in value.items() if k in paths)
value = dict((k, v) for k, v in value.items() if self.match_object_selector(thr.selector, namespaces=namespaces, path=k))
return [key, value]
if key[2] in paths:
if self.match_object_selector(thr.selector, namespaces=namespaces, path=key[2]):
return change
else:
return
Expand All @@ -578,19 +577,19 @@ def filter_change(change):
if key_len == 5:
if value is None:
return change
value = dict((k, v) for k, v in value.items() if k in paths)
value = dict((k, v) for k, v in value.items() if self.match_object_selector(thr.selector, namespaces=namespaces, path=k))
return [key, value]
if key[5] in paths:
if self.match_object_selector(thr.selector, namespaces=namespaces, path=key[5]):
return change
else:
return
if key[4] == "config":
if key_len == 5:
if value is None:
return change
value = dict((k, v) for k, v in value.items() if k in paths)
value = dict((k, v) for k, v in value.items() if self.match_object_selector(thr.selector, namespaces=namespaces, path=k))
return [key, value]
if key[5] in paths:
if self.match_object_selector(thr.selector, namespaces=namespaces, path=key[5]):
return change
else:
return
Expand Down
12 changes: 9 additions & 3 deletions lib/osvcd_shared.py
Expand Up @@ -1515,7 +1515,12 @@ def filter_daemon_status(self, data, namespace=None, namespaces=None, selector=N
del data["monitor"]["services"][path]
return data

def object_selector(self, selector=None, namespace=None, namespaces=None):
def match_object_selector(self, selector=None, namespace=None, namespaces=None, path=None):
if selector is None:
selector = "**"
return path in self.object_selector(selector=selector, namespace=namespace, namespaces=namespaces, paths=[path])

def object_selector(self, selector=None, namespace=None, namespaces=None, paths=None):
if not selector:
return []
if namespace:
Expand All @@ -1525,8 +1530,9 @@ def object_selector(self, selector=None, namespace=None, namespaces=None):
if "root" in namespaces:
namespaces.add(None)

# all objects
paths = [p for p in AGG if split_path(p)[1] in namespaces]
if paths is None:
# all objects
paths = [p for p in AGG if split_path(p)[1] in namespaces]
if selector == "**":
return paths

Expand Down

0 comments on commit bbcf7aa

Please sign in to comment.