Skip to content

Commit

Permalink
Remove debug code
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertSzefler committed Mar 24, 2024
1 parent e66be57 commit ba1abd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
4 changes: 0 additions & 4 deletions scripts/generate_kubernetes_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,6 @@ def __init__(
labels_selector=labels_selector,
scope=scope,
)
if scope:
logging.warning("SCOPE (" + str(type(self)) + "): " + str(scope))
@staticmethod
def get_execution_event_type() -> type:
Expand Down Expand Up @@ -418,8 +416,6 @@ def __init__(
labels_selector=labels_selector,
scope=scope,
)
if scope:
logging.warning("SCOPE (" + str(type(self)) + "): " + str(scope))
@staticmethod
def get_execution_event_type() -> type:
Expand Down
16 changes: 5 additions & 11 deletions src/robusta/integrations/kubernetes/base_triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class K8sBaseTrigger(BaseTrigger, BaseScopeMatching):

def __init__(self, *args, **data):
super().__init__(*args, **data)
if self.scope:
logging.warning(f"2 SCOPE: {self.scope}")
if self.labels_selector:
labels = self.labels_selector.split(",")
self._labels_map = {}
Expand Down Expand Up @@ -128,14 +126,12 @@ def scope_match_attributes(self, attr_matcher, attr_value):
# attr_value is the full payload (nested dicts/lists)
# attr_matcher is a comma-separated list of jsonpath_ng-compatible search path expressions
# (for example "spec.containers[*].name=bad, status.phase=Pending")
logging.error(f"XXX {attr_matcher}")
logging.error(f"XXX {attr_value}")
try:
return all(self.match_by_yaml_path(expr, attr_value) for expr in attr_matcher.split(","))
return all(self.match_attr_by_path(expr, attr_value) for expr in attr_matcher.split(","))
except InvalidMatcher:
logging.error(f'invalid attribute-matching expression "{attr_matcher}')

def match_by_yaml_path(self, expr, data):
def match_attr_by_path(self, expr, data):
try:
path, value = expr.rsplit("=", 1)
except ValueError: # no "=" in the expression
Expand All @@ -153,7 +149,6 @@ def match_by_yaml_path(self, expr, data):
logging.error(f'invalid path expression "{path}"')
return not expected_result
found = expr.find(data)
logging.warning(f"--> {path} {found}")
# The match expression must be constructed in a way that it matches a single leaf
# value in the data structure, which in case of K8s data would always be either a
# string, an integer or null (None).
Expand All @@ -169,13 +164,12 @@ def match_by_yaml_path(self, expr, data):
elif isinstance(found, int):
try:
value = int(value)
return (found == value) is expected_result
except (TypeError, ValueError):
logging.error(f'right-hand side value of match expression "{expr}" cannot be parsed as int')
return not expected_result
return (found == value) is expected_result
elif found is None:
# TODO
return not expected_result
# TODO is this the expected behavior?
return (found == "null") is expected_result
else:
logging.error(
f'path expression "{path}" matched a value of type "{type(found)}, '
Expand Down

0 comments on commit ba1abd0

Please sign in to comment.