controller

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: Apache-2.0 Imports: 36 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// core
	ServicesResource   = core.SchemeGroupVersion.WithResource("services")
	ConfigMapsResource = core.SchemeGroupVersion.WithResource("configmaps")

	// gateway api
	GatewayClassesResource = gwapiv1.SchemeGroupVersion.WithResource("gatewayclasses")
	GatewaysResource       = gwapiv1.SchemeGroupVersion.WithResource("gateways")
	HTTPRoutesResource     = gwapiv1.SchemeGroupVersion.WithResource("httproutes")
)

API Resources

Functions

func CreateAndSetLogger

func CreateAndSetLogger() logr.Logger

CreateAndSetLogger returns a new logger and sets it as the default logger for the controller-runtime and klog packages.

func Destruct

func Destruct[T any](obj T) (*unstructured.Unstructured, error)

func FieldsFromObject

func FieldsFromObject[T any](obj T, fields []string) map[string]string

func LoggerFromContext

func LoggerFromContext(ctx context.Context) logr.Logger

LoggerFromContext returns the logger from the context, or a discard logger if no logger is found.

func LoggerIntoContext

func LoggerIntoContext(ctx context.Context, logger logr.Logger) context.Context

LoggerIntoContext returns a new context with the logger set.

func ObjectAs

func ObjectAs[T any](obj Object, _ int) T

ObjectAs casts an Object generically into any kind

func Restructure

func Restructure[T any](obj any) (any, error)

func ToFieldSelector

func ToFieldSelector(s string) fields.Selector

func ToLabelSelector

func ToLabelSelector(s string) labels.Selector

func TypedEnqueueRequestsMapFunc

func TypedEnqueueRequestsMapFunc[T Object](_ context.Context, _ T) []ctrlruntimereconcile.Request

Types

type CacheStore added in v0.3.0

type CacheStore struct {
	sync.RWMutex
	watchable.Map[string, Store]
}

func (*CacheStore) Add added in v0.3.0

func (c *CacheStore) Add(storeId string, obj Object)

func (*CacheStore) Delete added in v0.3.0

func (c *CacheStore) Delete(storeId string, obj Object)

func (*CacheStore) List added in v0.3.0

func (c *CacheStore) List(storeId string) Store

func (*CacheStore) Replace added in v0.3.0

func (c *CacheStore) Replace(storeId string, store Store)

type Controller

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

func NewController

func NewController(f ...ControllerOption) *Controller

func (*Controller) Start

func (c *Controller) Start(ctx context.Context) error

Start starts the runnables and blocks until the context is cancelled

type ControllerOption

type ControllerOption func(*ControllerOptions)

func AllowLoops

func AllowLoops() ControllerOption

func ManagedBy

func ManagedBy(manager ctrlruntime.Manager) ControllerOption

func WithClient

func WithClient(client *dynamic.DynamicClient) ControllerOption

func WithLogger

func WithLogger(logger logr.Logger) ControllerOption

func WithName

func WithName(name string) ControllerOption

func WithObjectKinds

func WithObjectKinds(objectKinds ...schema.GroupKind) ControllerOption
func WithObjectLinks(objectLinks ...LinkFunc) ControllerOption

func WithPolicyKinds

func WithPolicyKinds(policyKinds ...schema.GroupKind) ControllerOption

func WithReconcile

func WithReconcile(reconcile ReconcileFunc) ControllerOption

func WithRunnable

func WithRunnable(name string, builder RunnableBuilder) ControllerOption

type ControllerOptions

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

type EventType

type EventType int
const (
	CreateEvent EventType = iota
	UpdateEvent
	DeleteEvent
)

func (*EventType) String

func (t *EventType) String() string

type LinkFunc

type LinkFunc func(objs Store) machinery.LinkFunc

type ListFunc

type ListFunc func() []Object

type Object

type Object interface {
	runtime.Object
	metav1.Object
}

type ObjectsByCreationTimestamp added in v0.4.0

type ObjectsByCreationTimestamp []Object

ObjectsByCreationTimestamp is a slice of RuntimeObject that can be sorted by creation timestamp RuntimeObjects with the oldest creation timestamp will appear first; if two objects have the same creation timestamp, the object appearing first in alphabetical order by namespace/name will appear first.

func (ObjectsByCreationTimestamp) Len added in v0.4.0

func (ObjectsByCreationTimestamp) Less added in v0.4.0

func (a ObjectsByCreationTimestamp) Less(i, j int) bool

func (ObjectsByCreationTimestamp) Swap added in v0.4.0

func (a ObjectsByCreationTimestamp) Swap(i, j int)

type ReconcileFunc

type ReconcileFunc func(context.Context, []ResourceEvent, *machinery.Topology, error, *sync.Map) error

ReconcileFunc is a function that reconciles a particular state of the world. It receives a list of recent events, an immutable copy of the topology as known by the caller after the events, an optional error detected before the reconciliation, and a thread-safe map to store transient state across chained calls to multiple ReconcileFuncs. If a ReconcileFunc returns an error, a chained sequence of ReconcileFuncs must be interrupted.

