From 24f751fd4f3b6a3648a11c4feae0a94c8159f0ff Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Sun, 17 Oct 2021 19:03:55 -0700 Subject: [PATCH] Enforce backOffLimit in ExitCode restartPolicy (#168) --- pkg/controller.v1/common/job.go | 2 +- pkg/core/job.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controller.v1/common/job.go b/pkg/controller.v1/common/job.go index 9f6cf428..083f6eea 100644 --- a/pkg/controller.v1/common/job.go +++ b/pkg/controller.v1/common/job.go @@ -313,7 +313,7 @@ func (jc *JobController) PastActiveDeadline(runPolicy *apiv1.RunPolicy, jobStatu } // PastBackoffLimit checks if container restartCounts sum exceeds BackoffLimit -// this method applies only to pods with restartPolicy == OnFailure or Always +// this method applies only to pods when restartPolicy is one of OnFailure, Always or ExitCode func (jc *JobController) PastBackoffLimit(jobName string, runPolicy *apiv1.RunPolicy, replicas map[apiv1.ReplicaType]*apiv1.ReplicaSpec, pods []*v1.Pod) (bool, error) { return core.PastBackoffLimit(jobName, runPolicy, replicas, pods, jc.FilterPodsForReplicaType) diff --git a/pkg/core/job.go b/pkg/core/job.go index f0b67cb4..577c9b18 100644 --- a/pkg/core/job.go +++ b/pkg/core/job.go @@ -74,7 +74,7 @@ func PastActiveDeadline(runPolicy *apiv1.RunPolicy, jobStatus apiv1.JobStatus) b } // PastBackoffLimit checks if container restartCounts sum exceeds BackoffLimit -// this method applies only to pods with restartPolicy == OnFailure or Always +// this method applies only to pods when restartPolicy is one of OnFailure, Always or ExitCode func PastBackoffLimit(jobName string, runPolicy *apiv1.RunPolicy, replicas map[apiv1.ReplicaType]*apiv1.ReplicaSpec, pods []*v1.Pod, podFilterFunc func(pods []*v1.Pod, replicaType apiv1.ReplicaType) ([]*v1.Pod, error)) (bool, error) { @@ -83,8 +83,8 @@ func PastBackoffLimit(jobName string, runPolicy *apiv1.RunPolicy, } result := int32(0) for rtype, spec := range replicas { - if spec.RestartPolicy != apiv1.RestartPolicyOnFailure && spec.RestartPolicy != apiv1.RestartPolicyAlways { - log.Warnf("The restart policy of replica %v of the job %v is not OnFailure or Always. Not counted in backoff limit.", rtype, jobName) + if spec.RestartPolicy != apiv1.RestartPolicyOnFailure && spec.RestartPolicy != apiv1.RestartPolicyAlways && spec.RestartPolicy != apiv1.RestartPolicyExitCode { + log.Warnf("The restart policy of replica %v of the job %v is not OnFailure, Always or ExitCode. Not counted in backoff limit.", rtype, jobName) continue } // Convert ReplicaType to lower string.