From 7f66d3983b80749f9947f4a38f1adc229abb2b94 Mon Sep 17 00:00:00 2001 From: Somtochi Onyekwere Date: Mon, 8 Nov 2021 23:23:07 +0100 Subject: [PATCH] Bump observed generation only once Signed-off-by: Somtochi Onyekwere --- api/v1beta1/condition_types.go | 4 ++++ controllers/alert_controller.go | 7 +++---- controllers/provider_controller.go | 3 +-- controllers/receiver_controller.go | 6 ------ 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/api/v1beta1/condition_types.go b/api/v1beta1/condition_types.go index a9162b76c..2e7996c2f 100644 --- a/api/v1beta1/condition_types.go +++ b/api/v1beta1/condition_types.go @@ -20,6 +20,10 @@ const ( // InitializedReason represents the fact that a given resource has been initialized. InitializedReason string = "Initialized" + // ValidationFailedReason represents the fact that some part of the spec of a given resource + // couldn't be validated. + ValidationFailedReason string = "ValidationFailed" + // TokenNotFound represents the fact that receiver token can't be found. TokenNotFoundReason string = "TokenNotFound" ) diff --git a/controllers/alert_controller.go b/controllers/alert_controller.go index 8867e5295..0310c2324 100644 --- a/controllers/alert_controller.go +++ b/controllers/alert_controller.go @@ -120,7 +120,6 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu meta.StalledCondition, }, }, - patch.WithStatusObservedGeneration{}, } if retErr == nil && (result.IsZero() || !result.Requeue) { @@ -156,7 +155,7 @@ func (r *AlertReconciler) reconcile(ctx context.Context, alert *v1beta1.Alert) ( // validate alert spec and provider if err := r.validate(ctx, alert); err != nil { - conditions.MarkFalse(alert, meta.ReadyCondition, meta.FailedReason, err.Error()) + conditions.MarkFalse(alert, meta.ReadyCondition, v1beta1.ValidationFailedReason, err.Error()) return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -171,8 +170,8 @@ func (r *AlertReconciler) validate(ctx context.Context, alert *v1beta1.Alert) er providerName := types.NamespacedName{Namespace: alert.Namespace, Name: alert.Spec.ProviderRef.Name} if err := r.Get(ctx, providerName, provider); err != nil { // log not found errors since they get filtered out - ctrl.LoggerFrom(ctx).Error(err, "failed to get provider %s, error: %w", providerName.String()) - return fmt.Errorf("failed to get provider '%s', error: %w", providerName.String(), err) + ctrl.LoggerFrom(ctx).Error(err, "failed to get provider %s", providerName.String()) + return fmt.Errorf("failed to get provider '%s': %w", providerName.String(), err) } if !conditions.IsReady(provider) { diff --git a/controllers/provider_controller.go b/controllers/provider_controller.go index 59de9c052..df980270d 100644 --- a/controllers/provider_controller.go +++ b/controllers/provider_controller.go @@ -99,7 +99,6 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r meta.StalledCondition, }, }, - patch.WithStatusObservedGeneration{}, } if retErr == nil && (result.IsZero() || !result.Requeue) { @@ -136,7 +135,7 @@ func (r *ProviderReconciler) reconcile(ctx context.Context, obj *v1beta1.Provide // validate provider spec and credentials if err := r.validate(ctx, obj); err != nil { - conditions.MarkFalse(obj, meta.ReadyCondition, meta.FailedReason, err.Error()) + conditions.MarkFalse(obj, meta.ReadyCondition, v1beta1.ValidationFailedReason, err.Error()) return ctrl.Result{}, err } diff --git a/controllers/receiver_controller.go b/controllers/receiver_controller.go index 2116df5b2..9b1b3b4db 100644 --- a/controllers/receiver_controller.go +++ b/controllers/receiver_controller.go @@ -94,7 +94,6 @@ func (r *ReceiverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r meta.StalledCondition, }, }, - patch.WithStatusObservedGeneration{}, } // Determine if the resource is still being reconciled, or if it has stalled, and record this observation @@ -155,11 +154,6 @@ func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *v1beta1.Receive receiverURL := fmt.Sprintf("/hook/%s", sha256sum(token+obj.Name+obj.Namespace)) - // Nothing has changed so return early - if obj.Status.URL == receiverURL && obj.Status.ObservedGeneration == obj.Generation { - return ctrl.Result{}, nil - } - // Mark the resource as ready and set the URL conditions.MarkTrue(obj, meta.ReadyCondition, v1beta1.InitializedReason, "Receiver initialised with URL: "+receiverURL, receiverURL)