in controllers/qualityprofile/sonarqualityprofile_controller.go [51:124]
func (r *SonarQualityProfileReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)
log.Info("Reconciling SonarQualityProfile")
profile := &sonarApi.SonarQualityProfile{}
err := r.client.Get(ctx, req.NamespacedName, profile)
if err != nil {
if k8sErrors.IsNotFound(err) {
return ctrl.Result{}, nil
}
return ctrl.Result{}, err
}
sonarApiClient, err := r.apiClientProvider.GetSonarApiClientFromSonarRef(ctx, req.Namespace, profile)
if err != nil {
log.Error(err, "An error has occurred while getting sonar api client")
return ctrl.Result{
RequeueAfter: errorRequeueTime,
}, nil
}
if profile.GetDeletionTimestamp() != nil {
if controllerutil.ContainsFinalizer(profile, sonarOperatorFinalizer) {
if err = chain.NewRemoveQualityProfile(sonarApiClient).ServeRequest(ctx, profile); err != nil {
log.Error(err, "An error has occurred while deleting QualityProfile")
return ctrl.Result{
RequeueAfter: errorRequeueTime,
}, nil
}
controllerutil.RemoveFinalizer(profile, sonarOperatorFinalizer)
if err = r.client.Update(ctx, profile); err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
}
if controllerutil.AddFinalizer(profile, sonarOperatorFinalizer) {
err = r.client.Update(ctx, profile)
if err != nil {
return ctrl.Result{}, err
}
}
oldStatus := profile.Status
if err = chain.MakeChain(sonarApiClient).ServeRequest(ctx, profile); err != nil {
log.Error(err, "An error has occurred while handling SonarQualityProfile")
profile.Status.Value = "error"
profile.Status.Error = err.Error()
if err = r.updateSonarQualityProfileStatus(ctx, profile, oldStatus); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{
RequeueAfter: errorRequeueTime,
}, nil
}
profile.Status.Value = common.StatusCreated
profile.Status.Error = ""
if err = r.updateSonarQualityProfileStatus(ctx, profile, oldStatus); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{}, nil
}