Skip to content

Commit 133be67

Browse files
committed
Respect ErrorResults returned from preflight checks
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.
1 parent 83bd9c0 commit 133be67

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/patterns/declarative/reconciler.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ type ErrorResult struct {
9595
}
9696

9797
func (e *ErrorResult) Error() string {
98-
return e.Err.Error()
98+
if e.Err != nil {
99+
return e.Err.Error()
100+
}
101+
102+
return ""
99103
}
100104

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

184188
if r.options.status != nil {
185189
if err := r.options.status.Preflight(ctx, instance); err != nil {
190+
if errorResult, ok := err.(*ErrorResult); ok {
191+
// the user was specific about what they wanted to return; respect that
192+
return errorResult.Result, errorResult.Err
193+
}
194+
186195
log.Error(err, "preflight check failed, not reconciling")
187196
statusInfo.Err = err
188197
return result, statusInfo.Err

0 commit comments

Comments
 (0)