Documentation ¶
Overview ¶
Package pause implements a controller pattern for temporarily stopping reconciliation of a resource (but not the entire controller).
When a specific label is added to the resource, the controller sees it and adds a `Paused` condition to the Status of the object, and refuses to process it further until it is un-paused (by removal of the label).
There is also a `SelfPause` handler that can be used if the controller detects a state that it can't easily recover without human intervention. For example, when a required Job has failed after all of its retries, or an external resource (like a Database) is in a bad state, and it is unreasonable to continuously poll for changes. SelfPause should be used sparingly, a controller should almost always prefer to backoff/retry.
Index ¶
Examples ¶
Constants ¶
const ConditionTypePaused = "Paused"
Variables ¶
This section is empty.
Functions ¶
func NewPausedCondition ¶
func NewSelfPausedCondition ¶
Types ¶
type Handler ¶
type Handler[K HasStatusConditions] struct { PausedLabelKey string Object *typedctx.DefaultingKey[K] PatchStatus func(ctx context.Context, patch K) error Next handler.ContextHandler // contains filtered or unexported fields }
func NewPauseContextHandler ¶
func NewPauseContextHandler[K HasStatusConditions](ctrls *typedctx.Key[queue.Interface], pausedLabelKey string, object *typedctx.DefaultingKey[K], patchStatus func(ctx context.Context, patch K) error, next handler.ContextHandler, ) *Handler[K]
Example ¶
queueOperations := queue.NewQueueOperationsCtx() ctxObject := typedctx.WithDefault[*MyObject](&MyObject{ TypeMeta: metav1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "test"}, }) ctx, cancel := context.WithCancel(context.Background()) defer cancel() pauseHandler := handler.NewHandler(NewPauseContextHandler( queueOperations.Key, "example.com/paused", ctxObject, func(ctx context.Context, patch *MyObject) error { // update status return nil }, handler.NoopHandler, ), "checkPause") pauseHandler.Handle(ctx)
Output:
type HasStatusConditions ¶
type HasStatusConditions interface { comparable metav1.Object FindStatusCondition(conditionType string) *metav1.Condition SetStatusCondition(metav1.Condition) RemoveStatusCondition(conditionType string) GetStatusConditions() *[]metav1.Condition }
HasStatusConditions is an interface that any object implementing standard condition accessors will satisfy.
type SelfPauseHandler ¶
type SelfPauseHandler[K HasStatusConditions] struct { CtxKey *typedctx.DefaultingKey[K] PausedLabelKey string OwnerUID types.UID Patch func(ctx context.Context, patch K) error PatchStatus func(ctx context.Context, patch K) error // contains filtered or unexported fields }
SelfPauseHandler is used when the controller pauses itself. This is only used when the controller has no good way to tell when the bad state has been resolved (i.e. an external resource is behaving poorly).
func NewSelfPauseHandler ¶
func NewSelfPauseHandler[K HasStatusConditions](ctrls *typedctx.Key[queue.Interface], pausedLabelKey string, contextKey *typedctx.DefaultingKey[K], patch, patchStatus func(ctx context.Context, patch K) error, ) *SelfPauseHandler[K]
func (*SelfPauseHandler[K]) Handle ¶
func (p *SelfPauseHandler[K]) Handle(ctx context.Context)