Documentation ¶
Overview ¶
Package framework implements all the grunt work involved in running a simple controller.
Index ¶
- func DeletionHandlingMetaNamespaceKeyFunc(obj interface{}) (string, error)
- type Config
- type Controller
- type FakeControllerSource
- func (f *FakeControllerSource) Add(obj runtime.Object)
- func (f *FakeControllerSource) AddDropWatch(obj runtime.Object)
- func (f *FakeControllerSource) Change(e watch.Event, watchProbability float64)
- func (f *FakeControllerSource) Delete(lastValue runtime.Object)
- func (f *FakeControllerSource) DeleteDropWatch(lastValue runtime.Object)
- func (f *FakeControllerSource) List() (runtime.Object, error)
- func (f *FakeControllerSource) Modify(obj runtime.Object)
- func (f *FakeControllerSource) ModifyDropWatch(obj runtime.Object)
- func (f *FakeControllerSource) Watch(resourceVersion string) (watch.Interface, error)
- type ProcessFunc
- type ResourceEventHandler
- type ResourceEventHandlerFuncs
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeletionHandlingMetaNamespaceKeyFunc ¶
DeletionHandlingMetaNamespaceKeyFunc checks for cache.DeletedFinalStateUnknown objects before calling cache.MetaNamespaceKeyFunc.
Types ¶
type Config ¶
type Config struct { // The queue for your objects; either a cache.FIFO or // a cache.DeltaFIFO. Your Process() function should accept // the output of this Oueue's Pop() method. cache.Queue // Something that can list and watch your objects. cache.ListerWatcher // Something that can process your objects. Process ProcessFunc // The type of your objects. ObjectType runtime.Object // Reprocess everything at least this often. // Note that if it takes longer for you to clear the queue than this // period, you will end up processing items in the order determined // by cache.FIFO.Replace(). Currently, this is random. If this is a // problem, we can change that replacement policy to append new // things to the end of the queue instead of replacing the entire // queue. FullResyncPeriod time.Duration // If true, when Process() returns an error, re-enqueue the object. // TODO: add interface to let you inject a delay/backoff or drop // the object completely if desired. Pass the object in // question to this interface as a parameter. RetryOnError bool }
Config contains all the settings for a Controller.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is a generic controller framework.
func NewIndexerInformer ¶
func NewIndexerInformer( lw cache.ListerWatcher, objType runtime.Object, resyncPeriod time.Duration, h ResourceEventHandler, indexers cache.Indexers, ) (cache.Indexer, *Controller)
NewIndexerInformer returns a cache.Indexer and a controller for populating the index while also providing event notifications. You should only used the returned cache.Index for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty.
Parameters:
- lw is list and watch functions for the source of the resource you want to be informed of.
- objType is an object of the type that you expect to receive.
- resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller).
- h is the object you want notifications sent to.
func NewInformer ¶
func NewInformer( lw cache.ListerWatcher, objType runtime.Object, resyncPeriod time.Duration, h ResourceEventHandler, ) (cache.Store, *Controller)
NewInformer returns a cache.Store and a controller for populating the store while also providing event notifications. You should only used the returned cache.Store for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty.
Parameters:
- lw is list and watch functions for the source of the resource you want to be informed of.
- objType is an object of the type that you expect to receive.
- resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller).
- h is the object you want notifications sent to.
func (*Controller) HasSynced ¶
func (c *Controller) HasSynced() bool
Returns true once this controller has completed an initial resource listing
func (*Controller) Requeue ¶
func (c *Controller) Requeue(obj interface{}) error
Requeue adds the provided object back into the queue if it does not already exist.
func (*Controller) Run ¶
func (c *Controller) Run(stopCh <-chan struct{})
Run begins processing items, and will continue until a value is sent down stopCh. It's an error to call Run more than once. Run blocks; call via go.
type FakeControllerSource ¶
type FakeControllerSource struct {
// contains filtered or unexported fields
}
FakeControllerSource implements listing/watching for testing.
func NewFakeControllerSource ¶
func NewFakeControllerSource() *FakeControllerSource
func (*FakeControllerSource) Add ¶
func (f *FakeControllerSource) Add(obj runtime.Object)
Add adds an object to the set and sends an add event to watchers. obj's ResourceVersion is set.
func (*FakeControllerSource) AddDropWatch ¶
func (f *FakeControllerSource) AddDropWatch(obj runtime.Object)
AddDropWatch adds an object to the set but forgets to send an add event to watchers. obj's ResourceVersion is set.
func (*FakeControllerSource) Change ¶
func (f *FakeControllerSource) Change(e watch.Event, watchProbability float64)
Change records the given event (setting the object's resource version) and sends a watch event with the specified probability.
func (*FakeControllerSource) Delete ¶
func (f *FakeControllerSource) Delete(lastValue runtime.Object)
Delete deletes an object from the set and sends a delete event to watchers. obj's ResourceVersion is set.
func (*FakeControllerSource) DeleteDropWatch ¶
func (f *FakeControllerSource) DeleteDropWatch(lastValue runtime.Object)
DeleteDropWatch deletes an object from the set but forgets to send a delete event to watchers. obj's ResourceVersion is set.
func (*FakeControllerSource) List ¶
func (f *FakeControllerSource) List() (runtime.Object, error)
List returns a list object, with its resource version set.
func (*FakeControllerSource) Modify ¶
func (f *FakeControllerSource) Modify(obj runtime.Object)
Modify updates an object in the set and sends a modified event to watchers. obj's ResourceVersion is set.
func (*FakeControllerSource) ModifyDropWatch ¶
func (f *FakeControllerSource) ModifyDropWatch(obj runtime.Object)
ModifyDropWatch updates an object in the set but forgets to send a modify event to watchers. obj's ResourceVersion is set.
type ProcessFunc ¶
type ProcessFunc func(obj interface{}) error
ProcessFunc processes a single object.
type ResourceEventHandler ¶
type ResourceEventHandler interface { OnAdd(obj interface{}) OnUpdate(oldObj, newObj interface{}) OnDelete(obj interface{}) }
ResourceEventHandler can handle notifications for events that happen to a resource. The events are informational only, so you can't return an error.
- OnAdd is called when an object is added.
- OnUpdate is called when an object is modified. Note that oldObj is the last known state of the object-- it is possible that several changes were combined together, so you can't use this to see every single change. OnUpdate is also called when a re-list happens, and it will get called even if nothing changed. This is useful for periodically evaluating or syncing something.
- OnDelete will get the final state of the item if it is known, otherwise it will get an object of type cache.DeletedFinalStateUnknown. This can happen if the watch is closed and misses the delete event and we don't notice the deletion until the subsequent re-list.
type ResourceEventHandlerFuncs ¶
type ResourceEventHandlerFuncs struct { AddFunc func(obj interface{}) UpdateFunc func(oldObj, newObj interface{}) DeleteFunc func(obj interface{}) }
ResourceEventHandlerFuncs is an adaptor to let you easily specify as many or as few of the notification functions as you want while still implementing ResourceEventHandler.
func (ResourceEventHandlerFuncs) OnAdd ¶
func (r ResourceEventHandlerFuncs) OnAdd(obj interface{})
OnAdd calls AddFunc if it's not nil.
func (ResourceEventHandlerFuncs) OnDelete ¶
func (r ResourceEventHandlerFuncs) OnDelete(obj interface{})
OnDelete calls DeleteFunc if it's not nil.
func (ResourceEventHandlerFuncs) OnUpdate ¶
func (r ResourceEventHandlerFuncs) OnUpdate(oldObj, newObj interface{})
OnUpdate calls UpdateFunc if it's not nil.