From 01cad5a39646e1e478657e348e9ddb1487394559 Mon Sep 17 00:00:00 2001 From: Michal Pryc Date: Mon, 29 Apr 2024 16:50:10 +0200 Subject: [PATCH] Adjust the reconcile loop to use simpler logic from reconcile batch Change of the main reconcile loop to easy logic of the return from the reconcile batch. We only requeue when there is need, otherwise we do exit the reconcile loop at the same place and individual reconcile functions control if that should happen now or should be requeued. --- internal/controller/nonadminbackup_controller.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/internal/controller/nonadminbackup_controller.go b/internal/controller/nonadminbackup_controller.go index 11239aa..d0466a2 100644 --- a/internal/controller/nonadminbackup_controller.go +++ b/internal/controller/nonadminbackup_controller.go @@ -82,7 +82,7 @@ func (r *NonAdminBackupReconciler) Reconcile(ctx context.Context, req ctrl.Reque } // Run Reconcile Batch as we have the NonAdminBackup object - reconcileExit, reconcileRequeue, reconcileErr := ReconcileBatch( + _, reconcileRequeue, reconcileErr := ReconcileBatch( ReconcileFunc(func(...any) (bool, bool, error) { return r.InitNonAdminBackup(ctx, rLog, &nab) // Phase: New }), @@ -95,17 +95,12 @@ func (r *NonAdminBackupReconciler) Reconcile(ctx context.Context, req ctrl.Reque ) // Return vars from the ReconcileBatch - if reconcileExit { - return ctrl.Result{}, reconcileErr - } else if reconcileRequeue { + if reconcileRequeue { return ctrl.Result{Requeue: true, RequeueAfter: requeueTimeSeconds * time.Second}, reconcileErr - } else if reconcileErr != nil { - return ctrl.Result{}, reconcileErr - } // No error and both reconcileExit and reconcileRequeue false, continue... + } logger.V(1).Info(">>> Reconcile NonAdminBackup - loop end") - - return ctrl.Result{}, nil + return ctrl.Result{}, reconcileErr } // SetupWithManager sets up the controller with the Manager.