Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix/improve guess cached pod name#1342

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ganeshrvel wants to merge3 commits intomaster
base:master
Choose a base branch
Loading
fromfix/improve_guess_cached_pod_name

Conversation

@ganeshrvel
Copy link
Contributor

No description provided.

@moshemoradmoshemorad added the SilenceIgnored by schedule notification labelJun 22, 2025
@coderabbitai
Copy link

coderabbitaibot commentedJun 22, 2025
edited
Loading

Walkthrough

This update introduces theFindingOwner model to encapsulate Kubernetes resource ownership metadata and integrates it throughout the reporting, event, and discovery logic. Ownership information is now included inFindingSubject instances and leveraged in service key resolution, event enrichment, and Prometheus alert subject construction. TheTopServiceResolver and related logic are refactored to use this ownership context for improved resource association.

Changes

File(s)Change Summary
src/robusta/core/reporting/findings.pyNew module defining theFindingOwner Pydantic model for ownership metadata.
src/robusta/core/reporting/base.pyFindingSubject andFinding constructors updated to support and propagate an optionalowner parameter of typeFindingOwner.
src/robusta/core/reporting/consts.pyAddedTYPE_REPLICASET toFindingSubjectType enum; updatedfrom_kind to support"replicaset".
src/robusta/core/reporting/finding_subjects.pyKubeObjFindingSubject andPodFindingSubject now include anowner attribute derived from Kubernetes object metadata.
src/robusta/core/discovery/top_service_resolver.pyRefactoredTopServiceResolver to use ownership data inguess_service_key andguess_cached_resource; added pod owner reference caching and logic for controller kinds.
src/robusta/core/playbooks/internal/discovery_events.pyFindingOwner imported and used inFindingSubject creation;guess_service_key call updated to include kind and owner.
src/robusta/core/triggers/error_event_trigger.pyWarningEventTrigger.should_fire now passes resource kind andFindingOwner toguess_service_key for rate limiting.
src/robusta/integrations/kubernetes/autogenerated/events.py,scripts/generate_kubernetes_code.pyAll resource event classes’get_subject methods now returnFindingSubject with anowner field from object metadata.
src/robusta/integrations/prometheus/models.pyget_alert_subject now extracts and includes ownership metadata in the returnedFindingSubject.
playbooks/robusta_playbooks/babysitter.py,playbooks/robusta_playbooks/event_enrichments.pyAdded import and usage ofFindingOwner for enriching event findings with ownership data.

Sequence Diagram(s)

sequenceDiagram    participant EventSource as Event Source    participant EventHandler as Event Handler    participant FindingSubject    participant TopServiceResolver    participant FindingOwner    EventSource->>EventHandler: Receives Kubernetes event    EventHandler->>FindingOwner: Extract ownerReferences from event metadata    EventHandler->>FindingSubject: Create with owner=FindingOwner(...)    EventHandler->>TopServiceResolver: guess_service_key(name, namespace, kind, owner)    TopServiceResolver->>FindingOwner: Use owner info to resolve top-level resource    TopServiceResolver-->>EventHandler: Returns service key    EventHandler-->>EventSource: Processed event with enriched ownership context
Loading
sequenceDiagram    participant Prometheus as Prometheus Alert    participant AlertHandler as Alert Handler    participant FindingSubject    participant FindingOwner    Prometheus->>AlertHandler: Receives alert with resource metadata    AlertHandler->>FindingOwner: Extract ownerReferences from resource metadata    AlertHandler->>FindingSubject: Create with owner=FindingOwner(...)    AlertHandler-->>Prometheus: Returns enriched FindingSubject
Loading
sequenceDiagram    participant UserCode as User Code    participant Finding as Finding    participant TopServiceResolver    participant FindingOwner    UserCode->>Finding: Create Finding with FindingSubject(owner=FindingOwner)    Finding->>TopServiceResolver: guess_cached_resource(name, namespace, kind, owner)    TopServiceResolver->>FindingOwner: Use ownerReferences to find top-level resource    TopServiceResolver-->>Finding: Returns resolved resource info
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag@coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag@coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on oursupport page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings togenerate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add@coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add@coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a.coderabbit.yaml file to the root of your repository.
  • Please see theconfiguration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

