libctrl

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const ConditionTypePaused = "Paused"

Variables

View Source
var FileGroupVersion = schema.GroupVersion{
	Group:   "//LocalFile",
	Version: "v1",
}

Functions

func Chain

func Chain(children ...handler.Builder) handler.Builder

Chain chains a set of HandleBuilder together

func HashEqual

func HashEqual(a, b string) bool

func HashObject

func HashObject(obj interface{}) (string, error)

func IsPaused

func IsPaused(object metav1.Object, pausedLabelKey string) bool

func NewPausedCondition

func NewPausedCondition(pausedLabelKey string) metav1.Condition

func NewSelfPausedCondition

func NewSelfPausedCondition(pausedLabelKey string) metav1.Condition

func Parallel

func Parallel(children ...handler.Builder) handler.Builder

Parallel creates a new handler.Builder that runs a set of handler.Builder in parallel

func SecureHashEqual

func SecureHashEqual(a, b string) bool

func SecureHashObject

func SecureHashObject(obj interface{}) (string, error)

func ShouldRetry

func ShouldRetry(err error) (bool, time.Duration)

ShouldRetry returns true if the error is transient. It returns a delay if the server suggested one.

Types

type Annotator

type Annotator[T any] interface {
	WithAnnotations(entries map[string]string) T
}

type BuilderComposer

type BuilderComposer func(builder ...handler.Builder) handler.Builder

BuilderComposer is a function that composes sets of handler.Builder into one handler.Builder, see `Chain` and `Parallel`.

func ChainWithMiddleware

func ChainWithMiddleware(middleware ...Middleware) BuilderComposer

func ParallelWithMiddleware

func ParallelWithMiddleware(middleware ...Middleware) BuilderComposer

func WithMiddleware

func WithMiddleware(composer BuilderComposer, middleware ...Middleware) BuilderComposer

WithMiddleware returns a new BuilderComposer with all middleware applied

type BuilderMiddleware

type BuilderMiddleware func(handler.Builder) handler.Builder

BuilderMiddleware returns a new (wrapped) Builder given a Builder

func MakeBuilderMiddleware

func MakeBuilderMiddleware(w HandlerMiddleware) BuilderMiddleware

MakeBuilderMiddleware generates the corresponding BuilderMiddleware from a HandlerMiddleware.

type Component

type Component[K metav1.Object] struct {
	// contains filtered or unexported fields
}

Component represents an object in the cluster that is "related" to another i.e. a pod would be a component of a deployment (though direct ownership is not required).

func NewComponent

NewComponent creates a component from an index name, a gvr, a selector, and a set of informers.

func (*Component[K]) List

func (c *Component[K]) List(indexValue fmt.Stringer) (out []K)

List all objects that match the component's specification. Components are expected to be unique (per label), but List returns a slice so that controllers can handle duplicates appropriately.

type ComponentContextHandler

type ComponentContextHandler[K metav1.Object] struct {
	HandlerControls
	// contains filtered or unexported fields
}

ComponentContextHandler fills the value for a ContextKey with the result of fetching a component.

func NewComponentContextHandler

func NewComponentContextHandler[K metav1.Object](ctrls HandlerControls, contextKey SettableContext[[]K], component *Component[K], owner fmt.Stringer, next handler.ContextHandler) *ComponentContextHandler[K]

func (*ComponentContextHandler[K]) Handle

func (h *ComponentContextHandler[K]) Handle(ctx context.Context)

type ContextDefaultingKey

type ContextDefaultingKey[V comparable] struct {
	// contains filtered or unexported fields
}

ContextDefaultingKey is a type that is used as a key in a context.Context for a specific type of value, but returns the default value for V if unset.

func NewContextDefaultingKey

func NewContextDefaultingKey[V comparable](defaultValue V) *ContextDefaultingKey[V]

func (*ContextDefaultingKey[V]) MustValue

func (k *ContextDefaultingKey[V]) MustValue(ctx context.Context) V

func (*ContextDefaultingKey[V]) Value

func (k *ContextDefaultingKey[V]) Value(ctx context.Context) V

func (*ContextDefaultingKey[V]) WithValue

func (k *ContextDefaultingKey[V]) WithValue(ctx context.Context, val V) context.Context

type ContextHandle

type ContextHandle[V any] struct {
	// contains filtered or unexported fields
}

type ContextHandleDefaultingKey

type ContextHandleDefaultingKey[V any] struct {
	// contains filtered or unexported fields
}

ContextHandleDefaultingKey is a type that is used as a key in a context.Context that points to a handle containing the desired value. This allows a handler higher up in the chain to carve out a spot to be filled in by other handlers. It can also be used to hold non-comparable objects by wrapping them with a pointer.

func NewContextHandleDefaultingKey

func NewContextHandleDefaultingKey[V any](defaultValue V) *ContextHandleDefaultingKey[V]

func (*ContextHandleDefaultingKey[V]) HandleBuilder

func (k *ContextHandleDefaultingKey[V]) HandleBuilder(id handler.Key) handler.Builder

