in kubernetes/controllers/elasticjob_controller.go [61:103]
func (r *ElasticJobReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
// Fetch the ElasticJob instance
elasticJob := &v1alpha1.ElasticJob{}
err := r.Get(context.TODO(), req.NamespacedName, elasticJob)
if err != nil {
if errors.IsNotFound(err) {
// Object not found, return. Created objects are automatically garbage collected.
// For additional cleanup logic use finalizers.
return reconcile.Result{}, nil
}
// Error reading the object - requeue the request.
return reconcile.Result{}, err
}
log := logger.LoggerForJob(elasticJob)
needSync := r.satisfiedExpections(elasticJob)
if !needSync {
log.Info("reconcile skipped, job does not need to sync")
return ctrl.Result{}, nil
}
if elasticJob.DeletionTimestamp != nil {
log.Info("reconcile skipped, job has been deleted.")
return ctrl.Result{}, nil
}
// Set default priorities for elastic job
scheme.Scheme.Default(elasticJob)
// Set default cleanPodPolicy for job
if elasticJob.Spec.RunPolicy.CleanPodPolicy == nil {
elasticJob.Spec.RunPolicy.CleanPodPolicy = &defaultCleanPodPolicy
}
// Use common to reconcile the job related pod and service
err = r.jobController.ReconcileJobs(elasticJob, elasticJob.Spec.ReplicaSpecs, elasticJob.Status.JobStatus, &elasticJob.Spec.RunPolicy)
if err != nil {
log.Infof("Reconcile ElasticJob error %v", err)
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}