New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
k8s server triggers filtering #1351
k8s server triggers filtering #1351
Conversation
cd98bce
to
ba1abd0
Compare
7733afd
to
121c6d8
Compare
2cb6bea
to
619b0aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work
left quite a few comments, as this is a complex feature
scripts/generate_kubernetes_code.py
Outdated
@@ -368,13 +372,16 @@ def autogenerate_triggers(f: TextIO): | |||
textwrap.dedent( | |||
f"""\ | |||
class {resource}{get_trigger_class_name(trigger_name)}Trigger(K8sBaseTrigger): | |||
def __init__(self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None): | |||
def __init__( | |||
self, name_prefix: str = None, namespace_prefix: str = None, labels_selector: str = None, scope: Optional[ScopeParamsAsDict] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is the wrong type
there are redundant wrappers
I think it should be: Optional[ScopeParams]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -93,8 +103,80 @@ def should_fire(self, event: TriggerEvent, playbook_id: str, build_context: Dict | |||
if label_value != obj_labels.get(label_key, ""): | |||
return False | |||
|
|||
if self.scope: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic here is wrong
same bug we had on scopes matchers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
return True | ||
|
||
def attribute_map(self, aux_obj=None) -> Dict[str, Union[str, Dict[str, str]]]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this aux_obj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed in favor of get_scope_matching_data
and refactored later to just be a data
attribute on BaseScopeMatcher
-derived classes.
src/robusta/utils/scope.py
Outdated
ScopeParamsAsDict = Dict[str, Optional[List[ScopeIncludeExcludeParams]]] | ||
|
||
|
||
class BaseScopeMatching(ABC): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this
IMO this should be a utility class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored into a utility class.
src/robusta/utils/scope.py
Outdated
return False | ||
return True | ||
|
||
def scope_attribute_matches(self, attr_name: str, attr_matchers: List[str], aux_obj): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this code at all
src/robusta/utils/scope.py
Outdated
def scope_inc_exc_matches(self, scope_inc_exc: Optional[list]): | ||
return any(self.scope_matches(scope) for scope in scope_inc_exc) | ||
|
||
def scope_matches(self, scope: Dict[str, List[str]]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type here is ScopeIncludeExcludeParams
?
please add return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
src/robusta/utils/scope.py
Outdated
return False | ||
return True | ||
|
||
def scope_attribute_matches(self, attr_name: str, attr_matchers: List[str]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
src/robusta/utils/scope.py
Outdated
return False | ||
attr_value = data[attr_name] | ||
for attr_matcher in attr_matchers: | ||
if hasattr(self, f"scope_match_{attr_name}"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not clear
I would do:
if attr_name == "attributes":
return self.match_path_attributes(...)
Then, in match_path_attributes
, for each attribute path, run get_attribute_by_path
, and do the matching logic here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/robusta/utils/scope.py
Outdated
return True | ||
return False | ||
|
||
def match_labels_annotations(self, labels_match_expr: str, labels: Dict[str, str]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/robusta/utils/scope.py
Outdated
return False | ||
return True | ||
|
||
def label_matches(self, label_match: str, labels: Dict[str, str]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
49ee6b2
to
1e4c06e
Compare
1e4c06e
to
67d154b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice work
Implements
scope
matching for k8s server triggers.