Documentation ¶
Index ¶
- type Activator
- type Controller
- func (c *Controller) Activate(activator Activator) *Controller
- func (c *Controller) Filter(filter Filter) *Controller
- func (c *Controller) Partition(partitioner WorkPartitioner) *Controller
- func (c *Controller) Reconcile(reconciler Reconciler) *Controller
- func (c *Controller) Start() error
- func (c *Controller) Stop()
- func (c *Controller) Watch(watcher Watcher) *Controller
- type Filter
- type ID
- type PartitionKey
- type Reconciler
- type RegexpPartitioner
- type Result
- type UnaryPartitioner
- type UnconditionalActivator
- type Watcher
- type WorkPartitioner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Activator ¶
type Activator interface { // Start starts the activator Start(ch chan<- bool) error // Stop stops the activator Stop() }
Activator is an interface for controlling the activation of a controller Once the Activator is Started, it may activate or deactivate processing of Watcher events on the node at any time by writing true or false to the activator channel respectively.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is a control loop The Controller is responsible for processing events provided by a Watcher. Events are processed by a configurable Reconciler. The controller processes events in a loop, retrying requests until the Reconciler can successfully process them. The Controller can be activated or deactivated by a configurable Activator. When inactive, the controller will ignore requests, and when active it processes all requests. For per-request filtering, a Filter can be provided which provides a simple bool to indicate whether a request should be passed to the Reconciler. Once the Reconciler receives a request, it should process the request using the current state of the cluster Reconcilers should not cache state themselves and should instead rely on stores for consistency. If a Reconciler returns false, the request will be requeued to be retried after all pending requests. If a Reconciler returns an error, the request will be retried after a backoff period. Once a Reconciler successfully processes a request by returning true, the request will be discarded. Requests can be partitioned among concurrent goroutines by configuring a WorkPartitioner. The controller will create a goroutine per PartitionKey provided by the WorkPartitioner, and requests to different partitions may be handled concurrently.
func NewController ¶
func NewController(name string) *Controller
NewController creates a new controller
func (*Controller) Activate ¶
func (c *Controller) Activate(activator Activator) *Controller
Activate sets an activator for the controller
func (*Controller) Filter ¶
func (c *Controller) Filter(filter Filter) *Controller
Filter sets a filter for the controller
func (*Controller) Partition ¶
func (c *Controller) Partition(partitioner WorkPartitioner) *Controller
Partition partitions work among multiple goroutines for the controller
func (*Controller) Reconcile ¶
func (c *Controller) Reconcile(reconciler Reconciler) *Controller
Reconcile sets the reconciler for the controller
func (*Controller) Watch ¶
func (c *Controller) Watch(watcher Watcher) *Controller
Watch adds a watcher to the controller
type Filter ¶
Filter filters individual events for a node Each time an event is received from a watcher, the filter has the option to discard the request by returning false.
type ID ¶
type ID struct {
// Value is the raw identifier
Value interface{}
}
ID is an object identifier
type Reconciler ¶
type Reconciler interface { // Reconcile is called to reconcile the state of an object Reconcile(ID) (Result, error) }
Reconciler reconciles objects The reconciler will be called for each type ID received from the Watcher. The reconciler may indicate whether to retry requests by returning either false or a non-nil error. Reconcilers should make no assumptions regarding the ordering of requests and should use the provided type IDs to resolve types against the current state of the cluster.
type RegexpPartitioner ¶
RegexpPartitioner is a WorkPartitioner that assigns work to a gouroutine per regex output
func (*RegexpPartitioner) Partition ¶
func (p *RegexpPartitioner) Partition(id ID) (PartitionKey, error)
Partition returns a PartitionKey from the configured regex
type Result ¶
type Result struct { // Requeue is the identifier of an event to requeue Requeue ID }
Result is a reconciler result
type UnaryPartitioner ¶
type UnaryPartitioner struct { }
UnaryPartitioner is a WorkPartitioner that assigns all work to a single goroutine
func (*UnaryPartitioner) Partition ¶
func (p *UnaryPartitioner) Partition(id ID) (PartitionKey, error)
Partition returns a static partition key
type UnconditionalActivator ¶
type UnconditionalActivator struct { }
UnconditionalActivator activates controllers on all nodes at all times
func (*UnconditionalActivator) Start ¶
func (a *UnconditionalActivator) Start(ch chan<- bool) error
Start starts the activator
func (*UnconditionalActivator) Stop ¶
func (a *UnconditionalActivator) Stop()
Stop stops the activator
type Watcher ¶
type Watcher interface { // Start starts watching for events Start(ch chan<- ID) error // Stop stops watching for events Stop() }
Watcher is implemented by controllers to implement watching for specific events Type identifiers that are written to the watcher channel will eventually be processed by the controller.
type WorkPartitioner ¶
type WorkPartitioner interface { // Partition gets a partition key for the given request Partition(id ID) (PartitionKey, error) }
WorkPartitioner is an interface for partitioning requests among a set of goroutines The WorkPartitioner can enable safe concurrency inside controllers. For each request, the partitioner will be called to provide a PartitionKey for the request. For each unique PartitionKey, a separate channel and goroutine will be created to process requests for the partition.