controller

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2026 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventTypeCreate  = "CREATE"
	EventTypeUpdate  = "UPDATE"
	EventTypeDelete  = "DELETE"
	EventTypeGeneric = "GENERIC"
	EventTypeUnknown = "UNKNOWN"
)

Event type constants cached to attribute the triggering reason for a reconcile request when it is later processed.

View Source
const (
	// ExtensionFinalizer is added to extension managed policies so that final
	// cleanup (e.g. mutator/subscription deregistration) can occur prior to
	// object deletion.
	ExtensionFinalizer = "kuadrant.io/extensions"
)

Variables

This section is empty.

Functions

func AcceptedCondition

func AcceptedCondition(p exttypes.Policy, err error) *metav1.Condition

AcceptedCondition returns a metav1.Condition reflecting the accepted state of a policy (accepted when err == nil, otherwise rejected with reason).

func ConditionMarshal

func ConditionMarshal(conditions []metav1.Condition) ([]byte, error)

ConditionMarshal marshals the set of conditions as a JSON array, sorted by condition type.

func EnforcedCondition

func EnforcedCondition(p exttypes.Policy, err error, fully bool) *metav1.Condition

EnforcedCondition returns a metav1.Condition representing enforcement success (or partial failure) for a policy. If err is non-nil the condition is False with the underlying policy error reason.

func Resolve

func Resolve[T any](ctx context.Context, kuadrantCtx exttypes.KuadrantCtx, policy exttypes.Policy, expression string, subscribe bool) (T, error)

Resolve is a generic helper that evaluates a CEL expression via the KuadrantCtx and converts the result to the requested Go type T.

An error is returned if evaluation fails or the type conversion cannot be satisfied.

Types

type Builder

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

Builder constructs an ExtensionController with a fluent API similar to controller-runtime's builder, adding extension specific concerns (gRPC client, event cache, unix socket path).

func NewBuilder

func NewBuilder(name string) (*Builder, logr.Logger)

NewBuilder creates a new Builder for a given controller name and returns it alongside the configured logger.

func (*Builder) Build

func (b *Builder) Build() (*ExtensionController, error)

Build validates the configuration, creates the underlying manager, gRPC client and returns a ready to Start ExtensionController.

func (*Builder) For

func (b *Builder) For(obj client.Object) *Builder

For sets the primary object type (policy) reconciled by the controller.

func (*Builder) Owns

func (b *Builder) Owns(obj client.Object) *Builder

Owns registers owned object types so that owner references are resolved and reconcile requests enqueued for the owning policy kind.

func (*Builder) Watches

func (b *Builder) Watches(obj client.Object) *Builder

Watches registers additional object types whose events should enqueue the primary object's reconcile requests.

func (*Builder) WithReconciler

func (b *Builder) WithReconciler(fn exttypes.ReconcileFn) *Builder

WithReconciler sets the user reconcile function.

func (*Builder) WithScheme

func (b *Builder) WithScheme(scheme *runtime.Scheme) *Builder

WithScheme sets the runtime Scheme used by the manager.

type EventCachingHandler

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

EventCachingHandler is a controller-runtime handler that adds the event type to the cache before enqueuing reconcile requests.

func (*EventCachingHandler) Create

Create implements the handler interface adding a CREATE event.

func (*EventCachingHandler) Delete

Delete implements the handler interface adding a DELETE event.

func (*EventCachingHandler) Generic

Generic implements the handler interface adding a GENERIC event.

func (*EventCachingHandler) Update

Update implements the handler interface adding an UPDATE event.

type EventTypeCache

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

EventTypeCache stores a FIFO list of event types per namespaced name so the reconcile loop can retrieve the causal event. Not concurrency heavy, guarded by a RWMutex.

type ExtensionConfig

type ExtensionConfig struct {
	Name         string
	PolicyKind   string
	ForType      client.Object
	Reconcile    exttypes.ReconcileFn
	WatchSources []ctrlruntimesrc.Source
}

ExtensionConfig captures the immutable configuration for a controller instance constructed by the Builder. It determines:

Name:        controller name (also used for logging prefix)
PolicyKind:  the Kind of the primary policy CRD managed
ForType:     the primary object type reconciled
Reconcile:   the user provided reconcile function
WatchSources: dynamic sources watched (primary, additional and owned)

type ExtensionController

type ExtensionController struct {
	*basereconciler.BaseReconciler // TODO(didierofrivia): Next iteration, use policy machinery
	// contains filtered or unexported fields
}

ExtensionController is a thin wrapper around controller-runtime's manager and controller that wires gRPC event subscriptions with the reconcile loop and exposes helper methods (Resolve, ReconcileObject, etc.) via the KuadrantCtx interface passed to user code.

func (*ExtensionController) AddDataTo

func (ec *ExtensionController) AddDataTo(ctx context.Context, policy exttypes.Policy, domain exttypes.Domain, binding string, expression string) error

AddDataTo registers a mutator expression that will inject computed data into a policy under the provided domain and binding.

func (*ExtensionController) ClearPolicy

func (ec *ExtensionController) ClearPolicy(ctx context.Context, namespace, name, kind string) error

ClearPolicy removes server side state associated with a policy (mutators, subscriptions) after deletion.

func (*ExtensionController) Manager

func (ec *ExtensionController) Manager() ctrlruntime.Manager

Manager returns the underlying controller-runtime Manager.

func (*ExtensionController) Reconcile

func (ec *ExtensionController) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error)

Reconcile implements the controller-runtime reconcile loop. It ensures finalizers, dispatches the configured user Reconcile function and performs post‑reconcile cleanup.

func (*ExtensionController) ReconcileObject

func (ec *ExtensionController) ReconcileObject(ctx context.Context, obj client.Object, desired client.Object, mutateFn exttypes.MutateFn) (client.Object, error)

ReconcileObject performs a create/update patch against the API server for a desired object applying the provided mutate function on differences.

func (*ExtensionController) Resolve

func (ec *ExtensionController) Resolve(ctx context.Context, policy exttypes.Policy, expression string, subscribe bool) (ref.Val, error)

Resolve evaluates a CEL expression against the provided policy returning the raw CEL result as a ref.Val. If subscribe is true the extension service will stream future changes (triggering new reconciliations).

func (*ExtensionController) ResolvePolicy

func (ec *ExtensionController) ResolvePolicy(ctx context.Context, policy exttypes.Policy, expression string, subscribe bool) (exttypes.Policy, error)

ResolvePolicy evaluates a CEL expression that must return a Policy protobuf which is then adapted to the generic Policy interface. Used when expressions transform or select policies.

func (*ExtensionController) Start

func (ec *ExtensionController) Start(ctx context.Context) error

Start launches the controller manager and begins processing events.

func (*ExtensionController) Subscribe

func (ec *ExtensionController) Subscribe(ctx context.Context, reconcileChan chan ctrlruntimeevent.GenericEvent)

Subscribe opens a long‑lived gRPC stream for events related to the policy kind and enqueues reconcile requests for received events.

Jump to

Keyboard shortcuts

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