Skip to content

Conversation

@omerap12
Copy link
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

As discussed in #8773, The updater currently will list all pods when it attempts to find pods that are controlled by VPAs. This approach will only the pods based on the targetRef selector of the VPA object. Hence improve the performance

Which issue(s) this PR fixes:

Fixes #8773

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area labels Nov 13, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: omerap12

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

The pull request process is described 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 added approved Indicates a PR has been approved by an approver from all required OWNERS files. area/vertical-pod-autoscaler labels Nov 13, 2025
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed do-not-merge/needs-area labels Nov 13, 2025
Signed-off-by: Omer Aplatony <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 13, 2025
Signed-off-by: Omer Aplatony <[email protected]>
Comment on lines +198 to +204
for _, pod := range podsWithSelector {
uid := string(pod.UID)
if _, seen := seenPods[uid]; !seen {
seenPods[uid] = struct{}{}
podsList = append(podsList, pod)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this filtering needed?

Later on GetControllingVPAForPod is called, which finds the Pod's upper most controller, and compares that controller to the one defined in the VPA spec, see

func GetControllingVPAForPod(ctx context.Context, pod *core.Pod, vpas []*VpaWithSelector, ctrlFetcher controllerfetcher.ControllerFetcher) *VpaWithSelector {
parentController, err := FindParentControllerForPod(ctx, pod, ctrlFetcher)
if err != nil {
klog.ErrorS(err, "Failed to get parent controller for pod", "pod", klog.KObj(pod))
return nil
}
if parentController == nil {
return nil
}
var controlling *VpaWithSelector
var controllingVpa *vpa_types.VerticalPodAutoscaler
// Choose the strongest VPA from the ones that match this Pod.
for _, vpaWithSelector := range vpas {
if vpaWithSelector.Vpa.Spec.TargetRef == nil {
klog.V(5).InfoS("Skipping VPA object because targetRef is not defined. If this is a v1beta1 object, switch to v1", "vpa", klog.KObj(vpaWithSelector.Vpa))
continue
}
if vpaWithSelector.Vpa.Spec.TargetRef.Kind != parentController.Kind ||
vpaWithSelector.Vpa.Namespace != parentController.Namespace ||
vpaWithSelector.Vpa.Spec.TargetRef.Name != parentController.Name {
continue // This pod is not associated to the right controller
}
if PodMatchesVPA(pod, vpaWithSelector) && Stronger(vpaWithSelector.Vpa, controllingVpa) {
controlling = vpaWithSelector
controllingVpa = controlling.Vpa
}
}
return controlling
}

My assumption is that this filtering isn't needed here, as it will happen later.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. We want to ensure that the podsList doesn't contain duplicate pods.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if this is a good idea, but Kubernetes does provide a Set.
I wonder if that would be more memory efficient than maintaining a list and a map.

It is used in various other controllers (example), so I assume it's performant.

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/vertical-pod-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow VPA Updater to filter pods via label selector

3 participants