Skip to content

Commit 239c486

Browse files
authored
Merge pull request kubernetes#3622 from vivekbagade/master
Ensure CA simulator takes existing nodes into account
2 parents 904ccb2 + 1f95298 commit 239c486

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cluster-autoscaler/simulator/cluster.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ func findPlaceFor(removedNode string, pods []*apiv1.Pod, nodes map[string]bool,
294294
return fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)
295295
}
296296

297+
isCandidateNode := func(nodeName string) bool {
298+
return nodeName != removedNode && nodes[nodeName]
299+
}
300+
297301
pods = tpu.ClearTPURequests(pods)
298302

299303
// remove pods from clusterSnapshot first
@@ -314,7 +318,7 @@ func findPlaceFor(removedNode string, pods []*apiv1.Pod, nodes map[string]bool,
314318

315319
klog.V(5).Infof("Looking for place for %s/%s", pod.Namespace, pod.Name)
316320

317-
if hintedNode, hasHint := oldHints[podKey(pod)]; hasHint && hintedNode != removedNode {
321+
if hintedNode, hasHint := oldHints[podKey(pod)]; hasHint && isCandidateNode(hintedNode) {
318322
if err := predicateChecker.CheckPredicates(clusterSnapshot, pod, hintedNode); err == nil {
319323
klog.V(4).Infof("Pod %s/%s can be moved to %s", pod.Namespace, pod.Name, hintedNode)
320324
if err := clusterSnapshot.AddPod(pod, hintedNode); err != nil {
@@ -328,7 +332,7 @@ func findPlaceFor(removedNode string, pods []*apiv1.Pod, nodes map[string]bool,
328332

329333
if !foundPlace {
330334
newNodeName, err := predicateChecker.FitsAnyNodeMatching(clusterSnapshot, pod, func(nodeInfo *schedulerframework.NodeInfo) bool {
331-
return nodeInfo.Node().Name != removedNode
335+
return isCandidateNode(nodeInfo.Node().Name)
332336
})
333337
if err == nil {
334338
klog.V(4).Infof("Pod %s/%s can be moved to %s", pod.Namespace, pod.Name, newNodeName)

0 commit comments

Comments
 (0)