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 DeviceResolver
- type Filter
- type LeadershipActivator
- type MastershipFilter
- type PartitionKey
- type Reconciler
- type RegexpDeviceResolver
- 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 DeviceResolver ¶
type DeviceResolver interface { // Resolve resolves a device Resolve(id types.ID) (topodevice.ID, error) }
DeviceResolver resolves a device from a type ID
type Filter ¶
type Filter interface { // Accept indicates whether to accept the given object Accept(id types.ID) bool }
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 LeadershipActivator ¶
type LeadershipActivator struct { Store leadershipstore.Store // contains filtered or unexported fields }
LeadershipActivator is an Activator for activating a controller on leadership The LeadershipActivator listens for leadership changes in the leadership store. When the local node becomes the leader, the controller is activated. If the local node loses leadership, the controller is deactivated. This can ensure only a single controller processes requests in a cluster.
func (*LeadershipActivator) Start ¶
func (a *LeadershipActivator) Start(ch chan<- bool) error
Start starts the activator
type MastershipFilter ¶
type MastershipFilter struct { Store mastershipstore.Store Resolver DeviceResolver // contains filtered or unexported fields }
MastershipFilter activates a controller on acquiring mastership The MastershipFilter requires a DeviceResolver to extract a device ID from each request. Given a device ID, the MastershipFilter rejects any requests for which the local node is not the master for the device.
type Reconciler ¶
type Reconciler interface { // Reconcile is called to reconcile the state of an object Reconcile(types.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 RegexpDeviceResolver ¶
RegexpDeviceResolver is a DeviceResolver that reads a device ID from a regexp
func (*RegexpDeviceResolver) Resolve ¶
func (r *RegexpDeviceResolver) Resolve(id types.ID) (topodevice.ID, error)
Resolve resolves a device ID from the configured regexp
type RegexpPartitioner ¶
RegexpPartitioner is a WorkPartitioner that assigns work to a gouroutine per regex output
func (*RegexpPartitioner) Partition ¶
func (p *RegexpPartitioner) Partition(id types.ID) (PartitionKey, error)
Partition returns a PartitionKey from the configured regex
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 types.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<- types.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 types.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.