Skip to content

Add optional label selector to KubeList for server-side pod filtering#4772

Open
aasserzo wants to merge 5 commits intomasterfrom
aasserzo/kubelist-improve
Open

Add optional label selector to KubeList for server-side pod filtering#4772
aasserzo wants to merge 5 commits intomasterfrom
aasserzo/kubelist-improve

Conversation

@aasserzo
Copy link
Copy Markdown
Collaborator

What this PR does / why we need it

This PR enhances the KubeList function to support server-side label selector filtering and uses this capability to improve the API server pod validation in the control plane VM resize pre-flight checks.

Changes

  1. Extended KubeList with optional label selector parameter

    • Added variadic labelSelector ...string parameter to KubeList in the KubeActions interface
    • Existing callers are unaffected (no breaking changes)
    • New callers can pass a label selector for server-side filtering
  2. Improved API server pod validation

    • Switched from client-side pod filtering to server-side label selector filtering
    • Uses app=openshift-kube-apiserver label selector to fetch only relevant pods
    • Removed client-side label filtering loop, simplifying the code
    • Reduces network overhead and eliminates risk from unrelated pods in the namespace

Which issue this PR addresses

Follow-up improvement to the control plane VM resize pre-validation feature, addressing reviewer feedback to use server-side filtering for pod selection.

Test plan

  • Unit tests updated to verify label selector is correctly passed to KubeList
  • Existing test coverage for validateAPIServerPods updated to reflect server-side filtering behavior
  • All existing tests pass (make unit-test-go, make lint-go)

Is there any documentation that needs to be updated for this PR?

No documentation changes required. This is an internal implementation improvement.

How do you know this will function as expected in production?

  1. The Kubernetes API natively supports label selectors in list operations
  2. An empty label selector (default) returns all resources, maintaining backward compatibility
  3. Unit tests verify the label selector is correctly passed through to the Kubernetes client
  4. The change reduces complexity by moving filtering from client-side to server-side

Copy link
Copy Markdown
Collaborator

@tuxerrante tuxerrante left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Collaborator

@mrWinston mrWinston left a comment

Choose a reason for hiding this comment

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

Nice PR! I do like using a variadic arg to have the labelSelector optional.
However, instead of requiring the array to have either 0 or 1 elements, I think it'd be more intuitive to support an arbitrary number of label selectors and join them to create the final one, eg:

i pass in something like []string{"app=frontend", "env=prod"} and they get combined into app=frontend,env=prod.

So basically, just calling

selector := strings.Join(labelSelector, ",")

@github-actions github-actions Bot added the needs-rebase branch needs a rebase label Apr 15, 2026
@github-actions
Copy link
Copy Markdown

Please rebase pull request.

@github-actions github-actions Bot removed the needs-rebase branch needs a rebase label Apr 15, 2026
@aasserzo
Copy link
Copy Markdown
Collaborator Author

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@aasserzo aasserzo requested a review from mrWinston April 24, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants