Skip to content

Commit

Permalink
avoid pod being terminating for a long time
Browse files Browse the repository at this point in the history
  • Loading branch information
ycfnana committed Jun 18, 2023
1 parent 2721275 commit e4cf4c6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/scheduler/api/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api

import (
"fmt"
"time"

v1 "k8s.io/api/core/v1"
clientcache "k8s.io/client-go/tools/cache"
Expand All @@ -33,15 +34,22 @@ func PodKey(pod *v1.Pod) TaskID {
}

func getTaskStatus(pod *v1.Pod) TaskStatus {
var gracePeriodSeconds int64 = 30
if pod.Spec.TerminationGracePeriodSeconds != nil {
// default grace period
gracePeriodSeconds = *pod.Spec.TerminationGracePeriodSeconds
}
switch pod.Status.Phase {
case v1.PodRunning:
if pod.DeletionTimestamp != nil {
if pod.DeletionTimestamp != nil &&
time.Now().Unix()-pod.DeletionTimestamp.Unix() <= gracePeriodSeconds {
return Releasing
}

return Running
case v1.PodPending:
if pod.DeletionTimestamp != nil {
if pod.DeletionTimestamp != nil &&
time.Now().Unix()-pod.DeletionTimestamp.Unix() <= gracePeriodSeconds {
return Releasing
}

Expand Down

0 comments on commit e4cf4c6

Please sign in to comment.