From 71cc3c70b6afe86daf6fb7c18ebd159eefcaa611 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Wed, 7 Aug 2024 08:59:51 +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/designate_controller.go | 9 ++++++--- controllers/designateapi_controller.go | 6 ++++-- controllers/designatebackendbind9_controller.go | 6 ++++-- controllers/designatecentral_controller.go | 6 ++++-- controllers/designatemdns_controller.go | 6 ++++-- controllers/designateproducer_controller.go | 6 ++++-- controllers/designateunbound_controller.go | 3 ++- controllers/designateworker_controller.go | 6 ++++-- 8 files changed, 32 insertions(+), 16 deletions(-) diff --git a/controllers/designate_controller.go b/controllers/designate_controller.go index 0db0278b..26a7910d 100644 --- a/controllers/designate_controller.go +++ b/controllers/designate_controller.go @@ -343,12 +343,13 @@ func (r *DesignateReconciler) reconcileInit( 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, @@ -364,12 +365,13 @@ func (r *DesignateReconciler) reconcileInit( transportURLSecret, hash, err := oko_secret.GetSecret(ctx, helper, instance.Status.TransportURLSecret, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("TransportURL secret %s not found", instance.Status.TransportURLSecret)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("TransportURL secret %s not found", instance.Status.TransportURLSecret) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, @@ -641,13 +643,14 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, diff --git a/controllers/designateapi_controller.go b/controllers/designateapi_controller.go index 301bcacc..18bc39f8 100644 --- a/controllers/designateapi_controller.go +++ b/controllers/designateapi_controller.go @@ -649,13 +649,14 @@ func (r *DesignateAPIReconciler) reconcileNormal(ctx context.Context, instance * _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, @@ -813,12 +814,13 @@ func (r *DesignateAPIReconciler) getSecret( secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + h.GetLogger().Info(fmt.Sprintf("Secret %s not found", secretName)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, diff --git a/controllers/designatebackendbind9_controller.go b/controllers/designatebackendbind9_controller.go index 5f26db27..973a184a 100644 --- a/controllers/designatebackendbind9_controller.go +++ b/controllers/designatebackendbind9_controller.go @@ -453,13 +453,14 @@ func (r *DesignateBackendbind9Reconciler) reconcileNormal(ctx context.Context, i _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + r.Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, @@ -613,12 +614,13 @@ func (r *DesignateBackendbind9Reconciler) getSecret( secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + r.Log.Info(fmt.Sprintf("Secret %s not found", secretName)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, diff --git a/controllers/designatecentral_controller.go b/controllers/designatecentral_controller.go index 2c0dd394..a4558133 100644 --- a/controllers/designatecentral_controller.go +++ b/controllers/designatecentral_controller.go @@ -412,13 +412,14 @@ func (r *DesignateCentralReconciler) reconcileNormal(ctx context.Context, instan _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, @@ -577,12 +578,13 @@ func (r *DesignateCentralReconciler) getSecret( secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + h.GetLogger().Info(fmt.Sprintf("Secret %s not found", secretName)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, diff --git a/controllers/designatemdns_controller.go b/controllers/designatemdns_controller.go index 037b09b4..5367cefa 100644 --- a/controllers/designatemdns_controller.go +++ b/controllers/designatemdns_controller.go @@ -410,13 +410,14 @@ func (r *DesignateMdnsReconciler) reconcileNormal(ctx context.Context, instance _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, @@ -575,12 +576,13 @@ func (r *DesignateMdnsReconciler) getSecret( secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + h.GetLogger().Info(fmt.Sprintf("Secret %s not found", secretName)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, diff --git a/controllers/designateproducer_controller.go b/controllers/designateproducer_controller.go index 924f2325..84d89e60 100644 --- a/controllers/designateproducer_controller.go +++ b/controllers/designateproducer_controller.go @@ -412,13 +412,14 @@ func (r *DesignateProducerReconciler) reconcileNormal(ctx context.Context, insta _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, @@ -577,12 +578,13 @@ func (r *DesignateProducerReconciler) getSecret( secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + h.GetLogger().Info(fmt.Sprintf("Secret %s not found", secretName)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, diff --git a/controllers/designateunbound_controller.go b/controllers/designateunbound_controller.go index aa8862dc..97871866 100644 --- a/controllers/designateunbound_controller.go +++ b/controllers/designateunbound_controller.go @@ -270,13 +270,14 @@ func (r *UnboundReconciler) reconcileNormal(ctx context.Context, instance *desig _, err := nad.GetNADWithName(ctx, helper, networkAttachment, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + r.Log.Info(fmt.Sprintf("network-attachment-definition %s not found", networkAttachment)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, networkAttachment)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", networkAttachment) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, diff --git a/controllers/designateworker_controller.go b/controllers/designateworker_controller.go index fb1a1179..bb813887 100644 --- a/controllers/designateworker_controller.go +++ b/controllers/designateworker_controller.go @@ -407,13 +407,14 @@ func (r *DesignateWorkerReconciler) reconcileNormal(ctx context.Context, instanc _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt)) instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.NetworkAttachmentsReadyWaitingMessage, netAtt)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("network-attachment-definition %s not found", netAtt) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.NetworkAttachmentsReadyCondition, @@ -570,12 +571,13 @@ func (r *DesignateWorkerReconciler) getSecret( secret, hash, err := secret.GetSecret(ctx, h, secretName, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + h.GetLogger().Info(fmt.Sprintf("Secret %s not found", secretName)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("Secret %s not found", secretName) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition,