Skip to content

Commit

Permalink
Improve CEL expresion validation error handling
Browse files Browse the repository at this point in the history
In the event of a CEL expresion error, this doesn't return the error to
the controller-runtime reconciler mechanism.

This means that the reconciliation will not be retried until there's a
change to the resource.
  • Loading branch information
bigkevmcd committed Nov 1, 2024
1 parent 57c36b0 commit 3f15050
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/controller/receiver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
helper "github.com/fluxcd/pkg/runtime/controller"
"github.com/fluxcd/pkg/runtime/patch"
"github.com/fluxcd/pkg/runtime/predicates"
"github.com/go-logr/logr"

apiv1 "github.com/fluxcd/notification-controller/api/v1"
"github.com/fluxcd/notification-controller/internal/server"
Expand Down Expand Up @@ -152,12 +153,12 @@ func (r *ReceiverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
return ctrl.Result{}, nil
}

return r.reconcile(ctx, obj)
return r.reconcile(ctx, obj, log)
}

// reconcile steps through the actual reconciliation tasks for the object, it returns early on the first step that
// produces an error.
func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *apiv1.Receiver) (ctrl.Result, error) {
func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *apiv1.Receiver, logger logr.Logger) (ctrl.Result, error) {
// Mark the resource as under reconciliation.
conditions.MarkReconciling(obj, meta.ProgressingReason, "Reconciliation in progress")

Expand All @@ -173,7 +174,8 @@ func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *apiv1.Receiver)
if err != nil {
conditions.MarkFalse(obj, meta.ReadyCondition, apiv1.InvalidCELExpressionReason, "%s", err)
obj.Status.WebhookPath = ""
return ctrl.Result{}, err
logger.Error(err, "parsing CEL resource filter expression")
return ctrl.Result{}, nil
}
}

Expand Down

0 comments on commit 3f15050

Please sign in to comment.