controller

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RunningPhase   shared.PhaseName     = "running"
	StartingPhase  shared.PhaseName     = "starting"
	ReadyCondition shared.ConditionName = "Ready"
	BaseAnnotation string               = "operator-sdk-extra.webcenter.fr"

	// ShortenError is the historical max length used for truncating error messages.
	// Deprecated: use MaxConditionMessage, MaxEventMessage or MaxStatusMessage instead,
	// combined with UserFacingError to extract the root cause before truncating.
	ShortenError int = 5000

	// MaxConditionMessage is the recommended max length for a metav1.Condition.Message
	// stored in a CRD status. The Kubernetes spec allows up to 32 KiB, but most
	// controllers cap well below 1 KiB to keep `kubectl get` / `kubectl describe` readable.
	MaxConditionMessage = 1024

	// MaxEventMessage is the recommended max length for a corev1.Event message.
	// The Kubernetes event recorder silently drops events whose total size exceeds
	// the etcd object limit (~1.5 MiB), and messages above ~1 KiB are rarely useful
	// when surfaced via `kubectl describe`.
	MaxEventMessage = 512

	// MaxStatusMessage is the recommended max length for the LastErrorMessage
	// field stored in CRD status. Stored in etcd, so kept short to avoid document
	// bloat across repeated failing reconcile loops.
	MaxStatusMessage = 1024
)

Variables

View Source
var (
	ErrWhenCallConfigureFromReconciler      = errors.Sentinel("Error when call 'configure' from reconciler")
	ErrWhenCallReadFromReconciler           = errors.Sentinel("Error when call 'read' from reconciler")
	ErrWhenCallDeleteFromReconciler         = errors.Sentinel("Error when call 'delete' from reconciler")
	ErrWhenCallDiffFromReconciler           = errors.Sentinel("Error when call 'diff' from reconciler")
	ErrWhenCallCreateFromReconciler         = errors.Sentinel("Error when call 'create' from reconciler")
	ErrWhenCallUpdateFromReconciler         = errors.Sentinel("Error when call 'update' from reconciler")
	ErrWhenCallApplyFromReconciler          = errors.Sentinel("Error when call 'apply' from reconciler")
	ErrWhenCallOnSuccessFromReconciler      = errors.Sentinel("Error when call 'onSuccess' from reconciler")
	ErrWhenCallOnDiffFromReconciler         = errors.Sentinel("Error when call 'onDiff' from reconciler")
	ErrWhenCallStepReconcilerFromReconciler = errors.Sentinel("Error when call 'reconcile' from step reconciler")
	ErrWhenGetObjectFromReconciler          = errors.Sentinel("Error when get object from reconciler")
	ErrWhenAddFinalizer                     = errors.Sentinel("Error when add finalizer")
	ErrWhenDeleteFinalizer                  = errors.Sentinel("Error when delete finalizer")
	ErrWhenGetObjectStatus                  = errors.Sentinel("Error when get object status")
	ErrDiffDisabled                         = errors.Sentinel("Dry-run diff detection is disabled. Either enable it with dryRun=true or override OnDiff to return nil")
)

Functions

func DefaultControllerRateLimiter

func DefaultControllerRateLimiter[T comparable]() workqueue.TypedRateLimiter[T]

DefaultControllerRateLimiter set rate limiter that is lower agressive than the default

func DeferStatusUpdate

func DeferStatusUpdate(ctx context.Context, c client.Client, o client.Object, logger *logrus.Entry) (deferred func() error, err error)

DeferStatusUpdate snapshots the current object status and returns a deferred function that updates the status on the API server if it changed. It returns a no-op function when the object has no status.

func EnsureNetworkPolicyForWebhook

func EnsureNetworkPolicyForWebhook(ctx context.Context, c client.Client, logger *logrus.Entry, namespace string, labels map[string]string, podSelecetors map[string]string) error

EnsureNetworkPolicyForWebhook permit to create / update NetworkPolicy for webhook

func GetObjectFromReconciler

func GetObjectFromReconciler(ctx context.Context, c client.Client, req reconcile.Request, o client.Object, logger *logrus.Entry) (found bool, err error)

GetObjectFromReconciler fetches the reconciled object into o. It returns (found=false, nil) when the object no longer exists, so the caller can stop the reconcile loop cleanly.

func GetObjectMeta

func GetObjectMeta(r client.Object) metav1.ObjectMeta

GetObjectMeta permit to get the metata from client.Object

func GetObjectStatus

func GetObjectStatus(r client.Object) any

GetObjectStatus permit to get the status from client.Object

func IsReconcileIgnored

func IsReconcileIgnored(o client.Object) bool

IsReconcileIgnored returns true when the object carries the ignoreReconcile annotation.

func MustInjectTypeMeta

func MustInjectTypeMeta(src, dst client.Object)

MustInjectTypeMeta permit to inject the typeMeta from src to dst

func SetupIndexerWithManager

