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 committed Aug 7, 2024
1 parent 47a11ff commit 23ea27a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions controllers/horizon_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 23ea27a

Please sign in to comment.