HandleBuilder returns a HandleBuilder that calls WithHandle before calling the next handler in the chain.

func (*ContextHandleDefaultingKey[V]) MustValue

func (k *ContextHandleDefaultingKey[V]) MustValue(ctx context.Context) V

func (*ContextHandleDefaultingKey[V]) Value

func (k *ContextHandleDefaultingKey[V]) Value(ctx context.Context) V

func (*ContextHandleDefaultingKey[V]) WithHandle

func (*ContextHandleDefaultingKey[V]) WithValue

func (k *ContextHandleDefaultingKey[V]) WithValue(ctx context.Context, val V) context.Context

type ContextKey

type ContextKey[V comparable] struct{}

ContextKey is a type that is used as a key in a context.Context for a specific type of value V. It mimics the context.Context interface

func NewContextKey

func NewContextKey[V comparable]() *ContextKey[V]

func (*ContextKey[V]) MustValue

func (k *ContextKey[V]) MustValue(ctx context.Context) V

func (*ContextKey[V]) Value

func (k *ContextKey[V]) Value(ctx context.Context) (V, bool)

func (*ContextKey[V]) WithValue

func (k *ContextKey[V]) WithValue(ctx context.Context, val V) context.Context

type ControlDone

type ControlDone interface {
	Done()
}

type ControlDoneRequeue

type ControlDoneRequeue interface {
	ControlDone
	ControlRequeue
}

type ControlDoneRequeueAfter

type ControlDoneRequeueAfter interface {
	ControlDone
	ControlRequeueAfter
}

type ControlDoneRequeueErr

type ControlDoneRequeueErr interface {
	ControlDone
	ControlRequeueErr
}

type ControlOpt

type ControlOpt func(*HandlerControls)

func WithDone

func WithDone(doneFunc func()) ControlOpt

func WithRequeue

func WithRequeue(requeueFunc func()) ControlOpt

func WithRequeueAfter

func WithRequeueAfter(requeueAfterFunc func(duration time.Duration)) ControlOpt

func WithRequeueImmediate

func WithRequeueImmediate(requeueFunc func(duration time.Duration)) ControlOpt

type ControlRequeue

type ControlRequeue interface {
	Requeue()
}

type ControlRequeueAPIErr

type ControlRequeueAPIErr interface {
	ControlDone
	ControlRequeue
	ControlRequeueAfter
	RequeueAPIErr(err error)
}

type ControlRequeueAfter

type ControlRequeueAfter interface {
	RequeueAfter(duration time.Duration)
}

type ControlRequeueErr

type ControlRequeueErr interface {
	ControlRequeue
	RequeueErr(err error)
}

type EnsureComponentByHash

type EnsureComponentByHash[K metav1.Object, A Annotator[A]] struct {
	ControlRequeueErr
	*HashableComponent[K]
	// contains filtered or unexported fields
}

func NewEnsureComponentByHash

func NewEnsureComponentByHash[K metav1.Object, A Annotator[A]](
	component *HashableComponent[K],
	owner types.NamespacedName,
	ctrls ControlRequeueErr,
	applyObj func(ctx context.Context, apply A) (K, error),
	deleteObject func(ctx context.Context, name string) error,
	newObj func(ctx context.Context) A,
) *EnsureComponentByHash[K, A]

func (*EnsureComponentByHash[K, A]) Handle

func (e *EnsureComponentByHash[K, A]) Handle(ctx context.Context)

type FileInformer

type FileInformer struct {
	// contains filtered or unexported fields
}

func NewFileInformer

func NewFileInformer(watcher *fsnotify.Watcher, gvr schema.GroupVersionResource) (*FileInformer, error)

func (*FileInformer) Informer

func (f *FileInformer) Informer() cache.SharedIndexInformer

func (*FileInformer) Lister

func (f *FileInformer) Lister() cache.GenericLister

type FileInformerFactory

type FileInformerFactory struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewFileInformerFactory

func NewFileInformerFactory() (*FileInformerFactory, error)

func (*FileInformerFactory) ForResource

func (*FileInformerFactory) Start

func (f *FileInformerFactory) Start(stopCh <-chan struct{})

func (*FileInformerFactory) WaitForCacheSync

