controller

package
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnexpectedBehavior indicates the current situation is not expected.
	// There should be something wrong with the system and cannot be recovered by itself.
	ErrUnexpectedBehavior = errors.New("unexpected behavior which cannot be handled by the controller")

	// ErrExpectedBehavior indicates the current situation is expected, which can be recovered by itself after retries.
	ErrExpectedBehavior = errors.New("expected behavior which can be recovered by itself")

	// ErrAPIServerError indicates the error is returned by the API server.
	ErrAPIServerError = errors.New("error returned by the API server")

	// ErrUserError indicates the error is caused by the user and customer needs to take the action.
	ErrUserError = errors.New("failed to process the request due to a client error")
)

Functions

func NewAPIServerError added in v0.6.4

func NewAPIServerError(fromCache bool, err error) error

NewAPIServerError returns error types when accessing data from cache or API server.

func NewCreateIgnoreAlreadyExistError added in v0.6.5

func NewCreateIgnoreAlreadyExistError(err error) error

NewCreateIgnoreAlreadyExistError returns ErrExpectedBehavior type error if the error is already exist. Otherwise, returns ErrAPIServerError type error.

func NewExpectedBehaviorError added in v0.6.4

func NewExpectedBehaviorError(err error) error

NewExpectedBehaviorError returns ErrExpectedBehavior type error when err is not nil.

func NewUnexpectedBehaviorError added in v0.6.4

func NewUnexpectedBehaviorError(err error) error

NewUnexpectedBehaviorError returns ErrUnexpectedBehavior type error when err is not nil.

func NewUpdateIgnoreConflictError added in v0.6.5

func NewUpdateIgnoreConflictError(err error) error

NewUpdateIgnoreConflictError returns ErrExpectedBehavior type error if the error is conflict. Otherwise, returns ErrAPIServerError type error.

func NewUserError added in v0.6.4

func NewUserError(err error) error

NewUserError returns ErrUserError type error when err is not nil.

Types

type Controller

type Controller interface {
	// Enqueue generates the key of 'obj' according to a 'KeyFunc' then adds the 'item' to queue immediately.
	Enqueue(obj interface{})

	// Run starts a certain number of concurrent workers to reconcile the items and will never stop until
	// the context is closed or canceled
	Run(ctx context.Context, workerNumber int) error
}

Controller maintains a rate limiting queue and the items in the queue will be reconciled by a "ReconcileFunc". The item will be re-queued if "ReconcileFunc" returns an error, maximum re-queue times defined by "maxRetries" above, after that the item will be discarded from the queue.

func NewController

func NewController(Name string, KeyFunc KeyFunc, ReconcileFunc ReconcileFunc, rateLimiter workqueue.RateLimiter) Controller

NewController returns a controller which can process resource periodically. We create the queue during the creation of the controller which means it can only be run once. We can move that to the run if we need to run it multiple times

type KeyFunc

type KeyFunc func(obj interface{}) (QueueKey, error)

KeyFunc knows how to make a key from an object. Implementations should be deterministic.

type QueueKey

type QueueKey interface{}

QueueKey is the type of the item key that stores in queue. The key could be arbitrary types.

The most common full-qualified key is of type '<namespace>/<name>' which doesn't carry the `GVK` info of the resource the key points to. We need to support a key type that includes GVK(Group Version Kind) so that we can reconcile on any type of resources.

func ClusterWideKeyFunc

func ClusterWideKeyFunc(obj interface{}) (QueueKey, error)

ClusterWideKeyFunc generates a ClusterWideKey for object.

func NamespaceKeyFunc

func NamespaceKeyFunc(obj interface{}) (QueueKey, error)

NamespaceKeyFunc generates a namespaced key for any objects.

type ReconcileFunc

type ReconcileFunc func(ctx context.Context, key QueueKey) (reconcile.Result, error)

ReconcileFunc knows how to consume items(key) from the queue.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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