Documentation ¶
Index ¶
- Constants
- Variables
- func Filter(gvk schema.GroupVersionKind) 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 GetTrackerLease(ctx context.Context) time.Duration
- func HandleAll(h func(interface{})) cache.ResourceEventHandler
- func IsPermanentError(err error) bool
- func NewPermanentError(err error) error
- func PassNew(f func(interface{})) func(interface{}, interface{})
- func SendGlobalUpdates(si cache.SharedInformer, handler cache.ResourceEventHandler)
- func StartAll(stopCh <-chan struct{}, controllers ...*Impl)
- func StartInformers(stopCh <-chan struct{}, informers ...Informer) error
- func WithEventRecorder(ctx context.Context, er record.EventRecorder) context.Context
- func WithResyncPeriod(ctx context.Context, resync time.Duration) context.Context
- type Callback
- 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 string)
- func (c *Impl) EnqueueKeyAfter(key string, 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) GlobalResync(si cache.SharedInformer)
- func (c *Impl) Run(threadiness int, stopCh <-chan struct{}) error
- type Informer
- 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. DefaultThreadsPerController = 2 )
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.
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 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 given error is permanentError
func NewPermanentError ¶
NewPermanentError returns a new instance of permanentError. Users can wrap an error as permanentError with this in reconcile, when he does 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 SendGlobalUpdates ¶
func SendGlobalUpdates(si cache.SharedInformer, handler cache.ResourceEventHandler)
SendGlobalUpdates triggers an update event for all objects from the passed SharedInformer.
Since this is triggered not by a real update of these objects themselves, we have no way of knowing the change to these objects if any, so we call handler.OnUpdate(obj, obj) for all of them regardless if they have changes or not.
func StartAll ¶
func StartAll(stopCh <-chan struct{}, controllers ...*Impl)
StartAll kicks off all of the passed controllers with DefaultThreadsPerController.
func StartInformers ¶
StartInformers kicks off all of the passed informers and then waits for all of them to synchronize.
func WithEventRecorder ¶
WithEventRecorder attaches the given record.EventRecorder to the provided context in the returned context.
Types ¶
type Callback ¶
type Callback func(interface{})
func EnsureTypeMeta ¶
func EnsureTypeMeta(f Callback, gvk schema.GroupVersionKind) Callback
type Impl ¶
type Impl struct { // Reconciler is the workhorse of this controller, it is fed the keys // from the workqueue to process. Public for testing. Reconciler Reconciler // WorkQueue is a rate limited work queue. This is used to queue work to be // processed instead of performing it as soon as a change happens. This // means we can ensure we only process a fixed amount of resources at a // time, and makes it easy to ensure we are never processing the same item // simultaneously in two different workers. WorkQueue workqueue.RateLimitingInterface // 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.
func NewImplWithStats ¶
func NewImplWithStats(r Reconciler, logger *zap.SugaredLogger, workQueueName string, reporter StatsReporter) *Impl
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 ¶
EnqueueKey takes a namespace/name string and puts it onto the work queue.
func (*Impl) EnqueueKeyAfter ¶
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) GlobalResync ¶
func (c *Impl) GlobalResync(si cache.SharedInformer)
GlobalResync enqueues all objects from the passed SharedInformer
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 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, key, success string) 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