poller

package
v1.11.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

View Source
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

type EnqueueFunc[T client.Object] func(ctx context.Context) ([]T, error)

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

func WithBufferSize(n int) Option

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

func WithInterval(d time.Duration) Option

WithInterval sets the polling interval. The option is a no-op when d is non-positive, leaving DefaultInterval in effect.

func WithName

func WithName(name string) Option

WithName sets the logger name attached to the runner's context. It also appears in dropped-event log lines, so it should be unique per runner.

type Runner

type Runner[T client.Object] struct {
	// contains filtered or unexported fields
}

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

func (r *Runner[T]) Start(ctx context.Context) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL