controllerlib

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ErrSyntheticRequeue = constErr("synthetic requeue request")

ErrSyntheticRequeue can be returned from a Syncer to force a retry artificially for the current key. This can also be done by re-adding the key to queue, but this is more convenient and has better logging.

Variables

This section is empty.

Functions

func TestRunSynchronously

func TestRunSynchronously(t *testing.T, controller Controller)

Just enough of the internal implementation of controller.Run() to allow "running" the controller without any goroutines being involved. For use in synchronous unit tests that wish to invoke TestSync() directly.

func TestSync

func TestSync(t *testing.T, controller Controller, ctx Context) error

func TestWrap

func TestWrap(t *testing.T, controller Controller, wrapper SyncWrapperFunc)

Types

type Config

type Config struct {
	Name   string
	Syncer Syncer
}

type Context

type Context struct {
	Context  context.Context
	Name     string
	Key      Key
	Queue    Queue
	Recorder events.EventRecorder
}

type Controller

type Controller interface {
	// Run runs the controller and blocks until the controller is finished.
	// Number of workers can be specified via workers parameter.
	// This function will return when all internal loops are finished.
	// Note that having more than one worker usually means handing parallelization of Sync().
	Run(ctx context.Context, workers int)

	// Name returns the controller name string.
	Name() string
	// contains filtered or unexported methods
}

Controller interface represents a runnable Kubernetes controller. Cancelling the context passed will cause the controller to shutdown. Number of workers determine how much parallel the job processing should be.

func New

func New(config Config, opts ...Option) Controller

type Filter

type Filter interface {
	Add(obj metav1.Object) bool
	Update(oldObj, newObj metav1.Object) bool
	Delete(obj metav1.Object) bool

	Parent(obj metav1.Object) Key
}

func FilterByNames

func FilterByNames(parentFunc ParentFunc, names ...string) Filter

type FilterFuncs

type FilterFuncs struct {
	ParentFunc ParentFunc
	AddFunc    func(obj metav1.Object) bool
	UpdateFunc func(oldObj, newObj metav1.Object) bool
	DeleteFunc func(obj metav1.Object) bool
}

func (FilterFuncs) Add

func (f FilterFuncs) Add(obj metav1.Object) bool

func (FilterFuncs) Delete

func (f FilterFuncs) Delete(obj metav1.Object) bool

func (FilterFuncs) Parent

func (f FilterFuncs) Parent(obj metav1.Object) Key

func (FilterFuncs) Update

func (f FilterFuncs) Update(oldObj, newObj metav1.Object) bool

type InformerGetter

type InformerGetter interface {
	Informer() cache.SharedIndexInformer
}

type InformerOption

type InformerOption struct {
	SkipSync   bool
	SkipEvents bool
}

type Key

type Key struct {
	Namespace string
	Name      string
}

type Manager

type Manager interface {
	Start(ctx context.Context)
	WithController(controller Controller, workers int) Manager
}

func NewManager

func NewManager() Manager

type Option

type Option func(*controller)

func WithInformer

func WithInformer(getter InformerGetter, filter Filter, opt InformerOption) Option

func WithInitialEvent

func WithInitialEvent(key Key) Option

func WithMaxRetries

func WithMaxRetries(maxRetries int) Option

func WithRateLimiter

func WithRateLimiter(limiter workqueue.RateLimiter) Option

func WithRecorder

func WithRecorder(recorder events.EventRecorder) Option

type ParentFunc

type ParentFunc func(obj metav1.Object) Key

type Queue

type Queue interface {
	// Add immediately adds a key to the queue and marks it as needing processing.
	Add(key Key)

	// AddRateLimited adds a key to the queue after the rate limiter says it is ok.
	AddRateLimited(key Key)

	// AddAfter adds a key to the queue after the indicated duration has passed.
	AddAfter(key Key, duration time.Duration)
}

type SyncFunc

type SyncFunc func(ctx Context) error

func (SyncFunc) Sync

func (s SyncFunc) Sync(ctx Context) error

type SyncWrapperFunc

type SyncWrapperFunc func(syncer Syncer) Syncer

type Syncer

type Syncer interface {
	Sync(ctx Context) error
}

Jump to

Keyboard shortcuts

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