component

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package component implements a common controller pattern: an object is specified by a user, and another kube object needs to be created in response.

`Component`specifies how to find these related objects in the cluster.

`ContextHandler` is a handler.Handler implementation that can pick out a component from a cluster and add it into a context.Context key.

`EnsureComponent` is a handler.Handler implementation that ensures that a component with a given specification exists. It handles creating the object if it doesn't exist and updating it only if the calculated object has changed. It also cleans up duplicate matching component objects by deleting any that match the component selector but do not match the calculated object.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Annotator

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

Annotator is any type that can have annotations added to it. All standard applyconfiguration packages from client-go implement this type. Custom types should implement it themselves.

type Component

type Component[K KubeObject] struct {
	// contains filtered or unexported fields
}

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

func NewIndexedComponent

func NewIndexedComponent[K KubeObject](indexer *typed.Indexer[K], indexName string, selectorFunc func(ctx context.Context) labels.Selector) *Component[K]

NewIndexedComponent creates a Component from an index

func (*Component[K]) List

func (c *Component[K]) List(ctx context.Context, 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 ContextHandler

type ContextHandler[K KubeObject] struct {
	// contains filtered or unexported fields
}

ContextHandler fills the value for a context.Key with the result of fetching a component.

func NewComponentContextHandler

func NewComponentContextHandler[K KubeObject](contextKey typedctx.SettableContext[[]K], component *Component[K], owner typedctx.MustValueContext[types.NamespacedName], next handler.ContextHandler) *ContextHandler[K]

NewComponentContextHandler creates a new ContextHandler.

func (*ContextHandler[K]) Handle

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

type EnsureComponentByHash

type EnsureComponentByHash[K KubeObject, A Annotator[A]] struct {
	*HashableComponent[K]
	// contains filtered or unexported fields
}

EnsureComponentByHash is a handler.Handler implementation that will create a component object and ensure it has the computed spec.

func NewEnsureComponentByHash

func NewEnsureComponentByHash[K KubeObject, A Annotator[A]](
	component *HashableComponent[K],
	owner typedctx.MustValueContext[types.NamespacedName],
	ctrls queue.OperationsContext,
	applyObj func(ctx context.Context, apply A) (K, error),
	deleteObject func(ctx context.Context, nn types.NamespacedName) error,
	newObj func(ctx context.Context) A,
) *EnsureComponentByHash[K, A]

NewEnsureComponentByHash returns a new EnsureComponentByHash handler.

func (*EnsureComponentByHash[K, A]) Handle

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

type HashableComponent

type HashableComponent[K KubeObject] struct {
	*Component[K]
	hash.ObjectHasher
	HashAnnotationKey string
}

HashableComponent is a Component with an annotation that stores a hash of the previous configuration written by the controller. The hash is used to determine if work still needs to be done.

func NewHashableComponent

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

NewHashableComponent creates HashableComponent from a Component and a hash.ObjectHasher, plus an annotation key to use to store the hash on the object.

type KubeObject

type KubeObject interface {
	metav1.Object
	runtime.Object
}

KubeObject is satisfied by any standard kube object.

Jump to

Keyboard shortcuts

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