Skip to content

Commit cb3b524

Browse files
committed
use Set only
Signed-off-by: Omer Aplatony <[email protected]>
1 parent ac977ed commit cb3b524

File tree

1 file changed

+12
-11
lines changed
  • vertical-pod-autoscaler/pkg/updater/logic

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
apiv1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/fields"
2828
"k8s.io/apimachinery/pkg/labels"
29-
"k8s.io/apimachinery/pkg/util/sets"
3029
kube_client "k8s.io/client-go/kubernetes"
3130
"k8s.io/client-go/kubernetes/fake"
3231
corescheme "k8s.io/client-go/kubernetes/scheme"
@@ -167,8 +166,7 @@ func (u *updater) RunOnce(ctx context.Context) {
167166

168167
inPlaceFeatureEnable := features.Enabled(features.InPlaceOrRecreate)
169168

170-
var podsList []*apiv1.Pod
171-
seenPods := sets.New[string]()
169+
seenPods := make(map[string]*apiv1.Pod)
172170

173171
for _, vpa := range vpaList {
174172
if slices.Contains(u.ignoredNamespaces, vpa.Namespace) {
@@ -197,9 +195,8 @@ func (u *updater) RunOnce(ctx context.Context) {
197195

198196
// handle the case of overlapping VPA selectors
199197
for _, pod := range podsWithSelector {
200-
if !seenPods.Has(pod.Name) {
201-
seenPods.Insert(pod.Name)
202-
podsList = append(podsList, pod)
198+
if _, exists := seenPods[pod.Name]; !exists {
199+
seenPods[pod.Name] = pod
203200
}
204201
}
205202

@@ -218,7 +215,7 @@ func (u *updater) RunOnce(ctx context.Context) {
218215
}
219216

220217
timer.ObserveStep("ListPods")
221-
allLivePods := filterDeletedPods(podsList)
218+
allLivePods := filterDeletedPodsFromMap(seenPods)
222219

223220
controlledPods := make(map[*vpa_types.VerticalPodAutoscaler][]*apiv1.Pod)
224221
for _, pod := range allLivePods {
@@ -403,10 +400,14 @@ func filterNonEvictablePods(pods []*apiv1.Pod, evictionRestriction restriction.P
403400
return filterPods(pods, evictionRestriction.CanEvict)
404401
}
405402

406-
func filterDeletedPods(pods []*apiv1.Pod) []*apiv1.Pod {
407-
return filterPods(pods, func(pod *apiv1.Pod) bool {
408-
return pod.DeletionTimestamp == nil
409-
})
403+
func filterDeletedPodsFromMap(podsMap map[string]*apiv1.Pod) []*apiv1.Pod {
404+
result := make([]*apiv1.Pod, 0, len(podsMap))
405+
for _, pod := range podsMap {
406+
if pod.DeletionTimestamp == nil {
407+
result = append(result, pod)
408+
}
409+
}
410+
return result
410411
}
411412

412413
func newPodLister(kubeClient kube_client.Interface, namespace string) v1lister.PodLister {

0 commit comments

Comments
 (0)