kubernetes-sigs / kubebuilder-declarative-pattern

A toolkit for building declarative operators with kubebuilder
Apache License 2.0
256 stars 85 forks source link

Error is logged even if result of `status.Preflight` doesn't have one #374

Closed tomasaschan closed 3 months ago

tomasaschan commented 8 months ago

What happened:

I implemented a custom declarative.Status like this:

type myStatus {}

func (myStatus) Preflight(ctx context.Context, o declarative.DeclarativeObject) error {
    // omitted: some precondition is not fulfilled
    // want to requeue with backoff and try again after some other controller has had a chance to make the precondition true
    return declarative.ErrorResult{
        Result: result.Result{Requeue: true},
        // note: Err: nil implied here
    }
}

func NewMyStatus() declarative.Status {
    return declarative.StatusBuilder{
        Preflight: myStatus{},
    }
}

When my controller reconciles with this, it logs "preflight check failed, not reconciling" with a stack trace that doesn't point to anywhere in my own code. That's annoying and a little confusing.

What you expected to happen: reconciliation is requeued without any errors logged.

How to reproduce it (as minimally and precisely as possible):

Create a declarative controller with a status implementation like the above, reconcile an instance and observe logs.

Anything else we need to know?:

This seems related to, but is different from #232. I imagine if my status also had a Reconcile function, it would be confusing that it gets called even though the preflight check failed (signalled by returning a non-nil result, even if that result has a nil Err). That, in turn, happens because this deferred function doesn't check for the preflight result. (It seems it once did check, but it's unclear to me why that was removed...)

k8s-triage-robot commented 5 months ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

tomasaschan commented 5 months ago

/remove-lifecycle stale

I've encountered this again recently, and have a mind on hacking on a better implementation here.