Skip to content

Commit

Permalink
Return nil error in case NotFound and to use RequeueAfter
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
stuggi authored and openshift-merge-bot[bot] committed Aug 7, 2024
1 parent 4550d67 commit a7c13fa
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func ensureSecret(
err := reader.Get(ctx, secretName, secret)
if err != nil {
if k8s_errors.IsNotFound(err) {
log.FromContext(ctx).Info(fmt.Sprintf("secret %s not found", secretName))
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
condition.RequestedReason,
Expand All @@ -207,7 +208,7 @@ func ensureSecret(
return "",
ctrl.Result{RequeueAfter: requeueTimeout},
*secret,
fmt.Errorf("secret %s not found", secretName)
nil
}
conditionUpdater.Set(condition.FalseCondition(
condition.InputReadyCondition,
Expand Down Expand Up @@ -268,13 +269,14 @@ func ensureNetworkAttachments(
_, err := nad.GetNADWithName(ctx, h, netAtt, h.GetBeforeObject().GetNamespace())
if err != nil {
if k8s_errors.IsNotFound(err) {
log.FromContext(ctx).Info(fmt.Sprintf("network-attachment-definition %s not found", netAtt))
conditionUpdater.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.NetworkAttachmentsReadyWaitingMessage,
netAtt))
return nadAnnotations, ctrl.Result{RequeueAfter: requeueTimeout}, fmt.Errorf("network-attachment-definition %s not found", netAtt)
return nadAnnotations, ctrl.Result{RequeueAfter: requeueTimeout}, nil
}
conditionUpdater.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
Expand Down
2 changes: 1 addition & 1 deletion controllers/novaapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (r *NovaAPIReconciler) Reconcile(ctx context.Context, req ctrl.Request) (re
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/novacell_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (r *NovaCellReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/novacompute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (r *NovaComputeReconciler) Reconcile(ctx context.Context, req ctrl.Request)
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/novaconductor_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (r *NovaConductorReconciler) Reconcile(ctx context.Context, req ctrl.Reques
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/novametadata_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (r *NovaMetadataReconciler) Reconcile(ctx context.Context, req ctrl.Request
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/novanovncproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *NovaNoVNCProxyReconciler) Reconcile(ctx context.Context, req ctrl.Reque
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down
2 changes: 1 addition & 1 deletion controllers/novascheduler_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (r *NovaSchedulerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
&instance.Status.Conditions,
r.RequeueTimeout,
)
if err != nil {
if (err != nil || result != ctrl.Result{}) {
return result, err
}

Expand Down

0 comments on commit a7c13fa

Please sign in to comment.