Documentation ¶
Index ¶
Constants ¶
const ( // SuccessSynced is used as part of the Event 'reason' when an object is synced SuccessSynced = "Synced" // MessageResourceSynced is the message used for an Event fired when an object // is synced successfully MessageResourceSynced = "%s synced successfully" )
Variables ¶
This section is empty.
Functions ¶
func EventfulError ¶
EventfulError wraps the given error and attaches an Event to it
Types ¶
type ControllerHandler ¶
type ControllerHandler interface { // AgentName returns a unique name for the controller. AgentName() string // Sync is called whenever a CRD object needs to be synced. // // The key of the object will be passed as argument. If something goes wrong during // the sync, an error needs to be returned. If that error is caused by a transient // cause (e.g. temporary network failure), make sure you return a TransientError, so // the same object will be retried without waiting for a change. // The bool return value specifies whether changes happened to reconcile the state. // If so, an event will be emitted. Sync(object runtime.Object) (bool, error) // CustomResourceKind returns the kind of the controlled resource, as it is specified // by the CRD manifest. CustomResourceKind() string // CustomResourceInstance returns the instance of the CustomResourceDefinition with // the given key (namespace, name). CustomResourceInstance(namespace, name string) (runtime.Object, error) // NeedPeriodicSync states whether a periodic Sync is needed for the CRDs even if // they didn't change NeedPeriodicSync() bool // OnControlledObjectUpdate is called whenever an object that could be controlled // by a custom resource is updated. // // If the objects points to a custom resource that you want to handle, you can // return it. It is going to be put in the work queue. // The owner reference is checked by default and you don't need to implement this // method if you need only that discovery method. OnControlledObjectUpdate(object interface{}) (interface{}, error) }
ControllerHandler provides the hooks necessary to the ControllerKit, in order to implement a fully functional controller.
type ControllerKit ¶
type ControllerKit interface { sharedctr.Controller // EventRecorder returns the event recorded that can be used to // record events on the controlled objects. EventRecorder() record.EventRecorder }
ControllerKit abstracts away some of the boring details from a controller implementation.
It allows to control one type of CustomResourceDefinition and trigger the synchronization after a change on a resource, a controlled resource, or periodically.
func NewController ¶
func NewController( handler ControllerHandler, kubeclientset kubernetes.Interface, crdInformer cache.SharedInformer, controlledObjectsInformers []cache.SharedInformer, ) ControllerKit
NewController creates a new controller for a single CustomResourceDefinition.
The given arguments determine how and on what the controller should operate. The handler provides the hooks that will be called at the right time, during the control loop. The kubeclientset needs to be a valid connection to Kubernetes. The crdInformer is a shared informer for the CustomResourceDefinition that this controller should manage. The controlledObjectsInformers list is a list of informers for objects that can be owned by the CRD. Whenever these objects are owned by the given CRD and they change, they will trigger a Sync for the owner CRD.