controller

package
v0.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2021 License: Apache-2.0 Imports: 6 Imported by: 34

Documentation

Index

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) Start

func (c *Controller) Start() error

Start starts the request controller

func (*Controller) Stop

func (c *Controller) Stop()

Stop stops the controller

func (*Controller) Watch

func (c *Controller) Watch(watcher Watcher) *Controller

Watch adds a watcher to the controller

type Filter

type Filter interface {
	// Accept indicates whether to accept the given object
	Accept(id 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 ID

type ID struct {
	// Value is the raw identifier
	Value interface{}
}

ID is an object identifier

func NewID

func NewID(value interface{}) ID

NewID creates a new object identifier

func (ID) Int

func (i ID) Int() int

Int returns the identifier as an integer

func (ID) Int32

func (i ID) Int32() int32

Int32 returns the identifier as an integer

func (ID) Int64

func (i ID) Int64() int64

Int64 returns the identifier as an integer

func (ID) String

func (i ID) String() string

String returns the identifier as a string

func (ID) Uint

func (i ID) Uint() uint

Uint returns the identifier as an integer

func (ID) Uint32

func (i ID) Uint32() uint32

Uint32 returns the identifier as an integer

func (ID) Uint64

func (i ID) Uint64() uint64

Uint64 returns the identifier as an integer

type PartitionKey

type PartitionKey string

PartitionKey is a key by which to partition requests

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

type RegexpPartitioner struct {
	Regexp regexp.Regexp
}

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 Request added in v0.7.6

type Request struct {
	ID ID
	// contains filtered or unexported fields
}

Request is a reconciler request

type Result

type Result struct {
	// Requeue is the identifier of an event to requeue
	Requeue      ID
	RequeueAt    time.Time
	RequeueAfter time.Duration
}

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 {
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL