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
27 changes: 26 additions & 1 deletion tests/test_change_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the unused DEFAULT_CHANGE_INCLUDE import.

Flake8 reports this import as unused (F401), so it should be removed before merge.

Proposed fix
 from robusta.integrations.kubernetes.base_triggers import (
     DEFAULT_CHANGE_FILTERS,
     DEFAULT_CHANGE_IGNORE,
-    DEFAULT_CHANGE_INCLUDE,
     K8sBaseTrigger,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DEFAULT_CHANGE_IGNORE,
from robusta.integrations.kubernetes.base_triggers import (
DEFAULT_CHANGE_FILTERS,
DEFAULT_CHANGE_IGNORE,
K8sBaseTrigger,
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_change_filters.py` at line 17, Remove the unused
DEFAULT_CHANGE_INCLUDE import from the imports in tests/test_change_filters.py,
leaving the required DEFAULT_CHANGE_IGNORE import and other dependencies
unchanged.

Source: Linters/SAST tools

DEFAULT_CHANGE_INCLUDE,
K8sBaseTrigger,
K8sTriggerChangeFilters,
)
from robusta.integrations.kubernetes.custom_models import RobustaDeployment


class TestK8sBaseTrigger:
Expand Down Expand Up @@ -81,3 +86,23 @@ 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.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 on lines +99 to +108

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Cover labels and annotations in the regression test.

The stated contract includes preserving subject.labels and subject.annotations, but this test only verifies namespace and name. Add assertions for both fields against the fixture’s metadata so regressions in the complete subject are detected.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_change_filters.py` around lines 99 - 108, Extend
test_default_finding_keeps_subject_and_source to assert that
finding.subject.labels and finding.subject.annotations match the corresponding
labels and annotations in the event fixture metadata, alongside the existing
namespace and name checks.