factory

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 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) types.Controller

Controller produce a runnable controller.

func (*Factory) WithBareInformers

func (f *Factory) WithBareInformers(informers ...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 types.EventFilterFunc, informers ...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 types.EventFilterFunc, informers ...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 types.ObjectQueueKeysFunc, filter types.EventFilterFunc, informers ...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 ...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 ...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 types.ObjectQueueKeysFunc, informers ...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 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 ...types.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 types.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 types.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.

type Informer

type Informer interface {
	AddEventHandler(handler cache.ResourceEventHandler) (cache.ResourceEventHandlerRegistration, error)
	HasSynced() bool
}

Informer represents any structure that allow to register event handlers and informs if caches are synced. Any SharedInformer will comply.

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