func()

in pkg/controllers/jobset_controller.go [351:382]


func (r *JobSetReconciler) createJobs(ctx context.Context, js *jobset.JobSet, ownedJobs *childJobs) error {
	log := ctrl.LoggerFrom(ctx)

	for _, rjob := range js.Spec.ReplicatedJobs {
		jobs, err := constructJobsFromTemplate(js, &rjob, ownedJobs)
		if err != nil {
			return err
		}

		// If pod DNS hostnames are enabled, create a headless service per replicatedjob.
		if dnsHostnamesEnabled(&rjob) {
			if err := r.createHeadlessSvcIfNotExist(ctx, js, &rjob); err != nil {
				return err
			}
		}

		for _, job := range jobs {
			// Set jobset controller as owner of the job for garbage collection and reconcilation.
			if err := ctrl.SetControllerReference(js, job, r.Scheme); err != nil {
				return err
			}

			// Create the job.
			// TODO(#18): Deal with the case where the job exists but is not owned by the jobset.
			if err := r.Create(ctx, job); err != nil {
				return err
			}
			log.V(2).Info("successfully created job", "job", klog.KObj(job))
		}
	}
	return nil
}