From 23ea27aa3565a37ec4963f530036fe0d64c26329 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Wed, 7 Aug 2024 08:43:55 +0200 Subject: [PATCH] Return nil error in case NotFound and to use RequeueAfter Currently the reconciler returned both a non-zero result and a non-nil error. The result will always be ignored if the error is non-nil and the non-nil error causes reqeueuing with exponential backoff. In case of NotFound return nil that the ReqeueAfter is used. For more details, see: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Reconciler Signed-off-by: Martin Schuppert --- controllers/horizon_controller.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/controllers/horizon_controller.go b/controllers/horizon_controller.go index 1d8bbf6e..0e51f089 100644 --- a/controllers/horizon_controller.go +++ b/controllers/horizon_controller.go @@ -501,12 +501,13 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz ospSecret, hash, err := oko_secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("openstack secret %s not found", instance.Spec.Secret)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("openstack secret %s not found", instance.Spec.Secret) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, @@ -527,12 +528,13 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz memcached, err := memcachedv1.GetMemcachedByName(ctx, helper, instance.Spec.MemcachedInstance, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("memcached %s not found", instance.Spec.MemcachedInstance)) instance.Status.Conditions.Set(condition.FalseCondition( condition.MemcachedReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.MemcachedReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("memcached %s not found", instance.Spec.MemcachedInstance) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.MemcachedReadyCondition, @@ -544,12 +546,13 @@ func (r *HorizonReconciler) reconcileNormal(ctx context.Context, instance *horiz } if !memcached.IsReady() { + Log.Info(fmt.Sprintf("memcached %s is not ready", memcached.Name)) instance.Status.Conditions.Set(condition.FalseCondition( condition.MemcachedReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.MemcachedReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("memcached %s is not ready", memcached.Name) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } // Mark the Memcached Service as Ready if we get to this point with no errors instance.Status.Conditions.MarkTrue(