Documentation ¶
Index ¶
- Constants
- Variables
- func Filter(gvk schema.GroupVersionKind) func(obj interface{}) booldeprecated
- func FilterController(r kmeta.OwnerRefable) func(obj interface{}) bool
- func FilterControllerGK(gk schema.GroupKind) func(obj interface{}) bool
- func FilterControllerGVK(gvk schema.GroupVersionKind) func(obj interface{}) bool
- func FilterGroupKind(gk schema.GroupKind) func(obj interface{}) booldeprecated
- func FilterGroupVersionKind(gvk schema.GroupVersionKind) func(obj interface{}) booldeprecated
- func FilterWithName(name string) func(obj interface{}) bool
- func FilterWithNameAndNamespace(namespace, name string) func(obj interface{}) bool
- func GetEventRecorder(ctx context.Context) record.EventRecorder
- func GetResyncPeriod(ctx context.Context) time.Duration
- func GetTracker(ctx context.Context) tracker.Interface
- func GetTrackerLease(ctx context.Context) time.Duration
- func HandleAll(h func(interface{})) cache.ResourceEventHandler
- func IsPermanentError(err error) bool
- func IsRequeueKey(err error) (bool, time.Duration)
- func IsSkipKey(err error) bool
- func NewPermanentError(err error) error
- func NewRequeueAfter(dur time.Duration) error
- func NewRequeueImmediately() error
- func NewSkipKey(key string) error
- func PassNew(f func(interface{})) func(interface{}, interface{})
- func RunInformers(stopCh <-chan struct{}, informers ...Informer) (func(), error)
- func StartAll(ctx context.Context, controllers ...*Impl) error
- func StartInformers(stopCh <-chan struct{}, informers ...Informer) error
- func WaitForCacheSyncQuick(stopCh <-chan struct{}, cacheSyncs ...cache.InformerSynced) bool
- func WithEventRecorder(ctx context.Context, er record.EventRecorder) context.Context
- func WithResyncPeriod(ctx context.Context, resync time.Duration) context.Context
- func WithTracker(ctx context.Context, t tracker.Interface) context.Context
- type Callback
- type ControllerOptions
- type Impl
- func (c *Impl) Enqueue(obj interface{})
- func (c *Impl) EnqueueAfter(obj interface{}, after time.Duration)
- func (c *Impl) EnqueueControllerOf(obj interface{})
- func (c *Impl) EnqueueKey(key types.NamespacedName)
- func (c *Impl) EnqueueKeyAfter(key types.NamespacedName, delay time.Duration)
- func (c *Impl) EnqueueLabelOfClusterScopedResource(nameLabel string) func(obj interface{})
- func (c *Impl) EnqueueLabelOfNamespaceScopedResource(namespaceLabel, nameLabel string) func(obj interface{})
- func (c *Impl) EnqueueNamespaceOf(obj interface{})
- func (c *Impl) EnqueueSentinel(k types.NamespacedName) func(interface{})
- func (c *Impl) EnqueueSlow(obj interface{})
- func (c *Impl) EnqueueSlowKey(key types.NamespacedName)
- func (c *Impl) FilteredGlobalResync(f func(interface{}) bool, si cache.SharedInformer)
- func (c *Impl) GlobalResync(si cache.SharedInformer)
- func (c *Impl) MaybeEnqueueBucketKey(bkt reconciler.Bucket, key types.NamespacedName)
- func (c *Impl) Run(ctx context.Context) error
- func (c *Impl) RunContext(ctx context.Context, threadiness int) error
- func (c *Impl) WorkQueue() workqueue.RateLimitingInterface
- type Informer
- type Options
- type OptionsFn
- type Reconciler
- type StatsReporter
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. // TODO rename the const to Concurrency and deprecated this DefaultThreadsPerController = 2 )
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 ¶
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 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 ¶
FilterWithName makes it simple to create FilterFunc's for use with cache.FilteringResourceEventHandler that filter based on a name.
func FilterWithNameAndNamespace ¶
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 ¶
GetResyncPeriod returns the resync period associated with the given context. When none is specified a default resync period is used.
func GetTracker ¶
GetTracker attempts to look up the tracker.Interface on a given context. It may return null if none is found.
func GetTrackerLease ¶
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 ¶
IsPermanentError returns true if the given error is a permanentError or wraps a permanentError.
func IsRequeueKey ¶
IsRequeueKey returns true if the given error is a requeueKeyError.
func NewPermanentError ¶
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 ¶
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 ¶
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 ¶
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 StartInformers ¶
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 ¶
WithEventRecorder attaches the given record.EventRecorder to the provided context in the returned context.
func WithResyncPeriod ¶
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 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 ¶
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 ¶
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) RunContext ¶
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 ¶
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 ¶
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