Documentation
¶
Overview ¶
Package poller provides a reusable controller-runtime sigs.k8s.io/controller-runtime/pkg/manager.Runnable that periodically invokes an enqueue function and emits the returned objects as sigs.k8s.io/controller-runtime/pkg/event.TypedGenericEvent on a typed channel.
Index ¶
Constants ¶
const ( // DefaultInterval is the polling interval used when no [WithInterval] // option is provided. DefaultInterval = 1 * time.Minute // DefaultBufferSize is the capacity of the emitted event channel used // when no [WithBufferSize] option is provided. DefaultBufferSize = 64 // DefaultName is the logger name used when no [WithName] option is // provided. DefaultName = "poller" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EnqueueFunc ¶
EnqueueFunc returns the objects that should be emitted as sigs.k8s.io/controller-runtime/pkg/event.TypedGenericEvent on the Runner's channel for a single tick.
Returning (nil, nil) is the canonical way to express "nothing to enqueue, not an error". Returning a non-nil error logs it at the runner's logger and drops the tick; the next tick will retry.
The returned slice must not contain nil entries: the runner forwards each element verbatim and controller-runtime panics on a nil event.Object.
type Option ¶
type Option func(*config)
Option configures a Runner at construction time.
func WithBufferSize ¶
WithBufferSize sets the capacity of the emitted event channel. The option is a no-op when n is non-positive, leaving DefaultBufferSize in effect.
The runner does not block on a full channel: events that cannot be sent immediately are dropped at V(1). The next tick will re-emit them if the EnqueueFunc still returns the same objects.
func WithInterval ¶
WithInterval sets the polling interval. The option is a no-op when d is non-positive, leaving DefaultInterval in effect.
type Runner ¶
Runner is a controller-runtime sigs.k8s.io/controller-runtime/pkg/manager.Runnable that periodically invokes an EnqueueFunc and emits the returned objects as sigs.k8s.io/controller-runtime/pkg/event.TypedGenericEvent on a channel.
T is the concrete client.Object kind handled by the runner; the emitted channel is typed [chan event.TypedGenericEvent[T]] so callers can wire it into a controller via sigs.k8s.io/controller-runtime/pkg/source.TypedChannel without an additional type assertion.
func NewRunner ¶
func NewRunner[T client.Object](enqueue EnqueueFunc[T], opts ...Option) *Runner[T]
NewRunner returns a Runner configured with the provided enqueue function and options. The returned runner must be registered with a manager via sigs.k8s.io/controller-runtime/pkg/manager.Manager.Add before its channel is wired into a controller.
NewRunner panics when enqueue is nil; a nil enqueue is a programmer error.
func (*Runner[T]) GetEventChannel ¶
func (r *Runner[T]) GetEventChannel() <-chan event.TypedGenericEvent[T]
GetEventChannel returns the channel of emitted sigs.k8s.io/controller-runtime/pkg/event.TypedGenericEvent.
The returned channel is closed when Runner.Start returns.
func (*Runner[T]) Start ¶
Start implements sigs.k8s.io/controller-runtime/pkg/manager.Runnable.
It runs until ctx is canceled, invoking the EnqueueFunc every interval. Each returned object is emitted as a sigs.k8s.io/controller-runtime/pkg/event.TypedGenericEvent. A full channel causes the event to be dropped at V(1); the next tick will re-emit it if the enqueue function still returns the same object.
Start refuses to run a second time and returns an error.