in pkg/controllers/jobset_controller.go [192:230]
func (r *JobSetReconciler) getChildJobs(ctx context.Context, js *jobset.JobSet) (*childJobs, error) {
log := ctrl.LoggerFrom(ctx)
// Get all active jobs owned by JobSet.
var childJobList batchv1.JobList
if err := r.List(ctx, &childJobList, client.InNamespace(js.Namespace), client.MatchingFields{jobOwnerKey: js.Name}); err != nil {
return nil, err
}
// Categorize each job into a bucket: active, successful, failed, or delete.
ownedJobs := childJobs{}
for i, job := range childJobList.Items {
// Jobs with jobset.sigs.k8s.io/restart-attempt < jobset.status.restarts are marked for
// deletion, as they were part of the previous JobSet run.
jobRestarts, err := strconv.Atoi(job.Labels[RestartsKey])
if err != nil {
log.Error(err, fmt.Sprintf("invalid value for label %s, must be integer", RestartsKey))
ownedJobs.delete = append(ownedJobs.delete, &childJobList.Items[i])
return nil, err
}
if jobRestarts < js.Status.Restarts {
ownedJobs.delete = append(ownedJobs.delete, &childJobList.Items[i])
continue
}
// Jobs with jobset.sigs.k8s.io/restart-attempt == jobset.status.restarts are part of
// the current JobSet run, and marked either active, successful, or failed.
_, finishedType := jobFinished(&job)
switch finishedType {
case "": // active
ownedJobs.active = append(ownedJobs.active, &childJobList.Items[i])
case batchv1.JobFailed:
ownedJobs.failed = append(ownedJobs.failed, &childJobList.Items[i])
case batchv1.JobComplete:
ownedJobs.successful = append(ownedJobs.successful, &childJobList.Items[i])
}
}
return &ownedJobs, nil
}