Copy link

@coderabbitaicoderabbitaibot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (2)
playbooks/robusta_playbooks/babysitter.py (1)

24-24:Remove unused import.

TheFindingOwner import is not used anywhere in this file and should be removed to avoid dead code.

-from robusta.core.reporting.findings import FindingOwner
src/robusta/core/discovery/top_service_resolver.py (1)

76-114:Consider refactoring to reduce complexity.

The static analysis correctly identifies that this method has too many return statements (7/6). Consider extracting helper methods to improve readability and maintainability.

The logic could be broken down into smaller, focused methods like:

  • _handle_owner_references()
  • _handle_unknown_owner()
  • _handle_no_owner()

This would make the code more testable and easier to understand.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweenc496509 andfd63b7b.

📒 Files selected for processing (12)
  • playbooks/robusta_playbooks/babysitter.py (1 hunks)
  • playbooks/robusta_playbooks/event_enrichments.py (2 hunks)
  • scripts/generate_kubernetes_code.py (4 hunks)
  • src/robusta/core/discovery/top_service_resolver.py (3 hunks)
  • src/robusta/core/playbooks/internal/discovery_events.py (3 hunks)
  • src/robusta/core/reporting/base.py (4 hunks)
  • src/robusta/core/reporting/consts.py (2 hunks)
  • src/robusta/core/reporting/finding_subjects.py (3 hunks)
  • src/robusta/core/reporting/findings.py (1 hunks)
  • src/robusta/core/triggers/error_event_trigger.py (2 hunks)
  • src/robusta/integrations/kubernetes/autogenerated/events.py (39 hunks)
  • src/robusta/integrations/prometheus/models.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
playbooks/robusta_playbooks/babysitter.py

24-24:robusta.core.reporting.findings.FindingOwner imported but unused

Remove unused import:robusta.core.reporting.findings.FindingOwner

(F401)

src/robusta/integrations/kubernetes/autogenerated/events.py

102-102: Undefined nameFindingOwner

(F821)


165-165: Undefined nameFindingOwner

(F821)


189-189: Undefined nameFindingOwner

(F821)


223-223: Undefined nameFindingOwner

(F821)


247-247: Undefined nameFindingOwner

(F821)


281-281: Undefined nameFindingOwner

(F821)


305-305: Undefined nameFindingOwner

(F821)


339-339: Undefined nameFindingOwner

(F821)


363-363: Undefined nameFindingOwner

(F821)


397-397: Undefined nameFindingOwner

(F821)


421-421: Undefined nameFindingOwner

(F821)


455-455: Undefined nameFindingOwner

(F821)


479-479: Undefined nameFindingOwner

(F821)


513-513: Undefined nameFindingOwner

(F821)


537-537: Undefined nameFindingOwner

(F821)


571-571: Undefined nameFindingOwner

(F821)


595-595: Undefined nameFindingOwner

(F821)


629-629: Undefined nameFindingOwner

(F821)


653-653: Undefined nameFindingOwner

(F821)


687-687: Undefined nameFindingOwner

(F821)


711-711: Undefined nameFindingOwner

(F821)


745-745: Undefined nameFindingOwner

(F821)


769-769: Undefined nameFindingOwner

(F821)


803-803: Undefined nameFindingOwner

(F821)


827-827: Undefined nameFindingOwner

(F821)


861-861: Undefined nameFindingOwner

(F821)


885-885: Undefined nameFindingOwner

(F821)


919-919: Undefined nameFindingOwner

(F821)


943-943: Undefined nameFindingOwner

(F821)


977-977: Undefined nameFindingOwner

(F821)


1001-1001: Undefined nameFindingOwner

(F821)


1035-1035: Undefined nameFindingOwner

(F821)


1059-1059: Undefined nameFindingOwner

(F821)


1093-1093: Undefined nameFindingOwner

(F821)


