Skip to content

Commit

Permalink
fix: race condition in job success check
Browse files Browse the repository at this point in the history
With the previous success check IsJobFinished could return true before the success had been registered
  • Loading branch information
msvticket committed Jan 5, 2024
1 parent f9b3334 commit 22a7c9a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/kube/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ package jobs

import (
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
)

// IsJobSucceeded returns true if the job completed and did not fail
func IsJobSucceeded(job *batchv1.Job) bool {
return IsJobFinished(job) && job.Status.Succeeded > 0
return IsJobFinished(job) && job.Status.Conditions[0].Type == batchv1.JobComplete
}

// IsJobFinished returns true if the job has completed
func IsJobFinished(job *batchv1.Job) bool {
BackoffLimit := job.Spec.BackoffLimit
return job.Status.CompletionTime != nil || (job.Status.Active == 0 && BackoffLimit != nil && job.Status.Failed >= *BackoffLimit)
for _, con := range job.Status.Conditions {
if con.Status == corev1.ConditionTrue {
return true
}
}
return false
}

0 comments on commit 22a7c9a

Please sign in to comment.