controller

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MPL-2.0 Imports: 8 Imported by: 3

Documentation

Overview

Package controller defines common interfaces to be implemented by the controllers and controller runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	Name() string
	Inputs() []Input
	Outputs() []Output

	Run(context.Context, Runtime, *zap.Logger) error
}

Controller interface should be implemented by Controllers.

type DependencyEdge

type DependencyEdge struct {
	ControllerName string

	ResourceNamespace resource.Namespace
	ResourceType      resource.Type
	ResourceID        resource.ID

	EdgeType DependencyEdgeType
}

DependencyEdge represents relationship between controller and resource(s).

type DependencyEdgeType

type DependencyEdgeType int

DependencyEdgeType is edge type in controller graph.

const (
	EdgeOutputExclusive DependencyEdgeType = iota
	EdgeOutputShared
	EdgeInputStrong
	EdgeInputWeak
	EdgeInputDestroyReady
	EdgeInputQPrimary
	EdgeInputQMapped
	EdgeInputQMappedDestroyReady
)

Controller graph edge types.

type DependencyGraph

type DependencyGraph struct {
	Edges []DependencyEdge
}

DependencyGraph is the exported information about controller/resources dependencies.

type Engine

type Engine interface {
	// RegisterController registers new controller.
	RegisterController(ctrl Controller) error
	// RegisterQController registers new QController.
	RegisterQController(ctrl QController) error
	// Run the controllers.
	Run(ctx context.Context) error
}

Engine is the entrypoint into Controller Runtime.

type Input

type Input struct {
	Namespace resource.Namespace
	Type      resource.Type
	ID        optional.Optional[resource.ID]
	Kind      InputKind
}

Input of the controller (dependency on some resource(s)).

Each controller might have multiple inputs, it might depend on all the objects of some type under namespace, or on specific object by ID.

Input might be either Weak or Strong. Any kind of input triggers cascading reconcile on changes, Strong dependencies in addition block deletion of parent object until all the dependencies are torn down.

Input can also be "DestroyReady" which means that the controller is watching some of its outputs to be ready to be destroyed. Controller will be notified when the resource enters "teardown" phase and has no finalizers attached. Resources are filtered to be owned by the controller.

func (Input) Compare added in v0.3.13

func (a Input) Compare(b Input) int

Compare defines Input sort order.

func (Input) EqualKeys added in v0.3.13

func (a Input) EqualKeys(b Input) bool

EqualKeys checks if two Inputs have equal (conflicting) keys.

type InputKind

type InputKind = int

InputKind for inputs.

const (
	InputWeak InputKind = iota
	InputStrong
	InputDestroyReady
	// InputQPrimary is put to the queue of the QController directly by metadata.
	InputQPrimary
	// InputQMapped is mapped by the QController to one of the primary inputs.
	InputQMapped
	// InputQMappedDestroyReady is mapped by the QController to one of the primary inputs.
	//
	// On top of mapping, filtered by FilterDestroyReady.
	InputQMappedDestroyReady
)

Input kinds.

type Option added in v0.3.1

type Option func(*Options)

Option for operation.

func WithOwner added in v0.3.1

func WithOwner(owner string) Option

WithOwner allows to specify owner of the resource.

type Options added in v0.3.1

type Options struct {
	Owner *string
}

Options for operation.

func ToOptions added in v0.3.1

func ToOptions(opts ...Option) Options

ToOptions converts variadic options to Options.

type Output

type Output struct {
	Type resource.Type
	Kind OutputKind
}

Output of the controller.

Controller can only modify resources which are declared as outputs.

type OutputKind

type OutputKind = int

OutputKind for outputs.

const (
	OutputExclusive OutputKind = iota
	OutputShared
)

Output kinds.

type OutputTracker added in v0.3.1

type OutputTracker interface {
	StartTrackingOutputs()
	CleanupOutputs(ctx context.Context, outputs ...resource.Kind) error
}

OutputTracker provides automatic cleanup of the outputs based on the calls to Modify function.

OutputTracker is optional, it is enabled by calling StartTrackingOutputs at the beginning of the reconcile cycle. Every call to Modify will be tracked and the outputs which are not touched will be destroyed. Finalize the cleanup by calling CleanupOutputs at the end of the reconcile cycle, it also automatically calls ResetRestartBackoff.

CleanupOutputs doesn't support finalizers on output resources.

type QController added in v0.4.0

type QController interface {
	// Name returns the name of the controller.
	Name() string

	// Settings is called exactly once before the controller is started.
	Settings() QSettings

	// Reconcile is called for each item in the queue.
	//
	// Reconcile might be called concurrently for different resource.Pointers.
	// If Reconcile succeeds, the item is removed from the queue.
	// If Reconcile fails, the item is requeued with exponential backoff.
	Reconcile(context.Context, *zap.Logger, QRuntime, resource.Pointer) error

	// MapInput is called for each input of kind ItemQMapped.
	//
	// MapInput returns the item(s) which should be put to the queue for the mapped input.
	// For example, MapInput might convert watch events in secondary input to primary input items.
	//
	// MapInput failures are treated in the same way as Reconcile failures.
	MapInput(context.Context, *zap.Logger, QRuntime, resource.Pointer) ([]resource.Pointer, error)
}

QController interface should be implemented by queue-based Controllers.

What is difference between Controller and QController?

Controller is triggered for any change in inputs, and the change is unspecified. Multiple changes in inputs are coalesced into a single change as long as the controller is busy reconciling previous changes. Controller always processes all inputs (i.e. it lists and transforms the all in a single reconcile loop). If the Controller fails, it is retried with exponential backoff, but for all inputs.

