From 87dba052787db01d2cbb26ef5d8aa5832a743b6e Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Thu, 11 Aug 2022 10:30:44 -0700 Subject: [PATCH] cluster-autoscaler: avoid goto in filterNodeGroupsByPods --- cluster-autoscaler/core/scale_up.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cluster-autoscaler/core/scale_up.go b/cluster-autoscaler/core/scale_up.go index 74f8c9570904..927ef8fa055e 100644 --- a/cluster-autoscaler/core/scale_up.go +++ b/cluster-autoscaler/core/scale_up.go @@ -664,26 +664,29 @@ func filterNodeGroupsByPods( result := make([]cloudprovider.NodeGroup, 0) -groupsloop: for _, group := range groups { option, found := expansionOptions[group.Id()] if !found { klog.V(1).Infof("No info about pods passing predicates found for group %v, skipping it from scale-up consideration", group.Id()) continue } - fittingPods := option.Pods - podSet := make(map[*apiv1.Pod]bool, len(fittingPods)) - for _, pod := range fittingPods { - podSet[pod] = true + fittingPods := make(map[*apiv1.Pod]bool, len(option.Pods)) + for _, pod := range option.Pods { + fittingPods[pod] = true } + allFit := true for _, pod := range podsRequiredToFit { - if _, found := podSet[pod]; !found { + if _, found := fittingPods[pod]; !found { klog.V(1).Infof("Group %v, can't fit pod %v/%v, removing from scale-up consideration", group.Id(), pod.Namespace, pod.Name) - continue groupsloop + allFit = false + break } } - result = append(result, group) + if allFit { + result = append(result, group) + } } + return result }