engine

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package engine manages the lifecycle of a set of controllers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControllerEngine

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

A ControllerEngine manages a set of controllers that can be dynamically started and stopped. It also manages a dynamic set of watches per controller, and the informers that back them.

func New

New creates a new controller engine.

func (*ControllerEngine) GarbageCollectCustomResourceInformers

func (e *ControllerEngine) GarbageCollectCustomResourceInformers(ctx context.Context) error

GarbageCollectCustomResourceInformers garbage collects informers for custom resources (e.g. Crossplane XRs, claims and composed resources) when the CRD that defines them is deleted. The garbage collector runs until the supplied context is cancelled.

func (*ControllerEngine) GetClient

func (e *ControllerEngine) GetClient() client.Client

GetClient gets a client backed by the controller engine's cache.

func (*ControllerEngine) GetFieldIndexer

func (e *ControllerEngine) GetFieldIndexer() client.FieldIndexer

GetFieldIndexer returns a FieldIndexer that can be used to add indexes to the controller engine's cache.

func (*ControllerEngine) GetWatches

func (e *ControllerEngine) GetWatches(name string) ([]WatchID, error)

GetWatches returns the active watches for the supplied controller.

func (*ControllerEngine) IsRunning

func (e *ControllerEngine) IsRunning(name string) bool

IsRunning returns true if the named controller is running.

func (*ControllerEngine) Start

func (e *ControllerEngine) Start(name string, o ...ControllerOption) error

Start a new controller.

func (*ControllerEngine) StartWatches

func (e *ControllerEngine) StartWatches(name string, ws ...Watch) error

StartWatches instructs the named controller to start the supplied watches. The controller will only start a watch if it's not already watching the type of object specified by the supplied Watch. StartWatches blocks other operations on the same controller if and when it starts a watch.

func (*ControllerEngine) Stop

func (e *ControllerEngine) Stop(ctx context.Context, name string) error

Stop a controller.

func (*ControllerEngine) StopWatches

func (e *ControllerEngine) StopWatches(ctx context.Context, name string, ws ...WatchID) (int, error)

StopWatches stops the supplied watches. StopWatches blocks other operations on the same controller if and when it stops a watch. It returns the number of watches that it successfully stopped.

type ControllerEngineOption

type ControllerEngineOption func(*ControllerEngine)

An ControllerEngineOption configures a controller engine.

func WithLogger

WithLogger configures an Engine to use a logger.

type ControllerOption

type ControllerOption func(o *ControllerOptions)

A ControllerOption configures a controller.

func WithNewControllerFn

func WithNewControllerFn(fn NewControllerFn) ControllerOption

WithNewControllerFn configures how the engine starts a new controller-runtime controller.

func WithRuntimeOptions

func WithRuntimeOptions(ko kcontroller.Options) ControllerOption

WithRuntimeOptions configures the underlying controller-runtime controller.

func WithWatchGarbageCollector

func WithWatchGarbageCollector(gc WatchGarbageCollector) ControllerOption

WithWatchGarbageCollector specifies an optional garbage collector this controller should use to remove unused watches.

type ControllerOptions

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

ControllerOptions configure a controller.

type EventHandler

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

An EventHandler converts a controller-runtime handler and predicates into a client-go ResourceEventHandler. It's a stripped down version of controller-runtime's internal implementation. https://github.com/kubernetes-sigs/controller-runtime/blob/v0.18.2/pkg/internal/source/event_handler.go#L35

func NewEventHandler

NewEventHandler creates a new EventHandler.

func (*EventHandler) HandlerFuncs

func (e *EventHandler) HandlerFuncs() kcache.ResourceEventHandlerFuncs

HandlerFuncs converts EventHandler to a ResourceEventHandlerFuncs.

func (*EventHandler) OnAdd

func (e *EventHandler) OnAdd(obj interface{})

OnAdd creates CreateEvent and calls Create on EventHandler.

func (*EventHandler) OnDelete

func (e *EventHandler) OnDelete(obj interface{})

OnDelete creates DeleteEvent and calls Delete on EventHandler.

func (*EventHandler) OnUpdate

func (e *EventHandler) OnUpdate(oldObj, newObj interface{})