1117-1117: Undefined nameFindingOwner

(F821)


1151-1151: Undefined nameFindingOwner

(F821)


1175-1175: Undefined nameFindingOwner

(F821)


1209-1209: Undefined nameFindingOwner

(F821)


1233-1233: Undefined nameFindingOwner

(F821)

🪛 Pylint (3.3.7)
src/robusta/core/reporting/findings.py

[refactor] 7-7: Too few public methods (0/2)

(R0903)

src/robusta/core/discovery/top_service_resolver.py

[refactor] 76-76: Too many return statements (7/6)

(R0911)

src/robusta/integrations/kubernetes/autogenerated/events.py

[error] 102-102: Undefined variable 'FindingOwner'

(E0602)


[error] 165-165: Undefined variable 'FindingOwner'

(E0602)


[error] 189-189: Undefined variable 'FindingOwner'

(E0602)


[error] 223-223: Undefined variable 'FindingOwner'

(E0602)


[error] 247-247: Undefined variable 'FindingOwner'

(E0602)


[error] 281-281: Undefined variable 'FindingOwner'

(E0602)


[error] 305-305: Undefined variable 'FindingOwner'

(E0602)


[error] 339-339: Undefined variable 'FindingOwner'

(E0602)


[error] 363-363: Undefined variable 'FindingOwner'

(E0602)


[error] 397-397: Undefined variable 'FindingOwner'

(E0602)


[error] 421-421: Undefined variable 'FindingOwner'

(E0602)


[error] 455-455: Undefined variable 'FindingOwner'

(E0602)


[error] 479-479: Undefined variable 'FindingOwner'

(E0602)


[error] 513-513: Undefined variable 'FindingOwner'

(E0602)


[error] 537-537: Undefined variable 'FindingOwner'

(E0602)


[error] 571-571: Undefined variable 'FindingOwner'

(E0602)


[error] 595-595: Undefined variable 'FindingOwner'

(E0602)


[error] 629-629: Undefined variable 'FindingOwner'

(E0602)


[error] 653-653: Undefined variable 'FindingOwner'

(E0602)


[error] 687-687: Undefined variable 'FindingOwner'

(E0602)


[error] 711-711: Undefined variable 'FindingOwner'

(E0602)


[error] 745-745: Undefined variable 'FindingOwner'

(E0602)


[error] 769-769: Undefined variable 'FindingOwner'

(E0602)


[error] 803-803: Undefined variable 'FindingOwner'

(E0602)


[error] 827-827: Undefined variable 'FindingOwner'

(E0602)


[error] 861-861: Undefined variable 'FindingOwner'

(E0602)


[error] 885-885: Undefined variable 'FindingOwner'

(E0602)


[error] 919-919: Undefined variable 'FindingOwner'

(E0602)


[error] 943-943: Undefined variable 'FindingOwner'

(E0602)


[error] 977-977: Undefined variable 'FindingOwner'

(E0602)


[error] 1001-1001: Undefined variable 'FindingOwner'

(E0602)


[error] 1035-1035: Undefined variable 'FindingOwner'

(E0602)


[error] 1059-1059: Undefined variable 'FindingOwner'

(E0602)


[error] 1093-1093: Undefined variable 'FindingOwner'

(E0602)


[error] 1117-1117: Undefined variable 'FindingOwner'

(E0602)


[error] 1151-1151: Undefined variable 'FindingOwner'

(E0602)


[error] 1175-1175: Undefined variable 'FindingOwner'

(E0602)


[error] 1209-1209: Undefined variable 'FindingOwner'

(E0602)


[error] 1233-1233: Undefined variable 'FindingOwner'

(E0602)

🔇 Additional comments (23)
playbooks/robusta_playbooks/event_enrichments.py (2)

43-43:Import looks good.

TheFindingOwner import is properly used in the file.


76-76:Ownership enrichment implemented correctly.

TheFindingOwner is properly constructed from the event's owner references and passed to theFindingSubject. This enriches the finding with ownership metadata as intended.

src/robusta/core/reporting/findings.py (1)

