factory

package
v0.0.2-0...-eeb6c19 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultQueueKeysFunc

func DefaultQueueKeysFunc(_ runtime.Object) []string

DefaultQueueKeysFunc returns a slice with a single element - the DefaultQueueKey

Types

type Factory

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

Factory is generator that generate standard Kubernetes controllers. Factory is really generic and should be only used for simple controllers that does not require special stuff..

func New

func New() *Factory

New return new factory instance.

func (*Factory) ResyncEvery

func (f *Factory) ResyncEvery(interval time.Duration) *Factory

ResyncEvery will cause the Sync() function to be called periodically, regardless of informers. This is useful when you want to refresh every N minutes or you fear that your informers can be stucked. If this is not called, no periodical resync will happen. Note: The controller context passed to Sync() function in this case does not contain the object metadata or object itself.

This can be used to detect periodical resyncs, but normal Sync() have to be cautious about `nil` objects.

func (*Factory) ResyncSchedule

func (f *Factory) ResyncSchedule(schedules ...string) *Factory

ResyncSchedule allows to supply a Cron syntax schedule that will be used to schedule the sync() call runs. This allows more fine-tuned controller scheduling than ResyncEvery. Examples:

factory.New().ResyncSchedule("@every 1s").ToController() // Every second factory.New().ResyncSchedule("@hourly").ToController() // Every hour factory.New().ResyncSchedule("30 * * * *").ToController() // Every hour on the half hour

Note: The controller context passed to Sync() function in this case does not contain the object metadata or object itself.

This can be used to detect periodical resyncs, but normal Sync() have to be cautious about `nil` objects.

func (*Factory) ToController

func (f *Factory) ToController(name string, eventRecorder events.Recorder) framework.Controller

Controller produce a runnable controller.

func (*Factory) WithBareInformers

func (f *Factory) WithBareInformers(informers ...framework.Informer) *Factory

WithBareInformers allow to register informer that already has custom event handlers registered and no additional event handlers will be added to this informer. The controller will wait for the cache of this informer to be synced. The existing event handlers will have to respect the queue key function or the sync() implementation will have to count with custom queue keys.

func (*Factory) WithFilteredEventsInformers

func (f *Factory) WithFilteredEventsInformers(filter framework.EventFilterFunc, informers ...framework.Informer) *Factory

WithFilteredEventsInformers is used to register event handlers and get the caches synchronized functions. Pass the informers you want to use to react to changes on resources. If informer event is observed, then the Sync() function is called. Pass filter to filter out events that should not trigger Sync() call.

func (*Factory) WithFilteredEventsInformersQueueKeyFunc

func (f *Factory) WithFilteredEventsInformersQueueKeyFunc(queueKeyFn ObjectQueueKeyFunc, filter framework.EventFilterFunc, informers ...framework.Informer) *Factory

WithFilteredEventsInformersQueueKeyFunc is used to register event handlers and get the caches synchronized functions. Pass informers you want to use to react to changes on resources. If informer event is observed, then the Sync() function is called. Pass the queueKeyFn you want to use to transform the informer runtime.Object into string key used by work queue. Pass filter to filter out events that should not trigger Sync() call.

func (*Factory) WithFilteredEventsInformersQueueKeysFunc

func (f *Factory) WithFilteredEventsInformersQueueKeysFunc(queueKeyFn framework.ObjectQueueKeysFunc, filter framework.EventFilterFunc, informers ...framework.Informer) *Factory

WithFilteredEventsInformersQueueKeysFunc is used to register event handlers and get the caches synchronized functions. Pass informers you want to use to react to changes on resources. If informer event is observed, then the Sync() function is called. Pass the queueKeyFn you want to use to transform the informer runtime.Object into string key used by work queue. Pass filter to filter out events that should not trigger Sync() call.

func (*Factory) WithInformers

func (f *Factory) WithInformers(informers ...framework.Informer) *Factory

WithInformers is used to register event handlers and get the caches synchronized functions. Pass informers you want to use to react to changes on resources. If informer event is observed, then the Sync() function is called.

func (*Factory) WithInformersQueueKeyFunc

func (f *Factory) WithInformersQueueKeyFunc(queueKeyFn ObjectQueueKeyFunc, informers ...framework.Informer) *Factory

WithInformersQueueKeyFunc is used to register event handlers and get the caches synchronized functions. Pass informers you want to use to react to changes on resources. If informer event is observed, then the Sync() function is called. Pass the queueKeyFn you want to use to transform the informer runtime.Object into string key used by work queue.

func (*Factory) WithInformersQueueKeysFunc

func (f *Factory) WithInformersQueueKeysFunc(queueKeyFn framework.ObjectQueueKeysFunc, informers ...framework.Informer) *Factory

WithInformersQueueKeysFunc is used to register event handlers and get the caches synchronized functions. Pass informers you want to use to react to changes on resources. If informer event is observed, then the Sync() function is called. Pass the queueKeyFn you want to use to transform the informer runtime.Object into string key used by work queue.

func (*Factory) WithNamespaceInformer

func (f *Factory) WithNamespaceInformer(informer framework.Informer, interestingNamespaces ...string) *Factory

WithNamespaceInformer is used to register event handlers and get the caches synchronized functions. The sync function will only trigger when the object observed by this informer is a namespace and its name matches the interestingNamespaces. Do not use this to register non-namespace informers.

func (*Factory) WithPostStartHooks

func (f *Factory) WithPostStartHooks(hooks ...framework.PostStartHook) *Factory

WithPostStartHooks allows to register functions that will run asynchronously after the controller is started via Run command.

func (*Factory) WithSync

func (f *Factory) WithSync(syncFn framework.ControllerSyncFn) *Factory

WithSync is used to set the controller synchronization function. This function is the core of the controller and is usually hold the main controller logic.

func (*Factory) WithSyncContext

func (f *Factory) WithSyncContext(ctx framework.Context) *Factory

WithSyncContext allows to specify custom, existing sync context for this factory. This is useful during unit testing where you can override the default event recorder or mock the runtime objects. If this function not called, a Context is created by the factory automatically.

func (*Factory) WithSyncErrorHandler

func (f *Factory) WithSyncErrorHandler(fn func(err error) error) *Factory

WithSyncErrorHandler allows in case the sync() function return error to additionally handle the error. This allows to build error handling mechanisms that for example report operator status or provide error count metrics for controller. NOTE: The original error is always returned from sync() call (so it is retried as usual). NOTE2: If the error is SyntheticRequeueError this error is not being handled and the sync() is simply retried. NOTE3: If an error is returned from the handler, this error causes panic()

func (*Factory) WithSyncPanicHandler

func (f *Factory) WithSyncPanicHandler(fn func(panicInterface interface{}) error) *Factory

WithSyncPanicHandler allows to register a panic() handler for Run() method of controller. This handler will recover from any panic inside the sync() and pass the panic into given function. This allows to update operator status OR it allows specific controller metrics to be created. If the panic handler is not specified, the util.HandleCrash() is called as usual.

type ObjectQueueKeyFunc

type ObjectQueueKeyFunc func(runtime.Object) string

ObjectQueueKeyFunc is used to make a string work queue key out of the runtime object that is passed to it. This can extract the "namespace/name" if you need to or just return "key" if you building controller that only use string triggers. DEPRECATED: use ObjectQueueKeysFunc instead

Jump to

Keyboard shortcuts

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