Documentation

Index

Constants

const (

	// DefaultResyncPeriod is the default duration that is used when no
	// resync period is associated with a controllers initialization context.
	DefaultResyncPeriod = 10 * time.Hour
)

Variables

var (
	// DefaultThreadsPerController is the number of threads to use
	// when processing the controller's workqueue.  Controller binaries
	// may adjust this process-wide default.  For finer control, invoke
	// Run on the controller directly.
	DefaultThreadsPerController = 2
)

var (
	NamespaceTagKey = tag.MustNewKey(metricskey.LabelNamespaceName)
)

Functions

func Filter

func Filter(gvk schema.GroupVersionKind) func(obj interface{}) bool

Filter makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on the schema.GroupVersionKind of the controlling resources.

Deprecated: Use FilterGroupVersionKind or FilterGroupKind instead

func FilterControllerGK

func FilterControllerGK(gk schema.GroupKind) func(obj interface{}) bool

FilterControllerGK makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on the schema.GroupKind of the controlling resources.

func FilterControllerGVK

func FilterControllerGVK(gvk schema.GroupVersionKind) func(obj interface{}) bool

FilterControllerGVK makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on the schema.GroupVersionKind of the controlling resources.

func FilterGroupKind

func FilterGroupKind(gk schema.GroupKind) func(obj interface{}) bool

FilterGroupKind makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on the schema.GroupKind of the controlling resources.

Deprecated: Use FilterControllerGK instead

func FilterGroupVersionKind

func FilterGroupVersionKind(gvk schema.GroupVersionKind) func(obj interface{}) bool

FilterGroupVersionKind makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on the schema.GroupVersionKind of the controlling resources.

Deprecated: Use FilterControllerGVK instead.

func FilterWithName

func FilterWithName(name string) func(obj interface{}) bool

FilterWithName makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on a name.

func FilterWithNameAndNamespace

func FilterWithNameAndNamespace(namespace, name string) func(obj interface{}) bool

FilterWithNameAndNamespace makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on a namespace and a name.

func GetEventRecorder

func GetEventRecorder(ctx context.Context) record.EventRecorder

GetEventRecorder attempts to look up the record.EventRecorder on a given context. It may return null if none is found.

func GetResyncPeriod

func GetResyncPeriod(ctx context.Context) time.Duration

GetResyncPeriod returns the resync period associated with the given context. When none is specified a default resync period is used.

func GetTrackerLease

func GetTrackerLease(ctx context.Context) time.Duration

GetTrackerLease fetches the tracker lease from the controller context.

func HandleAll

func HandleAll(h func(interface{})) cache.ResourceEventHandler

HandleAll wraps the provided handler function into a cache.ResourceEventHandler that sends all events to the given handler. For Updates, only the new object is forwarded.

func IsPermanentError

func IsPermanentError(err error) bool

IsPermanentError returns true if the given error is a permanentError or wraps a permanentError.

func NewPermanentError

func NewPermanentError(err error) error

NewPermanentError returns a new instance of permanentError. Users can wrap an error as permanentError with this in reconcile when they do not expect the key to get re-queued.

func PassNew

func PassNew(f func(interface{})) func(interface{}, interface{})

PassNew makes it simple to create an UpdateFunc for use with cache.ResourceEventHandlerFuncs that can delegate the same methods as AddFunc/DeleteFunc but passing through only the second argument (which is the "new" object).

func RunInformers

func RunInformers(stopCh <-chan struct{}, informers ...Informer) (func(), error)

RunInformers kicks off all of the passed informers and then waits for all of them to synchronize. Returned function will wait for all informers to finish.

func StartAll

func StartAll(ctx context.Context, controllers ...*Impl)

StartAll kicks off all of the passed controllers with DefaultThreadsPerController.

func StartInformers

func StartInformers(stopCh <-chan struct{}, informers ...Informer) error

StartInformers kicks off all of the passed informers and then waits for all of them to synchronize.

func WithEventRecorder

func WithEventRecorder(ctx context.Context, er record.EventRecorder) context.Context

