Skip to content

Commit

Permalink
Merge pull request #6725 from ZihanJiang96/filter-out-evicted-pod-on-…
Browse files Browse the repository at this point in the history
…drained-nodes-1

filter out pods that have deletion timestamp set in currentlyDrainedPods
  • Loading branch information
k8s-ci-robot authored Apr 30, 2024
2 parents 7c86e28 + e6ab343 commit 3fd892a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
7 changes: 7 additions & 0 deletions cluster-autoscaler/utils/test/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3fd892a

Please sign in to comment.