Skip to content

Commit

Permalink
Add unit test for long-terminating pod past grace period
Browse files Browse the repository at this point in the history
  • Loading branch information
artemvmin committed Oct 10, 2023
1 parent 9a7459c commit 33e300f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 0 additions & 3 deletions cluster-autoscaler/simulator/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ func GetPodsToMove(nodeInfo *schedulerframework.NodeInfo, deleteOptions options.
status := drainabilityRules.Drainable(drainCtx, pod)
switch status.Outcome {
case drainability.UndefinedOutcome, drainability.DrainOk:
if drain.IsPodLongTerminating(pod, timestamp) {
continue
}
if pod_util.IsDaemonSetPod(pod) {
daemonSetPods = append(daemonSetPods, pod)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,23 @@ func TestDrainable(t *testing.T) {
want: drainability.NewUndefinedStatus(),
},
"long terminating pod with 0 grace period": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "default",
DeletionTimestamp: &metav1.Time{Time: testTime.Add(drain.PodLongTerminatingExtraThreshold / 2)},
},
Spec: apiv1.PodSpec{
RestartPolicy: apiv1.RestartPolicyOnFailure,
TerminationGracePeriodSeconds: &zeroGracePeriod,
},
Status: apiv1.PodStatus{
Phase: apiv1.PodUnknown,
},
},
want: drainability.NewUndefinedStatus(),
},
"expired long terminating pod with 0 grace period": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Expand All @@ -64,6 +81,23 @@ func TestDrainable(t *testing.T) {
want: drainability.NewSkipStatus(),
},
"long terminating pod with extended grace period": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "default",
DeletionTimestamp: &metav1.Time{Time: testTime.Add(time.Duration(extendedGracePeriod) / 2 * time.Second)},
},
Spec: apiv1.PodSpec{
RestartPolicy: apiv1.RestartPolicyOnFailure,
TerminationGracePeriodSeconds: &extendedGracePeriod,
},
Status: apiv1.PodStatus{
Phase: apiv1.PodUnknown,
},
},
want: drainability.NewUndefinedStatus(),
},
"expired long terminating pod with extended grace period": {
pod: &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Expand Down

0 comments on commit 33e300f

Please sign in to comment.