Documentation ¶
Overview ¶
Package engine manages the lifecycle of a set of controllers.
Index ¶
- type ControllerEngine
- func (e *ControllerEngine) GarbageCollectCustomResourceInformers(ctx context.Context) error
- func (e *ControllerEngine) GetClient() client.Client
- func (e *ControllerEngine) GetFieldIndexer() client.FieldIndexer
- func (e *ControllerEngine) GetWatches(name string) ([]WatchID, error)
- func (e *ControllerEngine) IsRunning(name string) bool
- func (e *ControllerEngine) Start(name string, o ...ControllerOption) error
- func (e *ControllerEngine) StartWatches(name string, ws ...Watch) error
- func (e *ControllerEngine) Stop(ctx context.Context, name string) error
- func (e *ControllerEngine) StopWatches(ctx context.Context, name string, ws ...WatchID) (int, error)
- type ControllerEngineOption
- type ControllerOption
- type ControllerOptions
- type EventHandler
- type InformerTrackingCache
- func (c *InformerTrackingCache) ActiveInformers() []schema.GroupVersionKind
- func (c *InformerTrackingCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, ...) error
- func (c *InformerTrackingCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
- func (c *InformerTrackingCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, ...) (cache.Informer, error)
- func (c *InformerTrackingCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
- func (c *InformerTrackingCache) RemoveInformer(ctx context.Context, obj client.Object) error
- type NewControllerFn
- type StoppableSource
- type TrackingInformers
- type Watch
- type WatchGarbageCollector
- type WatchID
- type WatchType
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 ¶
func New(mgr manager.Manager, infs TrackingInformers, c client.Client, o ...ControllerEngineOption) *ControllerEngine
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 ¶
func WithLogger(l logging.Logger) ControllerEngineOption
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 ¶
func NewEventHandler(ctx context.Context, q workqueue.RateLimitingInterface, h handler.EventHandler, ps ...predicate.Predicate) *EventHandler
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 ¶
func (c *InformerTrackingCache) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error
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 ¶
func (c *InformerTrackingCache) GetInformer(ctx context.Context, obj client.Object, opts ...cache.InformerGetOption) (cache.Informer, error)
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 ¶
func (c *InformerTrackingCache) GetInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, opts ...cache.InformerGetOption) (cache.Informer, error)
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 ¶
func (c *InformerTrackingCache) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error
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 ¶
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 ¶
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 ¶
func (s *StoppableSource) Start(ctx context.Context, q workqueue.RateLimitingInterface) error
Start is internal and should be called only by the Controller to register an EventHandler with the Informer to enqueue reconcile.Requests.
type TrackingInformers ¶
type TrackingInformers interface { cache.Informers ActiveInformers() []schema.GroupVersionKind }
TrackingInformers is a set of Informers. It tracks which are active.
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.