Skip to content

Commit fac0ca8

Browse files
committed
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 <[email protected]>
1 parent f663445 commit fac0ca8

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

controllers/aodh_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ func (r *AutoscalingReconciler) reconcileInitAodh(
112112
_, _, err := secret.GetSecret(ctx, helper, instance.Spec.Aodh.Secret, instance.Namespace)
113113
if err != nil {
114114
if k8s_errors.IsNotFound(err) {
115-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Aodh.Secret)
115+
Log.Info(fmt.Sprintf("OpenStack secret %s not found", instance.Spec.Aodh.Secret))
116+
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
116117
}
117118
return ctrl.Result{}, err
118119
}

controllers/autoscaling_controller.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,13 @@ func (r *AutoscalingReconciler) reconcileNormal(
344344
memcached, err := memcachedv1.GetMemcachedByName(ctx, helper, instance.Spec.Aodh.MemcachedInstance, instance.Namespace)
345345
if err != nil {
346346
if k8s_errors.IsNotFound(err) {
347+
Log.Info(fmt.Sprintf("memcached %s not found", instance.Spec.Aodh.MemcachedInstance))
347348
instance.Status.Conditions.Set(condition.FalseCondition(
348349
condition.MemcachedReadyCondition,
349350
condition.RequestedReason,
350351
condition.SeverityInfo,
351352
condition.MemcachedReadyWaitingMessage))
352-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("memcached %s not found", instance.Spec.Aodh.MemcachedInstance)
353+
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
353354
}
354355
instance.Status.Conditions.Set(condition.FalseCondition(
355356
condition.MemcachedReadyCondition,
@@ -361,12 +362,13 @@ func (r *AutoscalingReconciler) reconcileNormal(
361362
}
362363

363364
if !memcached.IsReady() {
365+
Log.Info(fmt.Sprintf("memcached %s is not ready", memcached.Name))
364366
instance.Status.Conditions.Set(condition.FalseCondition(
365367
condition.MemcachedReadyCondition,
366368
condition.RequestedReason,
367369
condition.SeverityInfo,
368370
condition.MemcachedReadyWaitingMessage))
369-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("memcached %s is not ready", memcached.Name)
371+
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
370372
}
371373
// Mark the Memcached Service as Ready if we get to this point with no errors
372374
instance.Status.Conditions.MarkTrue(
@@ -379,12 +381,13 @@ func (r *AutoscalingReconciler) reconcileNormal(
379381
heat, err := r.getAutoscalingHeat(ctx, helper, instance)
380382
if err != nil {
381383
if k8s_errors.IsNotFound(err) {
384+
Log.Info(fmt.Sprintf("heat %s not found", instance.Spec.HeatInstance))
382385
instance.Status.Conditions.Set(condition.FalseCondition(
383386
telemetryv1.HeatReadyCondition,
384387
condition.RequestedReason,
385388
condition.SeverityInfo,
386389
telemetryv1.HeatReadyNotFoundMessage))
387-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("heat %s not found", instance.Spec.HeatInstance)
390+
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
388391
}
389392
instance.Status.Conditions.Set(condition.FalseCondition(
390393
telemetryv1.HeatReadyCondition,
@@ -396,12 +399,13 @@ func (r *AutoscalingReconciler) reconcileNormal(
396399
}
397400

398401
if !heat.IsReady() {
402+
Log.Info(fmt.Sprintf("heat %s is not ready", heat.Name))
399403
instance.Status.Conditions.Set(condition.FalseCondition(
400404
telemetryv1.HeatReadyCondition,
401405
condition.RequestedReason,
402406
condition.SeverityInfo,
403407
telemetryv1.HeatReadyUnreadyMessage))
404-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("heat %s is not ready", heat.Name)
408+
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
405409
}
406410
// Mark the Heat Service as Ready if we get to this point with no errors
407411
instance.Status.Conditions.MarkTrue(

controllers/ceilometer_controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ func (r *CeilometerReconciler) reconcileInit(
237237
_, _, err := secret.GetSecret(ctx, helper, instance.Spec.Secret, instance.Namespace)
238238
if err != nil {
239239
if k8s_errors.IsNotFound(err) {
240-
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", instance.Spec.Secret)
240+
Log.Info(fmt.Sprintf("OpenStack secret %s not found", instance.Spec.Secret))
241+
return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
241242
}
242243
return ctrl.Result{}, err
243244
}

controllers/telemetry_common.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"k8s.io/apimachinery/pkg/types"
2828
ctrl "sigs.k8s.io/controller-runtime"
2929
"sigs.k8s.io/controller-runtime/pkg/client"
30+
"sigs.k8s.io/controller-runtime/pkg/log"
3031
)
3132

3233
type conditionUpdater interface {
@@ -49,12 +50,13 @@ func ensureSecret(
4950
hash, res, err := secret.VerifySecret(ctx, secretName, expectedFields, reader, requeueTimeout)
5051
if err != nil {
5152
if k8s_errors.IsNotFound(err) {
53+
log.FromContext(ctx).Info(fmt.Sprintf("OpenStack secret %s not found", secretName))
5254
conditionUpdater.Set(condition.FalseCondition(
5355
condition.InputReadyCondition,
5456
condition.RequestedReason,
5557
condition.SeverityInfo,
5658
condition.InputReadyWaitingMessage))
57-
return "", ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, fmt.Errorf("OpenStack secret %s not found", secretName)
59+
return "", ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil
5860
}
5961
conditionUpdater.Set(condition.FalseCondition(
6062
condition.InputReadyCondition,

0 commit comments

Comments
 (0)