Skip to content

Commit

Permalink
Respect ErrorResults returned from preflight checks
Browse files Browse the repository at this point in the history
A common pattern in our operators is to use preflight checks to call out to some external system
for more information (that can be written e.g. to the status of the `DeclarativeObject`) or to
validate that some property of the `spec` meets requirements to be able to expand the channel
manifests. If the check fails, sometimes the right behavior is to requeue with backoff - but
often it's not: e.g., if the spec is deemed invalid, there's no reason to requeue the resource.
If spec changes we'll get a new event anyway, and until spec changes we won't be able to reconcile.

There is already a `ErrorResult` type that can be used in a Preflight implementation to signal
what we want the reconciliation function to return, but it's currently not being respected. This
change addresses that.
  • Loading branch information
tomasaschan committed Apr 29, 2024
1 parent 83bd9c0 commit 133be67
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkg/patterns/declarative/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ type ErrorResult struct {
}

func (e *ErrorResult) Error() string {
return e.Err.Error()
if e.Err != nil {
return e.Err.Error()
}

return ""
}

// For mocking
Expand Down Expand Up @@ -183,6 +187,11 @@ func (r *Reconciler) Reconcile(ctx context.Context, request reconcile.Request) (

if r.options.status != nil {
if err := r.options.status.Preflight(ctx, instance); err != nil {
if errorResult, ok := err.(*ErrorResult); ok {
// the user was specific about what they wanted to return; respect that
return errorResult.Result, errorResult.Err
}

log.Error(err, "preflight check failed, not reconciling")
statusInfo.Err = err
return result, statusInfo.Err
Expand Down

0 comments on commit 133be67

Please sign in to comment.