Skip to content

Commit 9c5507e

Browse files
pass list of destination names, not map
1 parent f1a84f4 commit 9c5507e

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

cluster-autoscaler/core/scale_down.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,6 @@ func (sd *ScaleDown) UpdateUnneededNodes(
417417
// This should never happen, List() returns err only because scheduler interface requires it.
418418
return errors.ToAutoscalerError(errors.InternalError, err)
419419
}
420-
destinations := make(map[string]bool, len(destinationNodes))
421-
for _, destination := range destinationNodes {
422-
destinations[destination.Name] = true
423-
}
424420

425421
sd.updateUnremovableNodes()
426422

@@ -500,6 +496,11 @@ func (sd *ScaleDown) UpdateUnneededNodes(
500496
// Phase2 - check which nodes can be probably removed using fast drain.
501497
currentCandidates, currentNonCandidates := sd.chooseCandidates(currentlyUnneededNonEmptyNodes)
502498

499+
destinations := make([]string, 0, len(destinationNodes))
500+
for _, destinationNode := range destinationNodes {
501+
destinations = append(destinations, destinationNode.Name)
502+
}
503+
503504
// Look for nodes to remove in the current candidates
504505
nodesToRemove, unremovable, newHints, simulatorErr := simulator.FindNodesToRemove(
505506
currentCandidates,
@@ -751,7 +752,7 @@ func (sd *ScaleDown) TryToScaleDown(pdbs []*policyv1.PodDisruptionBudget, curren
751752
}
752753

753754
nodesWithoutMaster := filterOutMasters(allNodeInfos)
754-
nodesWithoutMasterNames := make(map[string]bool, len(nodesWithoutMaster))
755+
nodesWithoutMasterNames := make([]string, 0, len(nodesWithoutMaster))
755756

756757
candidateNames := make([]string, 0)
757758
readinessMap := make(map[string]bool)
@@ -771,7 +772,7 @@ func (sd *ScaleDown) TryToScaleDown(pdbs []*policyv1.PodDisruptionBudget, curren
771772
resourcesWithLimits := resourceLimiter.GetResources()
772773
for _, nodeInfo := range nodesWithoutMaster {
773774
node := nodeInfo.Node()
774-
nodesWithoutMasterNames[node.Name] = true
775+
nodesWithoutMasterNames = append(nodesWithoutMasterNames, node.Name)
775776

776777
unneededSince, found := sd.unneededNodes[node.Name]
777778
if !found {

cluster-autoscaler/simulator/cluster.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ type UtilizationInfo struct {
113113
// rescheduling location for each of the pods.
114114
func FindNodesToRemove(
115115
candidates []string,
116-
destinations map[string]bool,
116+
destinations []string,
117117
listers kube_util.ListerRegistry,
118118
clusterSnapshot ClusterSnapshot,
119119
predicateChecker PredicateChecker,
@@ -134,6 +134,11 @@ func FindNodesToRemove(
134134
}
135135
newHints := make(map[string]string, len(oldHints))
136136

137+
destinationMap := make(map[string]bool, len(destinations))
138+
for _, destination := range destinations {
139+
destinationMap[destination] = true
140+
}
141+
137142
candidateloop:
138143
for _, nodeName := range candidates {
139144
nodeInfo, err := clusterSnapshot.NodeInfos().Get(nodeName)
@@ -145,7 +150,7 @@ candidateloop:
145150
var podsToRemove []*apiv1.Pod
146151
var blockingPod *drain.BlockingPod
147152

148-
if _, found := destinations[nodeName]; !found {
153+
if _, found := destinationMap[nodeName]; !found {
149154
klog.V(2).Infof("%s: nodeInfo for %s not found", evaluationType, nodeName)
150155
unremovable = append(unremovable, &UnremovableNode{Node: nodeInfo.Node(), Reason: UnexpectedError})
151156
continue candidateloop
@@ -169,7 +174,7 @@ candidateloop:
169174
continue candidateloop
170175
}
171176

172-
findProblems := findPlaceFor(nodeName, podsToRemove, destinations, clusterSnapshot,
177+
findProblems := findPlaceFor(nodeName, podsToRemove, destinationMap, clusterSnapshot,
173178
predicateChecker, oldHints, newHints, usageTracker, timestamp)
174179

175180
if findProblems == nil {

cluster-autoscaler/simulator/cluster_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ func TestFindNodesToRemove(t *testing.T) {
369369

370370
for _, test := range tests {
371371
t.Run(test.name, func(t *testing.T) {
372-
destinations := map[string]bool{}
372+
destinations := make([]string, 0, len(test.allNodes))
373373
for _, node := range test.allNodes {
374-
destinations[node.Name] = true
374+
destinations = append(destinations, node.Name)
375375
}
376376
InitializeClusterSnapshotOrDie(t, clusterSnapshot, test.allNodes, test.pods)
377377
toRemove, unremovable, _, err := FindNodesToRemove(

0 commit comments

Comments
 (0)