func SetupIndexerWithManager(mgr ctrl.Manager, indexers ...Indexer) (err error)

SetupIndexerWithManager permit to registers indexers on manager

func SetupWebhookWithManager

func SetupWebhookWithManager(mgr ctrl.Manager, client client.Client, webhookRegisters ...WebhookRegister) (err error)

SetupWebhookWithManager permit to registers webhooks on manager

func UserFacingError

func UserFacingError(err error, maxLen int) string

UserFacingError returns a short, human-useful error message from an error chain.

It extracts the deepest (root) cause through errors.Cause — the one produced by the underlying library or API — discarding the intermediate wrapping messages added by errors.Wrap / errors.Wrapf up the call stack. Those wrapping messages remain available via the logger.

The result is truncated to maxLen bytes. When truncation occurs the string is suffixed with "..." so the user can see the message was not complete.

If the chain has no extractable cause, the top-level error message is used as-is.

Types

type BaseReconciler

type BaseReconciler interface {
	// Client get the client
	Client() client.Client

	// Recorder get the recorder
	Recorder() record.EventRecorder
}

BaseReconciler is the interface for all reconciler

func NewBaseReconciler

func NewBaseReconciler(client client.Client, recorder record.EventRecorder) BaseReconciler

NewBaseReconciler return the default implementation of BaseReconciler interface

type Controller

type Controller interface {
	Reconcile(context.Context, reconcile.Request) (reconcile.Result, error)

	// SetupWithManager permit to setup controller with manager
	SetupWithManager(mgr ctrl.Manager) error
}

Controller is the controller interface

func NewController

func NewController() Controller

NewController is the default implementation of Controller

type DefaultBaseReconciler

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

DefaultBaseReconciler is the default implementation of BaseReconciler interface

func (*DefaultBaseReconciler) Client

func (h *DefaultBaseReconciler) Client() client.Client

func (*DefaultBaseReconciler) Recorder

type DefaultController

type DefaultController struct{}

DefaultController is the default controller implementation

func (*DefaultController) Reconcile

func (*DefaultController) SetupWithManager

func (h *DefaultController) SetupWithManager(mgr ctrl.Manager) error

type DefaultReconciler

type DefaultReconciler struct {
	BaseReconciler
	// contains filtered or unexported fields
}

DefaultReconciler is the default implementation of Reconciler interface

func (*DefaultReconciler) Finalizer

func (h *DefaultReconciler) Finalizer() shared.FinalizerName

func (*DefaultReconciler) Logger

func (h *DefaultReconciler) Logger() *logrus.Entry

type DefaultReconcilerAction

type DefaultReconcilerAction struct {
	BaseReconciler
	// contains filtered or unexported fields
}

DefaultReconcilerAction is the default implementation of ReconcilerAction interface

func (*DefaultReconcilerAction) Condition

type Indexer

type Indexer func(mgr ctrl.Manager) error

Indexer is a function to add indexer on manager

type Reconciler

type Reconciler interface {
	BaseReconciler

	// Finalizer get the finalier name
	Finalizer() shared.FinalizerName

	// Logger get the logger
	Logger() *logrus.Entry
}

func NewReconciler

func NewReconciler(client client.Client, recorder record.EventRecorder, finalizer shared.FinalizerName, logger *logrus.Entry) Reconciler

NewReconciler is the default implementation of the Reconciler interface

type ReconcilerAction

type ReconcilerAction interface {
	BaseReconciler

	// Condition get the condition name
	Condition() shared.ConditionName
}

func NewReconcilerAction

func NewReconcilerAction(client client.Client, recorder record.EventRecorder, conditionName shared.ConditionName) ReconcilerAction

NewReconcilerAction return the default implementation of ReconcilerAction

type WebhookRegister

type WebhookRegister func(mgr ctrl.Manager, client client.Client) error

WebhookRegister is a function to add Webhook on manager

Directories

Path Synopsis
Package certificate provides pluggable TLSBackend abstractions for certificate management in Kubernetes operators.
Package certificate provides pluggable TLSBackend abstractions for certificate management in Kubernetes operators.
byo
Package byo provides a TLSBackend that references an existing user-managed Secret.
Package byo provides a TLSBackend that references an existing user-managed Secret.
certmanager
Package certmanager provides a TLSBackend that emits cert-manager Issuer and Certificate custom resources.
Package certmanager provides a TLSBackend that emits cert-manager Issuer and Certificate custom resources.
selfmanaged
Package selfmanaged provides a TLSBackend that generates and manages CA and leaf certificates using Go's crypto/x509 standard library.
Package selfmanaged provides a TLSBackend that generates and manages CA and leaf certificates using Go's crypto/x509 standard library.
Package workflow provides a multi-cycle saga abstraction on top of the multiphase reconciler pattern.
Package workflow provides a multi-cycle saga abstraction on top of the multiphase reconciler pattern.

Jump to

Keyboard shortcuts

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