WithEventRecorder attaches the given record.EventRecorder to the provided context in the returned context.

func WithResyncPeriod

func WithResyncPeriod(ctx context.Context, resync time.Duration) context.Context

WithResyncPeriod associates the given resync period with the given context in the context that is returned.

Types

type Callback

type Callback func(interface{})

Callback is a function that is passed to an informer's event handler.

func EnsureTypeMeta

func EnsureTypeMeta(f Callback, gvk schema.GroupVersionKind) Callback

EnsureTypeMeta augments the passed-in callback, ensuring that all objects that pass through this callback have their TypeMeta set according to the provided GVK.

type ControllerOptions

type ControllerOptions struct {
	WorkQueueName string
	Logger        *zap.SugaredLogger
	Reporter      StatsReporter
	RateLimiter   workqueue.RateLimiter
}

ControllerOptions encapsulates options for creating a new controller, including throttling and stats behavior.

type Impl

type Impl struct {
	// Name is the unique name for this controller workqueue within this process.
	// This is used for surfacing metrics, and per-controller leader election.
	Name string

	// Reconciler is the workhorse of this controller, it is fed the keys
	// from the workqueue to process.  Public for testing.
	Reconciler Reconciler
	// contains filtered or unexported fields
}

Impl is our core controller implementation. It handles queuing and feeding work from the queue to an implementation of Reconciler.

func NewImpl

func NewImpl(r Reconciler, logger *zap.SugaredLogger, workQueueName string) *Impl

NewImpl instantiates an instance of our controller that will feed work to the provided Reconciler as it is enqueued. Deprecated: use NewImplFull.

func NewImplFull

func NewImplFull(r Reconciler, options ControllerOptions) *Impl

NewImplFull accepts the full set of options available to all controllers.

func NewImplWithStats

func NewImplWithStats(r Reconciler, logger *zap.SugaredLogger, workQueueName string, reporter StatsReporter) *Impl

NewImplWithStats creates a controller.Impl with stats reporter. Deprecated: use NewImplFull.

func (*Impl) Enqueue

func (c *Impl) Enqueue(obj interface{})

Enqueue takes a resource, converts it into a namespace/name string, and passes it to EnqueueKey.

func (*Impl) EnqueueAfter

func (c *Impl) EnqueueAfter(obj interface{}, after time.Duration)

EnqueueAfter takes a resource, converts it into a namespace/name string, and passes it to EnqueueKey.

func (*Impl) EnqueueControllerOf

func (c *Impl) EnqueueControllerOf(obj interface{})

EnqueueControllerOf takes a resource, identifies its controller resource, converts it into a namespace/name string, and passes that to EnqueueKey.

func (*Impl) EnqueueKey

func (c *Impl) EnqueueKey(key types.NamespacedName)

EnqueueKey takes a namespace/name string and puts it onto the work queue.

func (*Impl) EnqueueKeyAfter

func (c *Impl) EnqueueKeyAfter(key types.NamespacedName, delay time.Duration)

EnqueueKeyAfter takes a namespace/name string and schedules its execution in the work queue after given delay.

func (*Impl) EnqueueLabelOfClusterScopedResource

func (c *Impl) EnqueueLabelOfClusterScopedResource(nameLabel string) func(obj interface{})

EnqueueLabelOfClusterScopedResource returns with an Enqueue func that takes a resource, identifies its controller resource through given name label, and passes it to EnqueueKey. The controller resource must be of cluster-scoped.

func (*Impl) EnqueueLabelOfNamespaceScopedResource

func (c *Impl) EnqueueLabelOfNamespaceScopedResource(namespaceLabel, nameLabel string) func(obj interface{})

EnqueueLabelOfNamespaceScopedResource returns with an Enqueue func that takes a resource, identifies its controller resource through given namespace and name labels, converts it into a namespace/name string, and passes that to EnqueueKey. The controller resource must be of namespace-scoped.

func (*Impl) EnqueueNamespaceOf

func (c *Impl) EnqueueNamespaceOf(obj interface{})