type ResourceEvent

type ResourceEvent struct {
	Kind      schema.GroupKind
	EventType EventType
	OldObject Object
	NewObject Object
}

type ResourceEventMatcher

type ResourceEventMatcher struct {
	Kind            *schema.GroupKind
	EventType       *EventType
	ObjectNamespace string
	ObjectName      string
}

type Runnable

type Runnable interface {
	Run(stopCh <-chan struct{})
	HasSynced() bool
}

type RunnableBuilder

type RunnableBuilder func(controller *Controller) Runnable

func IncrementalInformer

func IncrementalInformer[T Object](obj T, resource schema.GroupVersionResource, namespace string, options ...RunnableBuilderOption[T]) RunnableBuilder

func StateReconciler

func StateReconciler[T Object](obj T, resource schema.GroupVersionResource, namespace string, options ...RunnableBuilderOption[T]) RunnableBuilder

func Watch

func Watch[T Object](obj T, resource schema.GroupVersionResource, namespace string, options ...RunnableBuilderOption[T]) RunnableBuilder

type RunnableBuilderOption

type RunnableBuilderOption[T Object] func(*RunnableBuilderOptions[T])

func Builder

func Builder[T Object](builder func(obj T, resource schema.GroupVersionResource, namespace string, options ...RunnableBuilderOption[T]) RunnableBuilder) RunnableBuilderOption[T]

func FilterResourcesByField

func FilterResourcesByField[T Object](selector string) RunnableBuilderOption[T]

func FilterResourcesByLabel

func FilterResourcesByLabel[T Object](selector string) RunnableBuilderOption[T]

func WithPredicates added in v0.3.0

func WithPredicates[T Object](predicates ...ctrlruntimepredicate.TypedPredicate[T]) RunnableBuilderOption[T]

type RunnableBuilderOptions

type RunnableBuilderOptions[T Object] struct {
	LabelSelector string
	FieldSelector string
	Predicates    []ctrlruntimepredicate.TypedPredicate[T]
	Builder       func(obj T, resource schema.GroupVersionResource, namespace string, options ...RunnableBuilderOption[T]) RunnableBuilder
}

type RuntimeObject

type RuntimeObject struct {
	Object
}

RuntimeObject is a wrapper around a Kubernetes runtime object, that also implements the machinery.Object interface Use it for wrapping runtime objects that do not natively implement machinery.Object, so such object can be added to a machinery.Topology

func (*RuntimeObject) GetLocator

func (o *RuntimeObject) GetLocator() string

func (*RuntimeObject) GetName

func (o *RuntimeObject) GetName() string

func (*RuntimeObject) GetNamespace

func (o *RuntimeObject) GetNamespace() string

func (*RuntimeObject) GroupVersionKind

func (o *RuntimeObject) GroupVersionKind() schema.GroupVersionKind

func (*RuntimeObject) SetGroupVersionKind

func (o *RuntimeObject) SetGroupVersionKind(schema.GroupVersionKind)

type Store

type Store map[string]Object

func (Store) DeepCopy added in v0.3.0

func (s Store) DeepCopy() Store

func (Store) Equal added in v0.3.0

func (s Store) Equal(other Store) bool

func (Store) Filter

func (s Store) Filter(predicates ...func(Object) bool) []Object

func (Store) FilterByGroupKind

func (s Store) FilterByGroupKind(gk schema.GroupKind) []Object

type Subscription

type Subscription struct {
	ReconcileFunc ReconcileFunc
	Events        []ResourceEventMatcher
}

Subscription runs a reconciliation function when the list of events has at least one event in common with the list of event matchers. The list of events then propagated to the reconciliation function is filtered to the ones the match only.

func (Subscription) Reconcile

func (s Subscription) Reconcile(ctx context.Context, resourceEvents []ResourceEvent, topology *machinery.Topology, err error, state *sync.Map) error

type WatchFunc

type WatchFunc func(ctrlruntime.Manager) ctrlruntimesrc.Source

type Workflow

type Workflow struct {
	Precondition  ReconcileFunc
	Tasks         []ReconcileFunc
	Postcondition ReconcileFunc
	ErrorHandler  ReconcileFunc
}

Workflow runs an optional precondition reconciliation function, then dispatches the reconciliation event to a list of concurrent reconciliation tasks, and runs an optional postcondition reconciliation function.

If any of the reconciliation functions returns an error, the error is handled by an optional error handler. The error passed to the error handler func is conflated with any occasional error carried over into the call to the workflow in the first place. It is up to the error handler to decide how to handle the error and whether to supress it or raise it again. Supressed errors cause the workflow to continue running, while raised errors interrupt the workflow. If the error handler is nil, the error is raised.

func (*Workflow) Run

func (w *Workflow) Run(ctx context.Context, resourceEvents []ResourceEvent, topology *machinery.Topology, err error, state *sync.Map) error

Jump to

Keyboard shortcuts

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