controller

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// Queue gives access to controller queue. This can be used for manual requeue, although if a Sync() function return
	// an error, the object is automatically re-queued. Use with caution.
	Queue() workqueue.RateLimitingInterface

	// GetObjectMeta provides access to currently synced object metadata.
	GetObjectMeta() metav1.Object

	// GetQueueObject provides access to current synced object deep copy.
	// It is safe to mutate this object inside Sync().
	GetQueueObject() runtime.Object

	// Events provide access to event recorder.
	Events() events.Recorder

	// ControllerName gives name of the controller.
	ControllerName() string
}

Context interface represents a context given to the Sync() function where the main controller logic happen. Context exposes controller name and give user access to the queue (for manual requeue). Context also provides metadata about object that informers observed as changed.

type Controller

type Controller interface {
	// Run runs the controller and blocks until the controller is finished.
	// Number of workers can be specified via workers parameter.
	// Note that having more than one worker usually means handing parallelization of Sync().
	Run(ctx context.Context, workers int)

	// ShutdownContext can be used to observe the finished shutdown of all controller workers and controller itself.
	// Example: <-controller.ShutdownContext().Done()
	ShutdownContext() context.Context
}

Controller interface represents a runnable Kubernetes controller. Cancelling the ctx passed will cause the controller to shutdown. Number of workers determine how much parallel the job processing should be.

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 NewFactory

func NewFactory() *Factory

NewFactory return new factory instance.

func (*Factory) Controller

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

Controller produce a runnable controller.

func (*Factory) Informers

func (f *Factory) Informers(informers ...cache.SharedInformer) *Factory

Informers 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) Sync

func (f *Factory) Sync(syncFn SyncFunc) *Factory

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

type SyncFunc

type SyncFunc func(ctx context.Context, controllerContext Context) error

SyncFunc is a function that contain main controller logic. The ctx.ctx passed is the main controller ctx, when cancelled it means the controller is being shut down. The ctx provides access to controller name, queue and event recorder.

Jump to

Keyboard shortcuts

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