Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/robusta/integrations/kubernetes/base_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def create_default_finding(self) -> Finding:
return Finding(
title=title,
aggregation_key="GenericChange",
subject=self.get_subject(),
source=self.get_source(),
)

@classmethod
Expand Down
30 changes: 28 additions & 2 deletions tests/test_change_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
from hikaru.model.rel_1_26 import Deployment

from robusta.core.model.k8s_operation_type import K8sOperationType
from robusta.integrations.kubernetes.autogenerated.events import KubernetesAnyChangeEvent
from robusta.core.reporting import FindingSource
from robusta.integrations.kubernetes.autogenerated.events import (
DeploymentChangeEvent,
KubernetesAnyChangeEvent,
)
from robusta.integrations.kubernetes.base_triggers import (
DEFAULT_CHANGE_FILTERS,
DEFAULT_CHANGE_IGNORE,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
DEFAULT_CHANGE_INCLUDE,
K8sBaseTrigger,
K8sTriggerChangeFilters,
)
from robusta.integrations.kubernetes.custom_models import RobustaDeployment


class TestK8sBaseTrigger:
Expand Down Expand Up @@ -81,3 +85,25 @@ def test_check_change_filters_changes(
assert diff.formatted_path == expected_change_path
assert diff.other_value == old_value
assert diff.value == expected_diff_new_value


class TestK8sBaseChangeEventDefaultFinding:
@pytest.fixture()
def event(self):
with open("tests/k8s_change_obj.json") as f:
data = json.loads(f.read())
obj = hikaru.from_dict(data, RobustaDeployment)
return DeploymentChangeEvent(operation=K8sOperationType.UPDATE, old_obj=obj, obj=obj)

def test_default_finding_keeps_subject_and_source(self, event):
finding = event.create_default_finding()

assert finding.aggregation_key == "GenericChange"
assert finding.subject.namespace == "default"
assert finding.subject.name == "xxx-deployment"
assert finding.subject.labels == {"app": "xxx"}
assert finding.subject.annotations == {"deployment.kubernetes.io/revision": "24"}
assert finding.source == FindingSource.KUBERNETES_API_SERVER
# sink routing/grouping reads these, so they must not fall back to "None"
assert finding.attribute_map["namespace"] == "default"
assert finding.attribute_map["name"] == "xxx-deployment"
Comment thread
coderabbitai[bot] marked this conversation as resolved.