Bump observed generation only once

Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
This commit is contained in:
Somtochi Onyekwere 2021-11-08 23:23:07 +01:00
parent 19a0daa906
commit 7f66d3983b
4 changed files with 8 additions and 12 deletions

View File

@ -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"
)

View File

@ -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) {

View File

@ -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
}

View File

@ -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)