From 8fc5c3fbac891f0e77547e723f2aed639d0c84fc Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Wed, 7 Aug 2024 08:17:46 +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/ironic_controller.go | 3 ++- controllers/ironicapi_controller.go | 9 ++++++--- controllers/ironicconductor_controller.go | 9 ++++++--- controllers/ironicinspector_controller.go | 8 ++++---- controllers/ironicneutronagent_controller.go | 3 ++- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/controllers/ironic_controller.go b/controllers/ironic_controller.go index 2f9db3cd..c81609fe 100644 --- a/controllers/ironic_controller.go +++ b/controllers/ironic_controller.go @@ -320,12 +320,13 @@ func (r *IronicReconciler) reconcileNormal(ctx context.Context, instance *ironic 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, diff --git a/controllers/ironicapi_controller.go b/controllers/ironicapi_controller.go index 6a440111..03fbafab 100644 --- a/controllers/ironicapi_controller.go +++ b/controllers/ironicapi_controller.go @@ -627,12 +627,13 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro ospSecret, hash, err := 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, @@ -652,12 +653,13 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro transportURLSecret, hash, err := secret.GetSecret(ctx, helper, instance.Spec.TransportURLSecret, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("TransportURL secret %s not found", instance.Spec.TransportURLSecret)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("TransportURL secret %s not found", instance.Spec.TransportURLSecret) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, @@ -775,13 +777,14 @@ func (r *IronicAPIReconciler) reconcileNormal(ctx context.Context, instance *iro _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info("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/ironicconductor_controller.go b/controllers/ironicconductor_controller.go index 129c54a8..0f74bb74 100644 --- a/controllers/ironicconductor_controller.go +++ b/controllers/ironicconductor_controller.go @@ -464,12 +464,13 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc ospSecret, hash, err := 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, @@ -489,12 +490,13 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc transportURLSecret, hash, err := secret.GetSecret(ctx, helper, instance.Spec.TransportURLSecret, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info(fmt.Sprintf("TransportURL secret %s not found", instance.Spec.TransportURLSecret)) instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, condition.RequestedReason, condition.SeverityInfo, condition.InputReadyWaitingMessage)) - return ctrl.Result{RequeueAfter: time.Second * 10}, fmt.Errorf("TransportURL secret %s not found", instance.Spec.TransportURLSecret) + return ctrl.Result{RequeueAfter: time.Second * 10}, nil } instance.Status.Conditions.Set(condition.FalseCondition( condition.InputReadyCondition, @@ -620,13 +622,14 @@ func (r *IronicConductorReconciler) reconcileNormal(ctx context.Context, instanc _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info("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/ironicinspector_controller.go b/controllers/ironicinspector_controller.go index 53130d30..13139819 100644 --- a/controllers/ironicinspector_controller.go +++ b/controllers/ironicinspector_controller.go @@ -474,15 +474,14 @@ func (r *IronicInspectorReconciler) reconcileConfigMapsAndSecrets( instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + log.FromContext(ctx).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( @@ -754,13 +753,14 @@ func (r *IronicInspectorReconciler) reconcileNormal( _, err := nad.GetNADWithName(ctx, helper, netAtt, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + Log.Info("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/ironicneutronagent_controller.go b/controllers/ironicneutronagent_controller.go index e4540cb6..4707f9db 100644 --- a/controllers/ironicneutronagent_controller.go +++ b/controllers/ironicneutronagent_controller.go @@ -351,12 +351,13 @@ func (r *IronicNeutronAgentReconciler) reconcileConfigMapsAndSecrets( ospSecret, hash, err := secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace) if err != nil { if k8s_errors.IsNotFound(err) { + log.FromContext(ctx).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,