Skip to content

Commit ce28c13

Browse files
committed
updater: fetch pods matching VPA selectors
Signed-off-by: Omer Aplatony <[email protected]>
1 parent 51b6969 commit ce28c13

File tree

1 file changed

+17
-5
lines changed
  • vertical-pod-autoscaler/pkg/updater/logic

1 file changed

+17
-5
lines changed

vertical-pod-autoscaler/pkg/updater/logic/updater.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ func (u *updater) RunOnce(ctx context.Context) {
166166

167167
inPlaceFeatureEnable := features.Enabled(features.InPlaceOrRecreate)
168168

169+
var podsList []*apiv1.Pod
170+
seenPods := make(map[string]struct{})
171+
169172
for _, vpa := range vpaList {
170173
if slices.Contains(u.ignoredNamespaces, vpa.Namespace) {
171174
klog.V(3).InfoS("Skipping VPA object in ignored namespace", "vpa", klog.KObj(vpa), "namespace", vpa.Namespace)
@@ -185,6 +188,20 @@ func (u *updater) RunOnce(ctx context.Context) {
185188
klog.V(3).InfoS("Skipping VPA object because we cannot fetch selector", "vpa", klog.KObj(vpa))
186189
continue
187190
}
191+
podsWithSelector, err := u.podLister.List(selector)
192+
if err != nil {
193+
klog.ErrorS(err, "Failed to get pods", "selector", selector)
194+
continue
195+
}
196+
197+
// handle the case of overlapping VPA selectors
198+
for _, pod := range podsWithSelector {
199+
uid := string(pod.UID)
200+
if _, seen := seenPods[uid]; !seen {
201+
seenPods[uid] = struct{}{}
202+
podsList = append(podsList, pod)
203+
}
204+
}
188205

189206
vpas = append(vpas, &vpa_api_util.VpaWithSelector{
190207
Vpa: vpa,
@@ -200,11 +217,6 @@ func (u *updater) RunOnce(ctx context.Context) {
200217
return
201218
}
202219

203-
podsList, err := u.podLister.List(labels.Everything())
204-
if err != nil {
205-
klog.ErrorS(err, "Failed to get pods list")
206-
return
207-
}
208220
timer.ObserveStep("ListPods")
209221
allLivePods := filterDeletedPods(podsList)
210222

0 commit comments

Comments
 (0)