informer

package
v0.0.0-...-32caa19 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoListFunc = errors.New("no list func defined")
View Source
var ErrNoWatchFunc = errors.New("no watch func defined")
View Source
var ErrNotRunning = errors.New("informer is not running")
View Source
var ErrRunning = errors.New("informer is running")

Functions

This section is empty.

Types

type AddHandler

type AddHandler[Res runtime.Object] func(obj Res)

type DeleteHandler

type DeleteHandler[Res runtime.Object] func(obj Res)

type Informer

type Informer[T runtime.Object] struct {
	// contains filtered or unexported fields
}

Informer is a generic informer, suitable for all Kubernetes types.

T specifies the type of the resource this informer should handle.

The informer must be supplied with at least a lister and a watcher function.

func NewInformer

func NewInformer[T runtime.Object](ctx context.Context, opts ...InformerOption[T]) (*Informer[T], error)

NewInformer instantiates a new informer for resource type T.

You must supply at least a list and a watch function using WithLisHandler and WithWatchHandler.

Resource callbacks can be provided at the time of instantiation using WithAddHandler, WithUpdateHandler and WithDeleteHandler options.

func (*Informer[T]) HasSynced

func (i *Informer[T]) HasSynced() bool

HasSynced returns true if the informer is synced

func (*Informer[T]) Start

func (i *Informer[T]) Start(ctx context.Context) error

Start starts the informer until the informer's control channel is closed. Note that this method will block, so it should be executed in a dedicated go routine.

func (*Informer[T]) Stop

func (i *Informer[T]) Stop() error

Stop stops the running informer

func (*Informer[T]) WaitForSync

func (i *Informer[T]) WaitForSync(ctx context.Context) error

WaitForSync blocks until either the informer has synced, or the context ctx is done. If the informer has synced, returns nil. Otherwise, the reason why the context was aborted is returned.

type InformerInterface

type InformerInterface interface {
	Start(ctx context.Context) error
	Stop() error
	HasSynced() bool
	WaitForSync(ctx context.Context) error
}

InformerInterface defines the interface for the informer

type InformerOption

type InformerOption[T runtime.Object] func(i *Informer[T]) error

func WithAddHandler

func WithAddHandler[T runtime.Object](f AddHandler[T]) InformerOption[T]

WithAddHandler sets the callback to be executed when a resource is added

func WithDeleteHandler

func WithDeleteHandler[T runtime.Object](f DeleteHandler[T]) InformerOption[T]

WithDeleteHandler sets the callback to be executed when a resource is deleted

func WithFilters

func WithFilters[T runtime.Object](fc *filter.Chain[T]) InformerOption[T]

WithFilters sets the filter chain used by the informer to decide whether to admit specific resources. The filter chain must be for the same resource type T as the informer.

func WithListHandler

func WithListHandler[T runtime.Object](f ListFunc) InformerOption[T]

WithListHandler sets the list function for the watcher

func WithMetrics

func WithMetrics[T runtime.Object](registry *prometheus.Registry, metrics *metrics.InformerMetrics) InformerOption[T]

WithMetrics sets the informer metrics to be used by this informer

func WithNamespaceScope

func WithNamespaceScope[T runtime.Object](namespace string) InformerOption[T]

WithNamespaceScope sets the scope of the informer to namespace. If namespace is the empty string, the informer will be cluster scoped (Which is also the default)

func WithResyncPeriod

func WithResyncPeriod[T runtime.Object](d time.Duration) InformerOption[T]

WithResyncPeriod sets the resync period for the informer to d

func WithUpdateHandler

func WithUpdateHandler[T runtime.Object](f UpdateHandler[T]) InformerOption[T]

WithUpdateHandler sets the callback to be executed when a resource is updated

func WithWatchHandler

func WithWatchHandler[T runtime.Object](f WatchFunc) InformerOption[T]

WithWatchHandler sets the watch function for the watcher

type ListFunc

type ListFunc func(ctx context.Context, opts v1.ListOptions) (runtime.Object, error)

type UpdateHandler

type UpdateHandler[Res runtime.Object] func(old Res, new Res)

type WatchFunc

type WatchFunc func(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)

Jump to

Keyboard shortcuts

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