diff --git a/pkg/detector/aggregate_status.go b/pkg/detector/aggregate_status.go index 7b76c85ee1f0..9f5c6bdd94b4 100644 --- a/pkg/detector/aggregate_status.go +++ b/pkg/detector/aggregate_status.go @@ -202,6 +202,11 @@ func (d *ResourceDetector) AggregateJobStatus(objRef workv1alpha2.ObjectReferenc return err } + // If a job is finished, we should never update status again. + if finished, _ := helper.GetJobFinishedStatus(&obj.Status); finished { + return nil + } + newStatus, err := helper.ParsingJobStatus(obj, status, clusters) if err != nil { return err diff --git a/pkg/util/helper/job.go b/pkg/util/helper/job.go index 7896d1332a42..02420a91c9fb 100644 --- a/pkg/util/helper/job.go +++ b/pkg/util/helper/job.go @@ -36,7 +36,7 @@ func ParsingJobStatus(obj *batchv1.Job, status []workv1alpha2.AggregatedStatusIt newStatus.Succeeded += temp.Succeeded newStatus.Failed += temp.Failed - isFinished, finishedStatus := getJobFinishedStatus(temp) + isFinished, finishedStatus := GetJobFinishedStatus(temp) if isFinished && finishedStatus == batchv1.JobComplete { successfulJobs++ } else if isFinished && finishedStatus == batchv1.JobFailed { @@ -88,9 +88,9 @@ func ParsingJobStatus(obj *batchv1.Job, status []workv1alpha2.AggregatedStatusIt return newStatus, nil } -// getJobFinishedStatus checks whether the given Job has finished execution. +// GetJobFinishedStatus checks whether the given Job has finished execution. // It does not discriminate between successful and failed terminations. -func getJobFinishedStatus(jobStatus *batchv1.JobStatus) (bool, batchv1.JobConditionType) { +func GetJobFinishedStatus(jobStatus *batchv1.JobStatus) (bool, batchv1.JobConditionType) { for _, c := range jobStatus.Conditions { if (c.Type == batchv1.JobComplete || c.Type == batchv1.JobFailed) && c.Status == corev1.ConditionTrue { return true, c.Type