controller

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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.
	// TODO rename the const to Concurrency and deprecated this
	DefaultThreadsPerController = 2
)
View Source
var (

	// NamespaceTagKey marks metrics with a namespace.
	NamespaceTagKey = tag.MustNewKey(metricskey.LabelNamespaceName)
)

Functions

func Filter deprecated

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 FilterController

func FilterController(r kmeta.OwnerRefable) func(obj interface{}) bool

FilterController makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on the controlling resource.

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 deprecated

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 deprecated

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 GetTracker

func GetTracker(ctx context.Context) tracker.Interface

GetTracker attempts to look up the tracker.Interface on a given context. It may return null if none is found.

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 IsRequeueKey

func IsRequeueKey(err error) (bool, time.Duration)

IsRequeueKey returns true if the given error is a requeueKeyError.

func IsSkipKey

func IsSkipKey(err error) bool

IsSkipKey returns true if the given error is a skipKeyError.

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 NewRequeueAfter

func NewRequeueAfter(dur time.Duration) error

NewRequeueAfter returns a new instance of requeueKeyError. Users can return this type of error to requeue a key after a delay.

func NewRequeueImmediately

func NewRequeueImmediately() error

NewRequeueImmediately returns a new instance of requeueKeyError. Users can return this type of error to immediately requeue a key.

func NewSkipKey

func NewSkipKey(key string) error

NewSkipKey returns a new instance of skipKeyError. Users can return this type of error to indicate that the key was skipped.

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) error

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 WaitForCacheSyncQuick

func WaitForCacheSyncQuick(stopCh <-chan struct{}, cacheSyncs ...cache.InformerSynced) bool

WaitForCacheSyncQuick is the same as cache.WaitForCacheSync but with a much reduced check-rate for the sync period.

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.

func WithTracker

func WithTracker(ctx context.Context, t tracker.Interface) context.Context

WithTracker attaches the given tracker.Interface to the provided context in the returned context.

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
	Concurrency   int
}

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

	// Concurrency - The number of workers to use when processing the controller's workqueue.
	Concurrency int

	// Tracker allows reconcilers to associate a reference with particular key,
	// such that when the reference changes the key is queued for reconciliation.
	Tracker tracker.Interface
	// 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 NewContext

func NewContext(ctx context.Context, r Reconciler, options ControllerOptions) *Impl

NewContext instantiates an instance of our controller that will feed work to the provided Reconciler as it is enqueued.

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(ctx context.Context) error

Run runs the controller with it's configured Concurrency

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

	// DemoteFunc configures the demote function this reconciler uses
	DemoteFunc func(b reconciler.Bucket)

	// Concurrency - The number of workers to use when processing the controller's workqueue.
	Concurrency int

	// PromoteFilterFunc filters the objects that are enqueued when the reconciler is promoted to leader.
	// Objects that pass the filter (return true) will be reconciled when a new leader is promoted.
	// If no filter is specified, all objects will be reconciled.
	PromoteFilterFunc func(obj interface{}) 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

Jump to

Keyboard shortcuts

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