QController always processes a single input, but different inputs might be processed in parallel (in goroutines). QController has a queue of items to be reconciled, with an optional backoff for each item. QController can return an error (fail) for a single item, and the item will be retried with exponential backoff (requeue after). QController should use finalizers on inputs to ensure that outputs are cleaned up properly. On startup, QController queue is filled with all inputs.

Controller might be triggered by events not related to the controller runtime (e.g. Linux inotify), QController doesn't support that.

type QRuntime added in v0.4.0

type QRuntime interface {
	ReaderWriter
	UncachedReader
}

QRuntime interface as presented to the QController.

type QSettings added in v0.4.0

type QSettings struct {
	RunHook      func(context.Context, *zap.Logger, QRuntime) error
	ShutdownHook func()
	Inputs       []Input
	Outputs      []Output
	Concurrency  optional.Optional[uint]
}

QSettings configures runtime for the QController.

type Reader

Reader provides read-only access to the state.

Interface state.State also satisfies this interface.

type ReaderWriter added in v0.3.0

type ReaderWriter interface {
	Reader
	Writer
}

ReaderWriter combines Reader and Writer interfaces.

type ReconcileEvent

type ReconcileEvent struct{}

ReconcileEvent is a signal for controller to reconcile its resources.

type RequeueError added in v0.4.0

type RequeueError struct {
	// contains filtered or unexported fields
}

RequeueError is returned by QController.Reconcile to requeue the item with specified backoff.

RequeueError might contain or might not contain an actual error, in either case the item is requeued with specified backoff. If the error is not nil, the error is logged and counted as a controller crash.

func NewRequeueError added in v0.4.0

func NewRequeueError(err error, interval time.Duration) *RequeueError

NewRequeueError creates a new RequeueError.

func NewRequeueErrorf added in v0.4.0

func NewRequeueErrorf(interval time.Duration, format string, args ...interface{}) *RequeueError

NewRequeueErrorf creates a new RequeueError with specified backoff interval.

func NewRequeueInterval added in v0.4.0

func NewRequeueInterval(interval time.Duration) *RequeueError

NewRequeueInterval creates a new RequeueError with specified backoff interval.

func (*RequeueError) Err added in v0.4.0

func (err *RequeueError) Err() error

Err returns the error.

func (*RequeueError) Error added in v0.4.0

func (err *RequeueError) Error() string

Error implements error interface.

func (*RequeueError) Interval added in v0.4.0

func (err *RequeueError) Interval() time.Duration

Interval returns the backoff interval.

func (*RequeueError) Unwrap added in v0.4.0

func (err *RequeueError) Unwrap() error

Unwrap implements errors.Unwrap interface.

type Runtime

type Runtime interface {
	EventCh() <-chan ReconcileEvent
	QueueReconcile()
	ResetRestartBackoff()

	UpdateInputs([]Input) error

	Reader
	UncachedReader
	Writer
	OutputTracker
}

Runtime interface as presented to the controller.

type UncachedReader added in v0.4.6

type UncachedReader interface {
	GetUncached(context.Context, resource.Pointer, ...state.GetOption) (resource.Resource, error)
	ListUncached(context.Context, resource.Kind, ...state.ListOption) (resource.List, error)
}

UncachedReader provides read-only access to the state without cache.

It might cause performance penalty, use only when necessary.

type Writer

Writer provides write access to the state.

Only output objects can be written to by the controller.

Directories

Path Synopsis
Package conformance implements tests which verify conformance of the implementation with the spec.
Package conformance implements tests which verify conformance of the implementation with the spec.
Package generic provides implementations of generic controllers.
Package generic provides implementations of generic controllers.
cleanup
Package cleanup provides a generic implementation of controller which waits for and cleans up resources.
Package cleanup provides a generic implementation of controller which waits for and cleans up resources.
destroy
Package destroy provides a generic implementation of controller which cleans up tearing down resources without finalizers.
Package destroy provides a generic implementation of controller which cleans up tearing down resources without finalizers.
qtransform
Package qtransform implements a generic controller which transforms Input resources into Output resources based on QController.
Package qtransform implements a generic controller which transforms Input resources into Output resources based on QController.
transform
Package transform provides a generic implementation of controller which transforms resources A into resources B.
Package transform provides a generic implementation of controller which transforms resources A into resources B.
Package runtime implements the controller runtime.
Package runtime implements the controller runtime.
internal/adapter
Package adapter provides common interface for controller adapters.
Package adapter provides common interface for controller adapters.
internal/cache
Package cache implements resource cache.
Package cache implements resource cache.
internal/controllerstate
Package controllerstate provides adapter which filters access to the resource state by controller inputs/outputs.
Package controllerstate provides adapter which filters access to the resource state by controller inputs/outputs.
internal/dependency
Package dependency implements controller dependency database.
Package dependency implements controller dependency database.
internal/qruntime
Package qruntime implements queue-based runtime for controllers.
Package qruntime implements queue-based runtime for controllers.
internal/qruntime/internal/containers
Package containers provides helper containers for qruntime.
Package containers provides helper containers for qruntime.
internal/qruntime/internal/queue
Package queue implements a concurrent queue of reconcile items.
Package queue implements a concurrent queue of reconcile items.
internal/qruntime/internal/timer
Package timer provides a resettable timer.
Package timer provides a resettable timer.
internal/reduced
Package reduced implements reducing resource metadata to a comparable value.
Package reduced implements reducing resource metadata to a comparable value.
internal/rruntime
Package rruntime implements runtime for Controllers (which reconcile full set of inputs on each iteration).
Package rruntime implements runtime for Controllers (which reconcile full set of inputs on each iteration).
metrics
Package metrics expose various controller runtime metrics using expvar.
Package metrics expose various controller runtime metrics using expvar.
options
Package options provides functional options for controller runtime.
Package options provides functional options for controller runtime.

Jump to

Keyboard shortcuts

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