Skip to content

Commit

Permalink
Bump observed generation only once
Browse files Browse the repository at this point in the history
Signed-off-by: Somtochi Onyekwere <somtochionyekwere@gmail.com>
  • Loading branch information
somtochiama committed Nov 8, 2021
1 parent 19a0daa commit 7f66d39
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
7 changes: 3 additions & 4 deletions controllers/alert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

Expand All @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions controllers/provider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 0 additions & 6 deletions controllers/receiver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7f66d39

Please sign in to comment.