1-10:Well-structured data model for ownership metadata.

TheFindingOwner class properly encapsulates Kubernetes ownership information with appropriate fields and types. The Pylint warning about too few public methods is a false positive for data models.

src/robusta/core/reporting/consts.py (1)

50-50:Consistent enum extension for replicaset support.

TheTYPE_REPLICASET enum value and correspondingfrom_kind method case are properly added together, maintaining consistency in the enum implementation.

Also applies to: 66-67

src/robusta/core/triggers/error_event_trigger.py (2)

5-5:Import properly used.

TheFindingOwner import is correctly utilized in the service key resolution logic.


74-77:Enhanced service key resolution with ownership context.

The changes correctly extract thekind and create aFindingOwner instance with owner references to provide richer context for service key resolution. This improvement aligns with the broader ownership metadata integration.

src/robusta/core/playbooks/internal/discovery_events.py (3)

19-19:LGTM: Import addition is consistent with the ownership enhancement.

The import ofFindingOwner aligns with the broader changes to integrate ownership metadata.


85-87:LGTM: Enhanced service key resolution with ownership context.

The addition ofkind andowner parameters toTopServiceResolver.guess_service_key provides better context for service resolution. The implementation correctly passes the owner from the finding's subject.


81-81: ```shell
#!/usr/bin/env bash

Locate the file defining FindingOwner and inspect its constructor for None handling

1. Find class declaration

rg --no-heading "class FindingOwner" -n .

2. If found, display the class definition andinit body

FILE=$(rg -l "class FindingOwner" . | head -n1)
if [[ -n "$FILE" ]]; then
echo "=== Definition in $FILE ==="
rg -n "class FindingOwner" -A 15 "$FILE"
echo
echo "===init in $FILE ==="
rg -n "definit" -A 10 "$FILE"
else
echo "FindingOwner class not found in the repository."
fi

</details><details><summary>src/robusta/core/reporting/base.py (3)</summary>`17-17`: **LGTM: Import addition supports ownership metadata integration.**The import of `FindingOwner` is correctly added to support the new ownership functionality.---`205-205`: **LGTM: Well-designed optional owner parameter.**The `owner` parameter is properly implemented as optional with correct type annotation, maintaining backward compatibility while enabling ownership metadata.Also applies to: 214-214---`257-259`: **LGTM: Enhanced service resolution with ownership context.**The `TopServiceResolver.guess_cached_resource` call now includes ownership information, providing better context for service resolution. The parameters are correctly passed from the subject's attributes.</details><details><summary>src/robusta/core/reporting/finding_subjects.py (2)</summary>`4-4`: **LGTM: Import addition enables ownership metadata support.**The import of `FindingOwner` is correctly added to support the new ownership functionality in finding subjects.---`27-27`: ```shell#!/bin/bash# Locate the FindingOwner class definition and inspect its __init__ for None handlingrg -n "class FindingOwner" -C 5
src/robusta/integrations/prometheus/models.py (3)

9-9:LGTM: Imports correctly added for ownership metadata support.

The imports ofOwnerReference andFindingOwner are properly added to support the enhanced ownership functionality.

Also applies to: 13-13


143-197:LGTM: Comprehensive ownership metadata extraction.

The implementation systematically extractsownerReferences from all supported Kubernetes resource types (deployment, daemonset, statefulset, node, pod, job, hpa) and correctly sets theunknown_owner flag when no specific resource type is matched. This provides comprehensive ownership context for Prometheus alerts.


202-203:LGTM: Enhanced FindingSubject with ownership information.

TheFindingSubject constructor now includes theowner parameter with properly constructedFindingOwner object, maintaining consistency with the broader ownership enhancement across the codebase.

scripts/generate_kubernetes_code.py (3)

80-80:LGTM: Import added to autogenerated code template.

The import ofFindingOwner is correctly added to the code generation template, ensuring it will be available in all autogenerated Kubernetes event classes.


181-190:LGTM: Consistent ownership metadata integration in autogenerated events.