EnqueueNamespaceOf takes a resource, and enqueues the Namespace to which it belongs.

func (*Impl) EnqueueSentinel

func (c *Impl) EnqueueSentinel(k types.NamespacedName) func(interface{})

EnqueueSentinel returns a Enqueue method which will always enqueue a predefined key instead of the object key.

func (*Impl) EnqueueSlow

func (c *Impl) EnqueueSlow(obj interface{})

EnqueueSlow extracts namespaced name from the object and enqueues it on the slow work queue.

func (*Impl) EnqueueSlowKey

func (c *Impl) EnqueueSlowKey(key types.NamespacedName)

EnqueueSlowKey takes a resource, converts it into a namespace/name string, and enqueues that key in the slow lane.

func (*Impl) FilteredGlobalResync

func (c *Impl) FilteredGlobalResync(f func(interface{}) bool, si cache.SharedInformer)

FilteredGlobalResync enqueues all objects from the SharedInformer that pass the filter function in to the slow queue.

func (*Impl) GlobalResync

func (c *Impl) GlobalResync(si cache.SharedInformer)

GlobalResync enqueues into the slow lane all objects from the passed SharedInformer

func (*Impl) MaybeEnqueueBucketKey

func (c *Impl) MaybeEnqueueBucketKey(bkt reconciler.Bucket, key types.NamespacedName)

MaybeEnqueueBucketKey takes a Bucket and namespace/name string and puts it onto the slow work queue.

func (*Impl) Run

func (c *Impl) Run(threadiness int, stopCh <-chan struct{}) error

DEPRECATED use RunContext instead.

func (*Impl) RunContext

func (c *Impl) RunContext(ctx context.Context, threadiness int) error

RunContext starts the controller's worker threads, the number of which is threadiness. If the context has been decorated for LeaderElection, then an elector is built and run. It then blocks until the context is cancelled, at which point it shuts down its internal work queue and waits for workers to finish processing their current work items.

func (*Impl) WorkQueue

func (c *Impl) WorkQueue() workqueue.RateLimitingInterface

WorkQueue permits direct access to the work queue.

type Informer

type Informer interface {
	Run(<-chan struct{})
	HasSynced() bool
}

Informer is the group of methods that a type must implement to be passed to StartInformers.

type Options

type Options struct {
	// ConfigStore is used to attach the frozen configuration to the context.
	ConfigStore reconciler.ConfigStore

	// FinalizerName is the name of the finalizer this reconciler uses. This
	// overrides a default finalizer name assigned by the generator if needed.
	FinalizerName string

	// AgentName is the name of the agent this reconciler uses. This overrides
	// the default controller's agent name.
	AgentName string

	// SkipStatusUpdates configures this reconciler to either do automated status
	// updates (default) or skip them if this is set to true.
	SkipStatusUpdates bool
}

Options is additional resources a Controller might want to use depending on implementation.

type OptionsFn

type OptionsFn func(impl *Impl) Options

OptionsFn is a callback method signature that accepts an Impl and returns Options. Used for controllers that need access to the members of Options but to build Options, integrators need an Impl.

type Reconciler

type Reconciler interface {
	Reconcile(ctx context.Context, key string) error
}

Reconciler is the interface that controller implementations are expected to implement, so that the shared controller.Impl can drive work through it.

type StatsReporter

type StatsReporter interface {
	// ReportQueueDepth reports the queue depth metric
	ReportQueueDepth(v int64) error

	// ReportReconcile reports the count and latency metrics for a reconcile operation
	ReportReconcile(duration time.Duration, success string, key types.NamespacedName) error
}

StatsReporter defines the interface for sending metrics

func MustNewStatsReporter

func MustNewStatsReporter(reconciler string, logger *zap.SugaredLogger) StatsReporter

MustNewStatsReporter creates a new instance of StatsReporter. Logs fatally if creation fails.

func NewStatsReporter

func NewStatsReporter(reconciler string) (StatsReporter, error)

NewStatsReporter creates a reporter that collects and reports metrics

Directories

Path Synopsis
testing