diff --git a/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes.go b/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes.go index 495aae1c08f8..58459da50f17 100644 --- a/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes.go +++ b/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes.go @@ -51,6 +51,11 @@ func currentlyDrainedPods(context *context.AutoscalingContext) []*apiv1.Pod { continue } for _, podInfo := range nodeInfo.Pods { + // Filter out pods that has deletion timestamp set + if podInfo.Pod.DeletionTimestamp != nil { + klog.Infof("Pod %v has deletion timestamp set, skipping injection to unschedulable pods list", podInfo.Pod.Name) + continue + } pods = append(pods, podInfo.Pod) } } diff --git a/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes_test.go b/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes_test.go index 678afbd05709..0aebcbd4d671 100644 --- a/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes_test.go +++ b/cluster-autoscaler/core/podlistprocessor/currently_drained_nodes_test.go @@ -69,6 +69,20 @@ func TestCurrentlyDrainedNodesPodListProcessor(t *testing.T) { BuildTestPod("p2", 200, 1), }, }, + { + name: "single node undergoing deletion, pods with deletion timestamp set", + drainedNodes: []string{"n"}, + nodes: []*apiv1.Node{ + BuildTestNode("n", 1000, 10), + }, + pods: []*apiv1.Pod{ + BuildScheduledTestPod("p1", 100, 1, "n"), + BuildTestPod("p2", 200, 1, WithNodeName("n"), WithDeletionTimestamp(time.Now())), + }, + wantPods: []*apiv1.Pod{ + BuildTestPod("p1", 100, 1), + }, + }, { name: "single empty node undergoing deletion", drainedNodes: []string{"n"}, diff --git a/cluster-autoscaler/utils/test/test_utils.go b/cluster-autoscaler/utils/test/test_utils.go index 81c939cbfc43..de868d1ef9c9 100644 --- a/cluster-autoscaler/utils/test/test_utils.go +++ b/cluster-autoscaler/utils/test/test_utils.go @@ -150,6 +150,13 @@ func WithMaxSkew(maxSkew int32, topologySpreadingKey string) func(*apiv1.Pod) { } } +// WithDeletionTimestamp sets deletion timestamp to the pod. +func WithDeletionTimestamp(deletionTimestamp time.Time) func(*apiv1.Pod) { + return func(pod *apiv1.Pod) { + pod.DeletionTimestamp = &metav1.Time{Time: deletionTimestamp} + } +} + // BuildTestPodWithEphemeralStorage creates a pod with cpu, memory and ephemeral storage resources. func BuildTestPodWithEphemeralStorage(name string, cpu, mem, ephemeralStorage int64) *apiv1.Pod { startTime := metav1.Unix(0, 0)