OnUpdate creates UpdateEvent and calls Update on EventHandler.

type InformerTrackingCache

type InformerTrackingCache struct {
	// The wrapped cache.
	cache.Cache
	// contains filtered or unexported fields
}

An InformerTrackingCache wraps a cache.Cache and keeps track of what GVKs it has started informers for. It takes a blocking lock whenever a new informer is started or stopped, but so does the standard controller-runtime Cache implementation.

func TrackInformers

func TrackInformers(c cache.Cache, s *runtime.Scheme) *InformerTrackingCache

TrackInformers wraps the supplied cache, adding a method to query which informers are active.

func (*InformerTrackingCache) ActiveInformers

func (c *InformerTrackingCache) ActiveInformers() []schema.GroupVersionKind

ActiveInformers returns the GVKs of the informers believed to currently be active. The InformerTrackingCache considers an informer to become active when a caller calls Get, List, or one of the GetInformer methods. It considers an informer to become inactive when a caller calls the RemoveInformer method.

func (*InformerTrackingCache) Get

Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.

Getting an object marks the informer for the object's GVK active.

func (*InformerTrackingCache) GetInformer

GetInformer fetches or constructs an informer for the given object that corresponds to a single API kind and resource.

Getting an informer for an object marks the informer as active.

func (*InformerTrackingCache) GetInformerForKind

GetInformerForKind is similar to GetInformer, except that it takes a group-version-kind, instead of the underlying object.

Getting an informer marks the informer as active.

func (*InformerTrackingCache) List

List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.

Listing objects marks the informer for the object's GVK active.

func (*InformerTrackingCache) RemoveInformer

func (c *InformerTrackingCache) RemoveInformer(ctx context.Context, obj client.Object) error

RemoveInformer removes an informer entry and stops it if it was running.

Removing an informer marks the informer as inactive.

type NewControllerFn

type NewControllerFn func(name string, mgr manager.Manager, options kcontroller.Options) (kcontroller.Controller, error)

A NewControllerFn can start a new controller-runtime controller.

type StoppableSource

type StoppableSource struct {
	Type client.Object
	// contains filtered or unexported fields
}

A StoppableSource is a controller-runtime watch source that can be stopped.

func NewStoppableSource

func NewStoppableSource(infs cache.Informers, t client.Object, h handler.EventHandler, ps ...predicate.Predicate) *StoppableSource

NewStoppableSource returns a new watch source that can be stopped.

func (*StoppableSource) Start

Start is internal and should be called only by the Controller to register an EventHandler with the Informer to enqueue reconcile.Requests.

func (*StoppableSource) Stop

func (s *StoppableSource) Stop(ctx context.Context) error

Stop removes the EventHandler from the source's Informer. The Informer will stop sending events to the source.

type TrackingInformers

type TrackingInformers interface {
	cache.Informers
	ActiveInformers() []schema.GroupVersionKind
}

TrackingInformers is a set of Informers. It tracks which are active.

type Watch

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

Watch an object.

func WatchFor

func WatchFor(kind client.Object, wt WatchType, h handler.EventHandler, p ...predicate.Predicate) Watch

WatchFor returns a Watch for the supplied kind of object. Events will be handled by the supplied EventHandler, and may be filtered by the supplied predicates.

type WatchGarbageCollector

type WatchGarbageCollector interface {
	GarbageCollectWatches(ctx context.Context, interval time.Duration)
}

A WatchGarbageCollector periodically garbage collects watches.

type WatchID

type WatchID struct {
	Type WatchType
	GVK  schema.GroupVersionKind
}

A WatchID uniquely identifies a watch.

type WatchType

type WatchType string

A WatchType uniquely identifies a "type" of watch - i.e. a handler and a set of predicates. The controller engine uniquely identifies a Watch by its (kind, watch type) tuple. The engine will only start one watch of each (kind, watch type) tuple. To watch the same kind of resource multiple times, use different watch types.

const (
	WatchTypeClaim               WatchType = "Claim"
	WatchTypeCompositeResource   WatchType = "CompositeResource"
	WatchTypeComposedResource    WatchType = "ComposedResource"
	WatchTypeCompositionRevision WatchType = "CompositionRevision"
)

Common watch types.

Jump to

Keyboard shortcuts

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