generic

package
v0.27.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package generic contains a typed wrapper over cache SharedIndexInformer and Lister (maybe eventually should have a home there?)

This interface is being experimented with as an easier way to write controllers with a bit less boilerplate.

Informer/Lister classes are thin wrappers providing a type-safe interface over regular interface{}-based Informers/Listers

Controller[T] provides a reusable way to reconcile objects out of an informer using the tried and true controller design pattern found all over k8s codebase based upon syncFunc/reconcile

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLister

func NewLister[T runtime.Object](indexer cache.Indexer) lister[T]

Types

type Controller

type Controller[T runtime.Object] interface {
	// Meant to be run inside a goroutine
	// Waits for and reacts to changes in whatever type the controller
	// is concerned with.
	//
	// Returns an error always non-nil explaining why the worker stopped
	Run(ctx context.Context) error

	// Retrieves the informer used to back this controller
	Informer() Informer[T]

	// Returns true if the informer cache has synced, and all the objects from
	// the initial list have been reconciled at least once.
	HasSynced() bool
}

func NewController

func NewController[T runtime.Object](
	informer Informer[T],
	reconciler func(namepace, name string, newObj T) error,
	options ControllerOptions,
) Controller[T]

type ControllerOptions

type ControllerOptions struct {
	Name    string
	Workers uint
}

type Informer

type Informer[T any] interface {
	cache.SharedIndexInformer
	Lister[T]
}

func NewInformer

func NewInformer[T runtime.Object](informe cache.SharedIndexInformer) Informer[T]

type Lister

type Lister[T any] interface {
	NamespacedLister[T]
	Namespaced(namespace string) NamespacedLister[T]
}

Lister[T] helps list Ts. All objects returned here must be treated as read-only.

type NamespacedLister

type NamespacedLister[T any] interface {
	// List lists all ValidationRuleSets in the indexer for a given namespace.
	// Objects returned here must be treated as read-only.
	List(selector labels.Selector) (ret []T, err error)
	// Get retrieves the ValidationRuleSet from the indexer for a given namespace and name.
	// Objects returned here must be treated as read-only.
	Get(name string) (T, error)
}

Jump to

Keyboard shortcuts

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