informer

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package informer provides a generic mechanism for listening for changes to resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event[T runtime.Object] struct {
	// Type is Added, Modified, Deleted, or Sync.
	Type EventType

	// Object is:
	//  * If Type is Added, Modified or Sync: the new state of the object.
	//  * If Type is Deleted: the state of the object immediately before deletion.
	Object T
}

Event represents a single event to a watched resource.

type EventType

type EventType string

EventType defines the possible types of events.

const (
	Added    EventType = "ADDED"
	Modified EventType = "MODIFIED"
	Deleted  EventType = "DELETED"
	Sync     EventType = "SYNC"
)

Event types.

type Getter

type Getter[T runtime.Object] interface {
	Get(name string) (T, bool)
	GetWithNamespace(name, namespace string) (T, bool)
	List() []T
}

Getter is a wrapper around a cache.Store that provides Get and List methods.

type Informer

type Informer[T runtime.Object, L runtime.Object] struct {
	ListFunc  func(ctx context.Context, opts metav1.ListOptions) (L, error)
	WatchFunc func(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}

Informer is a wrapper around a Get/List/Watch function.

func NewInformer

func NewInformer[T runtime.Object, L runtime.Object](lw Watcher[T, L]) *Informer[T, L]

NewInformer returns a new Informer.

func (*Informer[T, L]) Sync

func (i *Informer[T, L]) Sync(ctx context.Context, opt Option, events chan<- Event[T]) error

Sync sends a sync event for each resource returned by the ListFunc.

func (*Informer[T, L]) Watch

func (i *Informer[T, L]) Watch(ctx context.Context, opt Option, events chan<- Event[T]) error

Watch starts a goroutine that watches the resource and sends events to the events channel.

func (*Informer[T, L]) WatchWithCache

func (i *Informer[T, L]) WatchWithCache(ctx context.Context, opt Option, events chan<- Event[T]) (Getter[T], error)

WatchWithCache starts a goroutine that watches the resource and sends events to the events channel.

func (*Informer[T, L]) WatchWithLazyCache added in v0.5.0

func (i *Informer[T, L]) WatchWithLazyCache(ctx context.Context, opt Option, events chan<- Event[T]) (Getter[T], error)

WatchWithLazyCache starts a goroutine that watches the resource and sends events to the events channel.

type Option

type Option struct {
	LabelSelector      string
	FieldSelector      string
	AnnotationSelector string
	// contains filtered or unexported fields
}

Option is used to filter events.

type Watcher

type Watcher[T runtime.Object, L runtime.Object] interface {
	// List returns an object containing a list of the resources matching the provided options.
	List(ctx context.Context, opts metav1.ListOptions) (L, error)
	// Watch returns an object that watches the resources matching the provided options.
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}

Watcher is an interface for objects that know how to watch resources.

Jump to

Keyboard shortcuts

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