Skip to content

Commonize filtering of Pods by Owner with all orphans in namespace #132615

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mimowo
Copy link
Contributor

@mimowo mimowo commented Jun 30, 2025

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

DRY principle, as part of #130767

Which issue(s) this PR is related to:

Special notes for your reviewer:

The duplication was observed when solving subtle issues in previous PR

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jun 30, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mimowo
Once this PR has been reviewed and has the lgtm label, please assign andrewsykim for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from kow3ns and krmayankk June 30, 2025 06:13
@mimowo
Copy link
Contributor Author

mimowo commented Jun 30, 2025

/sig apps
cc @xigang @hakuna-matatah @atiratree

@k8s-ci-robot k8s-ci-robot added the sig/apps Categorizes an issue or PR as relevant to SIG Apps. label Jun 30, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jun 30, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in SIG Apps Jun 30, 2025
@xigang
Copy link
Member

xigang commented Jun 30, 2025

LGTM.

@xigang
Copy link
Member

xigang commented Jun 30, 2025

/cc @wojtek-t
PTAL.

@k8s-ci-robot k8s-ci-robot requested a review from wojtek-t June 30, 2025 06:31
@hakuna-matatah
Copy link
Contributor

/lgtm

Thanks @mimowo

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 30, 2025
@k8s-ci-robot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 1c94a333d2b70694ed6187acec26169e0641cba1

result := []*v1.Pod{}
// Iterate over two keys:
// - the UID of the owner, which identifies Pods that are controlled by the owner
// - the OrphanPodIndexKey, which identifies orphaned Pods in the owner's namespace
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// - the OrphanPodIndexKey, which identifies orphaned Pods in the owner's namespace
// - the OrphanPodIndexKey, which identifies orphaned Pods in the owner's namespace and might be adopted by the owner later

@@ -1112,6 +1113,29 @@ func AddPodControllerUIDIndexer(podInformer cache.SharedIndexInformer) error {
})
}

// FilterPodsByOwner gets the Pods managed by an owner or orphan Pods in the owner's namespace
func FilterPodsByOwner(podIndexer cache.Indexer, owner *metav1.ObjectMeta) ([]*v1.Pod, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can we take this refactoring as an opportunity to introduce a simple unit test?

@atiratree
Copy link
Member

/triage accepted
/priority backlog

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. priority/backlog Higher priority than priority/awaiting-more-evidence. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/backlog Higher priority than priority/awaiting-more-evidence. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

5 participants