func (f *FileInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[schema.GroupVersionResource]bool

type FileSharedIndexInformer

type FileSharedIndexInformer struct {
	sync.Once
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewFileSharedIndexInformer

func NewFileSharedIndexInformer(fileName string, watcher *fsnotify.Watcher, defaultEventHandlerResyncPeriod time.Duration) *FileSharedIndexInformer

NewFileSharedIndexInformer creates a new informer watching the file Note that currently all event handlers share the default resync period.

func (*FileSharedIndexInformer) AddEventHandler

func (f *FileSharedIndexInformer) AddEventHandler(handler cache.ResourceEventHandler)

func (*FileSharedIndexInformer) AddEventHandlerWithResyncPeriod

func (f *FileSharedIndexInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration)

func (*FileSharedIndexInformer) AddIndexers

func (f *FileSharedIndexInformer) AddIndexers(indexers cache.Indexers) error

func (*FileSharedIndexInformer) GetController

func (f *FileSharedIndexInformer) GetController() cache.Controller

func (*FileSharedIndexInformer) GetIndexer

func (f *FileSharedIndexInformer) GetIndexer() cache.Indexer

func (*FileSharedIndexInformer) GetStore

func (f *FileSharedIndexInformer) GetStore() cache.Store

func (*FileSharedIndexInformer) HasSynced

func (f *FileSharedIndexInformer) HasSynced() bool

func (*FileSharedIndexInformer) LastSyncResourceVersion

func (f *FileSharedIndexInformer) LastSyncResourceVersion() string

func (*FileSharedIndexInformer) Run

func (f *FileSharedIndexInformer) Run(stopCh <-chan struct{})

func (*FileSharedIndexInformer) SetWatchErrorHandler

func (f *FileSharedIndexInformer) SetWatchErrorHandler(handler cache.WatchErrorHandler) error

type HandlerControls

type HandlerControls struct {
	// contains filtered or unexported fields
}

func HandlerControlsWith

func HandlerControlsWith(opts ...ControlOpt) HandlerControls

func (HandlerControls) Done

func (c HandlerControls) Done()

func (HandlerControls) Requeue

func (c HandlerControls) Requeue()

func (HandlerControls) RequeueAPIErr

func (c HandlerControls) RequeueAPIErr(err error)

func (HandlerControls) RequeueAfter

func (c HandlerControls) RequeueAfter(duration time.Duration)

func (HandlerControls) RequeueErr

func (c HandlerControls) RequeueErr(err error)

type HandlerMiddleware

type HandlerMiddleware func(handler.Handler) handler.Handler

HandlerMiddleware returns a new (wrapped) Handler given a Handler

type HasStatusConditions

type HasStatusConditions interface {
	comparable
	metav1.Object
	FindStatusCondition(conditionType string) *metav1.Condition
	SetStatusCondition(metav1.Condition)
	GetStatusConditions() []metav1.Condition
}

HasStatusConditions is used for pausing

type HashEqualFunc

type HashEqualFunc func(a, b string) bool

type HashableComponent

type HashableComponent[K metav1.Object] struct {
	Component[K]
	ObjectHasher
	HashAnnotationKey string
}

HashableComponent is a Component with an annotation that stores a hash of the previous configuration the controller wrote

func NewHashableComponent

func NewHashableComponent[K metav1.Object](component Component[K], hasher ObjectHasher, key string) *HashableComponent[K]

type Middleware

type Middleware func(BuilderComposer) BuilderComposer

Middleware operates on BuilderComposer (to wrap all underlying builders)

func MakeMiddleware

func MakeMiddleware(w HandlerMiddleware) Middleware

MakeMiddleware generates the corresponding Middleware for HandlerMiddleware

type ObjectHashFunc

type ObjectHashFunc func(obj any) (string, error)

type ObjectHasher

type ObjectHasher interface {
	Hash(obj any) (string, error)
	Equal(a, b string) bool
}

func NewObjectHash

func NewObjectHash() ObjectHasher

func NewSecureObjectHash

func NewSecureObjectHash() ObjectHasher

type PauseHandler

type PauseHandler[K HasStatusConditions] struct {
	ControlDoneRequeueErr
	PausedLabelKey string
	Object         K
	PatchStatus    func(ctx context.Context, patch K) error
	Next           handler.ContextHandler
}

func NewPauseHandler

func NewPauseHandler[K HasStatusConditions](ctrls ControlDoneRequeueErr,
	pausedLabelKey string,
	object K,
	patchStatus func(ctx context.Context, patch K) error,
	next handler.ContextHandler,
) *PauseHandler[K]

func (*PauseHandler[K]) Handle

func (p *PauseHandler[K]) Handle(ctx context.Context)

type SelfPauseHandler

type SelfPauseHandler[K HasStatusConditions] struct {
	HandlerControls
	CtxKey         *ContextDefaultingKey[K]
	PausedLabelKey string
	OwnerUID       types.UID
	Patch          func(ctx context.Context, patch K) error
	PatchStatus    func(ctx context.Context, patch K) error
}

SelfPauseHandler is used when the controller pauses itself. This is only used when the controller has no good way to tell when the bad state has been resolved (i.e. an external resource is behaving poorly).

func NewSelfPauseHandler

func NewSelfPauseHandler[K HasStatusConditions](ctrls HandlerControls,
	pausedLabelKey string,
	contextKey *ContextDefaultingKey[K],
	ownerUID types.UID,
	patch, patchStatus func(ctx context.Context, patch K) error,
) *SelfPauseHandler[K]

func (*SelfPauseHandler[K]) Handle

func (p *SelfPauseHandler[K]) Handle(ctx context.Context)

type SettableContext

type SettableContext[V any] interface {
	WithValue(ctx context.Context, val V) context.Context
}

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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