controller

package
v0.0.0-...-afacdd9 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller[T comparable] struct {
	// Name is used to uniquely identify a Controller in tracing, logging and monitoring.  Name is required.
	Name string

	// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
	MaxConcurrentReconciles int

	// Reconciler is a function that can be called at any time with the Name / Namespace of an object and
	// ensures that the state of the system matches the state specified in the object.
	// Defaults to the DefaultReconcileFunc.
	Do reconcile.Reconciler[T]

	// MakeQueue constructs the queue for this controller once the controller is ready to start.
	// This exists because the standard Kubernetes workqueues start themselves immediately, which
	// leads to goroutine leaks if something calls controller.New repeatedly.
	MakeQueue func() workqueue.RateLimitingInterface

	// Queue is an listeningQueue that listens for events from Informers and adds object keys to
	// the Queue for processing
	Queue workqueue.RateLimitingInterface

	// Started is true if the Controller has been Started
	Started bool

	// LogConstructor is used to construct a logger to then log messages to users during reconciliation,
	// or for example when a watch is started.
	// Note: LogConstructor has to be able to handle nil requests as we are also using it
	// outside the context of a reconciliation.
	LogConstructor func(request *reconcile.Request[T]) logr.Logger

	// RecoverPanic indicates whether the panic caused by reconcile should be recovered.
	RecoverPanic *bool

	// LeaderElected indicates whether the controller is leader elected or always running.
	LeaderElected *bool
	// contains filtered or unexported fields
}

func (*Controller[T]) GetLogger

func (c *Controller[T]) GetLogger() logr.Logger

func (*Controller[T]) NeedLeaderElection

func (c *Controller[T]) NeedLeaderElection() bool

func (*Controller[T]) Reconcile

func (c *Controller[T]) Reconcile(ctx context.Context, req reconcile.Request[T]) (_ reconcile.Result, err error)

func (*Controller[T]) Start

func (c *Controller[T]) Start(ctx context.Context) error

func (*Controller[T]) Watch

func (c *Controller[T]) Watch(src source.Source[T], eventHandler handler.EventHandler[T], predicates ...predicate.Predicate[T]) error

type Interface

type Interface[T comparable] interface {
	reconcile.Reconciler[T]

	// Watch takes events provided by a Source and uses the EventHandler to
	// enqueue reconcile.Requests in response to the events.
	//
	// Watch may be provided one or more Predicates to filter events before
	// they are given to the EventHandler.  Events will be passed to the
	// EventHandler if all provided Predicates evaluate to true.
	Watch(src source.Source[T], eventHandler handler.EventHandler[T], predicates ...predicate.Predicate[T]) error

	// Start starts the controller.  Start blocks until the context is closed or a
	// controller has an error starting.
	Start(ctx context.Context) error

	// GetLogger returns this controller logger prefilled with basic information.
	GetLogger() logr.Logger
}

func New

func New[T comparable](name string, mgr manager.Manager, options Options[T]) (Interface[T], error)

New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have been synced before the Controller is Started.

func NewUnmanaged

func NewUnmanaged[T comparable](name string, mgr manager.Manager, options Options[T]) (Interface[T], error)

NewUnmanaged returns a new controller without adding it to the manager. The caller is responsible for starting the returned controller.

type Options

type Options[T comparable] struct {
	config.Controller

	// Reconciler reconciles an object
	Reconciler reconcile.Reconciler[T]

	// RateLimiter is used to limit how frequently requests may be queued.
	// Defaults to MaxOfRateLimiter which has both overall and per-item rate limiting.
	// The overall is a token bucket and the per-item is exponential.
	RateLimiter ratelimiter.RateLimiter

	// LogConstructor is used to construct a logger used for this controller and passed
	// to each reconciliation via the context field.
	LogConstructor func(request *reconcile.Request[T]) logr.Logger

	MetricsRegistry *prometheus.Registry
}

Options are the arguments for creating a new Controller.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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