Support Reconciler Pattern
IfSentient opened this issue · comments
Austin Pond commented
What
The SDK should support the ReconcilerController
alongside with the InformerController
. The reconciler-based controller should loosely follow the Reconciler interface github.com/kubernetes-sigs/controller-runtime
, i.e. something along the lines of:
// Describes the action that triggered reconciliation.
type ReconcileAction int
const (
ReconcileActionUnknown ReconcileAction = iota
// Object was created
ReconcileActionCreated
// Object was updated
ReconcileActionUpdated
// Object was deleted
ReconcileActionDeleted
// Object was re-synced (i.e. periodic reconciliation)
ReconcileActionResynced
)
// The request encapsulates both the action and the object state at the time of the action.
type ReconcileRequest struct {
Action ReconcileAction
Object resource.Object
}
// The result can be returned by the reconciler
// e.g. when reconciler wants to requeue the reconciliation
// because some remote component is not ready yet.
//
// By default it will be empty.
type ReconcileResult struct {
RequeueAfter time.Duration
}
// If the reconciler returns an error, the request will be requeued.
// If the reconciler returns a non-empty result, the request will be requeued as well (according to RequeueAfter).
type Reconciler interface {
Reconcile(context.Context, ReconcileRequest) (ReconcileResult, error)
}
Why
It is a much simpler pattern, since most of the reconcilers don't care about the actions (and can thus safely ignore the action part of the request) since the logic is the same.
It also requires less boilerplate code, which is good.