Skip to content

Commit

Permalink
Merge pull request #2011 from Garrybest/automated-cherry-pick-of-#198…
Browse files Browse the repository at this point in the history
…7-upstream-release-1.0

Automated cherry pick of #1987: fix bugs of aggregating job status
  • Loading branch information
karmada-bot committed Jun 16, 2022
2 parents 292f521 + cb04e8a commit b26dae6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions pkg/detector/aggregate_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/util/helper/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b26dae6

Please sign in to comment.