The pattern of addingowner=FindingOwner(owner_references=self.obj.metadata.ownerReferences) is consistently applied across all autogenerated event classes (base KubernetesResourceEvent, specific resource events, and change events). This ensures uniform ownership metadata support across the entire Kubernetes event system.

Also applies to: 265-274, 289-298


189-189: ```shell
#!/bin/bash

Search for the FindingOwner class definition and inspect its constructor

rg "class FindingOwner" -A10 -n

</details><details><summary>src/robusta/core/discovery/top_service_resolver.py (3)</summary>`6-6`: **LGTM! Required imports properly added.**The imports are correctly added to support the new ownership-aware functionality.Also applies to: 10-11---`32-32`: **LGTM! Caching strategy for owner references.**Adding a cache for owner references is a good optimization to avoid repeated API calls.---`58-60`: **LGTM! Method signature properly updated.**The method signature correctly includes the new ownership parameters and passes them through to the updated guess_cached_resource method.</details></blockquote></details></details><!-- This is an auto-generated comment by CodeRabbit for review status -->

Comment on lines +63 to +73
defget_pod_owner_reference(cls,name:str,namespace:str)->Optional[OwnerReference]:
key=f"{namespace}/{name}"
ifkeyincls.__cached_owner_references:
returncls.__cached_owner_references[key]

robusta_pod=RobustaPod.find_pod(name,namespace)
ifrobusta_pod.metadata.ownerReferences:
cls.__cached_owner_references[key]=robusta_pod.metadata.ownerReferences[0]
returnrobusta_pod.metadata.ownerReferences[0]

returnNone

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for pod retrieval.

The method lacks error handling for cases whereRobustaPod.find_pod might fail or return None.

 @classmethod def get_pod_owner_reference(cls, name: str, namespace: str) -> Optional[OwnerReference]:     key = f"{namespace}/{name}"     if key in cls.__cached_owner_references:         return cls.__cached_owner_references[key]+    try:         robusta_pod = RobustaPod.find_pod(name, namespace)-        if robusta_pod.metadata.ownerReferences:+        if robusta_pod and robusta_pod.metadata and robusta_pod.metadata.ownerReferences:             cls.__cached_owner_references[key] = robusta_pod.metadata.ownerReferences[0]             return robusta_pod.metadata.ownerReferences[0]+    except Exception:+        # Log error or handle gracefully+        pass      return None
📝 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
defget_pod_owner_reference(cls,name:str,namespace:str)->Optional[OwnerReference]:
key=f"{namespace}/{name}"
ifkeyincls.__cached_owner_references:
returncls.__cached_owner_references[key]
robusta_pod=RobustaPod.find_pod(name,namespace)
ifrobusta_pod.metadata.ownerReferences:
cls.__cached_owner_references[key]=robusta_pod.metadata.ownerReferences[0]
returnrobusta_pod.metadata.ownerReferences[0]
returnNone
defget_pod_owner_reference(cls,name:str,namespace:str)->Optional[OwnerReference]:
key=f"{namespace}/{name}"
ifkeyincls.__cached_owner_references:
returncls.__cached_owner_references[key]
try:
robusta_pod=RobustaPod.find_pod(name,namespace)
ifrobusta_podandrobusta_pod.metadataandrobusta_pod.metadata.ownerReferences:
cls.__cached_owner_references[key]=robusta_pod.metadata.ownerReferences[0]
returnrobusta_pod.metadata.ownerReferences[0]
exceptException:
# Log error or handle gracefully
pass
returnNone
🤖 Prompt for AI Agents
In src/robusta/core/discovery/top_service_resolver.py around lines 63 to 73, themethod get_pod_owner_reference does not handle errors or None returns fromRobustaPod.find_pod. Add a check after calling find_pod to verify the pod wasfound; if not, handle the error gracefully by returning None or logging anappropriate message. This prevents attribute errors when accessing metadata on aNone object.

Comment on lines +94 to +97
ifowner_kind=="replicaset":
new_owner_reference=cls.get_pod_owner_reference(name=owner_reference.name,namespace=namespace)
returnTopLevelResource(name=new_owner_reference.name,resource_type=new_owner_reference.kind,
namespace=namespace)

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle potential None return from get_pod_owner_reference.

The code doesn't handle the case whereget_pod_owner_reference returns None, which could cause an AttributeError.

 # replicset if owner_kind == "replicaset":     new_owner_reference = cls.get_pod_owner_reference(name=owner_reference.name, namespace=namespace)+    if not new_owner_reference:+        return TopLevelResource(name=name, resource_type=kind, namespace=namespace)     return TopLevelResource(name=new_owner_reference.name, resource_type=new_owner_reference.kind,                             namespace=namespace)
📝 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
ifowner_kind=="replicaset":
new_owner_reference=cls.get_pod_owner_reference(name=owner_reference.name,namespace=namespace)
returnTopLevelResource(name=new_owner_reference.name,resource_type=new_owner_reference.kind,
namespace=namespace)
ifowner_kind=="replicaset":
new_owner_reference=cls.get_pod_owner_reference(name=owner_reference.name,namespace=namespace)
ifnotnew_owner_reference:
returnTopLevelResource(name=name,resource_type=kind,namespace=namespace)
returnTopLevelResource(name=new_owner_reference.name,resource_type=new_owner_reference.kind,
namespace=namespace)
🤖 Prompt for AI Agents
In src/robusta/core/discovery/top_service_resolver.py around lines 94 to 97, thecall to get_pod_owner_reference may return None, leading to an AttributeErrorwhen accessing its attributes. Add a check after calling get_pod_owner_referenceto verify the result is not None before accessing its name and kind. If it isNone, handle this case appropriately, such as returning None or raising a clearexception.

node=KubeObjFindingSubject.get_node_name(self.obj),
labels=self.obj.metadata.labels,
annotations=self.obj.metadata.annotations,
owner=FindingOwner(owner_references=self.obj.metadata.ownerReferences)

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Missing import for FindingOwner.

The file usesFindingOwner throughout but doesn't import it, which will cause runtime failures.

Add the missing import at the top of the file:

 from ....core.reporting.base import FindingSubject from ....core.reporting.consts import FindingSubjectType, FindingSource+from ....core.reporting.findings import FindingOwner from ....core.reporting.finding_subjects import KubeObjFindingSubject

The pattern of adding ownership information toFindingSubject instances is consistent and correct across all event classes.

Also applies to: 165-165, 189-189, 223-223, 247-247, 281-281, 305-305, 339-339, 363-363, 397-397, 421-421, 455-455, 479-479, 513-513, 537-537, 571-571, 595-595, 629-629, 653-653, 687-687, 711-711, 745-745, 769-769, 803-803, 827-827, 861-861, 885-885, 919-919, 943-943, 977-977, 1001-1001, 1035-1035, 1059-1059, 1093-1093, 1117-1117, 1151-1151, 1175-1175, 1209-1209, 1233-1233

🧰 Tools
🪛 Ruff (0.11.9)

102-102: Undefined nameFindingOwner

(F821)

🪛 Pylint (3.3.7)

[error] 102-102: Undefined variable 'FindingOwner'

(E0602)

🤖 Prompt for AI Agents
In src/robusta/integrations/kubernetes/autogenerated/events.py at lines 102,165, 189, 223, 247, 281, 305, 339, 363, 397, 421, 455, 479, 513, 537, 571, 595,629, 653, 687, 711, 745, 769, 803, 827, 861, 885, 919, 943, 977, 1001, 1035,1059, 1093, 1117, 1151, 1175, 1209, and 1233, the code uses FindingOwner butdoes not import it, causing runtime errors. To fix this, add the appropriateimport statement for FindingOwner at the top of the file, ensuring it isimported from its correct module so all references to FindingOwner are resolvedproperly.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@coderabbitaicoderabbitai[bot]coderabbitai[bot] left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

SilenceIgnored by schedule notification

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@ganeshrvel@moshemorad

[8]ページ先頭

©2009-2025 Movatter.jp