lifecycle

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AppliedPropagatorAnnotation stores the list of last applied label keys on the destination object
	AppliedPropagatorAnnotation = "greenhouse.sap/last-applied-propagator"

	// PropagateLabelsAnnotation defines which label keys should be propagated from source to destination
	PropagateLabelsAnnotation = "greenhouse.sap/propagate-labels"
	// PropagateAnnotationsAnnotation defines which annotation keys should be propagated from source to destination
	PropagateAnnotationsAnnotation = "greenhouse.sap/propagate-annotations"
)
View Source
const (
	CreatedReason          greenhousemetav1alpha1.ConditionReason = "Created"
	PendingCreationReason  greenhousemetav1alpha1.ConditionReason = "PendingCreation"
	FailingCreationReason  greenhousemetav1alpha1.ConditionReason = "FailingCreation"
	PendingDeletionReason  greenhousemetav1alpha1.ConditionReason = "PendingDeletion"
	FailingDeletionReason  greenhousemetav1alpha1.ConditionReason = "FailingDeletion"
	DeletedReason          greenhousemetav1alpha1.ConditionReason = "Deleted"
	CommonCleanupFinalizer                                        = "greenhouse.sap/cleanup"

	// Success should be returned in case the operator reached its target state
	Success ReconcileResult = "Success"
	// Failed should be returned in case the operator wasn't able to reach its target state and without external changes it's unlikely that this will succeed in the next try
	Failed ReconcileResult = "Failed"
	// Pending should be returned in case the operator is still trying to reach the target state (Requeue, waiting for remote resource to be cleaned up, etc.)
	Pending ReconcileResult = "Pending"

	// SuspendAnnotation is the annotation used to suspend reconciliation of a resource
	SuspendAnnotation = "greenhouse.sap/suspend"

	// ReconcileAnnotation is the annotation used to trigger reconciliation of a resource
	// Any change to the value of this annotation should trigger a reconciliation.
	ReconcileAnnotation = "greenhouse.sap/reconcile"
)

Variables

This section is empty.

Functions

func Reconcile

func Reconcile(ctx context.Context, kubeClient client.Client, namespacedName types.NamespacedName, runtimeObject RuntimeObject, reconciler Reconciler, statusFunc Conditioner) (ctrl.Result, error)

Reconcile - is a generic function that is used to reconcile the state of a resource It standardizes the reconciliation loop and provides a common way to set finalizers, remove finalizers, and update the status of the resource It splits the reconciliation into two phases: EnsureCreated and EnsureDeleted to keep the create / update and delete logic in controllers segregated

func ReconcileAnnotationValue

func ReconcileAnnotationValue(object v1.Object) (string, bool)

ReconcileAnnotationValue returns the value of the reconcile annotation and a boolean indicating whether the annotation is present

Types

type CatalogObject

type CatalogObject interface {
	runtime.Object
	v1.Object
	GetConditions() []v1.Condition
}

CatalogObject is an interface that generalizes the CR object that represents a Flux resource TODO: Rename to GenericFluxObject (This is used now in other controllers and CatalogObject is not appropriate)

type Conditioner

type Conditioner func(context.Context, RuntimeObject)

Conditioner is a function that can be used to set the status conditions of the object at a later point in the reconciliation process Provided by the caller of the Reconcile function

type LastReconciledAtSetter

type LastReconciledAtSetter interface {
	// UpdateLastReconciledAtStatus updates the status field for last reconcile annotation
	UpdateLastReconciledAtStatus(string)
}

LastReconciledAtSetter is an interface for runtime objects that support setting the lastReconciledAt status

type Propagator

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

Propagator encapsulates a source and destination object between which label keys are propagated according to configured annotations.

func NewPropagator

func NewPropagator(src, dst client.Object) *Propagator

NewPropagator creates a new Propagator instance for syncing labels between a source and destination Kubernetes object.

func (*Propagator) Apply

func (p *Propagator) Apply() client.Object

Apply - performs idempotent propagation of declared label and annotation keys based on the propagate-labels and propagate-annotations annotations on the source object. It adds or updates only the specified keys from src to dst, and removes any previously propagated keys that were removed in src or are no longer declared.

func (*Propagator) CopyLabels added in v0.11.0

func (p *Propagator) CopyLabels(labelKeys []string) client.Object

CopyLabels - copies labels from src to dst, only labels with the keys specified in the parameter. Supports wildcards (e.g., "metadata.greenhouse.sap/*" matches all labels with that prefix). Does not track applied state. If a label key exists in both src and dst, the src value overwrites dst. If a specified label key doesn't exist in src, dst remains unchanged for that key.

type ReconcileResult

type ReconcileResult string

func ExecuteSubRoutine added in v0.16.0

func ExecuteSubRoutine(ctx context.Context, routines []SubRoutine) (ctrl.Result, ReconcileResult, error)

ExecuteSubRoutine runs subroutines in order until one signals exit or the chain completes. Mapping into ReconcileResult:

  • Break or err != nil -> Failed, stop.
  • Pending or RequeueAfter > 0 -> Pending, stop (caller requeues).
  • All routines return Continue -> Success.

type Reconciler

type Reconciler interface {
	EnsureCreated(context.Context, RuntimeObject) (ctrl.Result, ReconcileResult, error)
	EnsureDeleted(context.Context, RuntimeObject) (ctrl.Result, ReconcileResult, error)
	EnsureSuspended(context.Context, RuntimeObject) (ctrl.Result, error)
}

Reconciler is the interface that wraps the basic EnsureCreated and EnsureDeleted methods that a controller should implement

type Result added in v0.16.0

type Result struct {
	reconcile.Result

	Pending bool
	Break   bool
}

Result is the return value of a SubRoutine. It embeds controller-runtime's reconcile.Result for RequeueAfter and carries two flags that short-circuit the chain:

  • Pending: stop the chain, map to ReconcileResult Pending (requeue).
  • Break: stop the chain, map to ReconcileResult Failed (degraded status).

A zero Result with nil error means "continue to the next subroutine".

func Break added in v0.16.0

func Break() Result

Break signals "stop the chain, mark Failed". The accompanying error from the subroutine is what surfaces on status.

func Continue added in v0.16.0

func Continue() Result

Continue signals "move to the next subroutine".

func Requeue added in v0.16.0

func Requeue() Result

Requeue signals a 5-second requeue. Use for short-poll loops on remote state that is expected to settle quickly.

func RequeueAfter added in v0.16.0

func RequeueAfter(d time.Duration) Result

RequeueAfter signals a requeue with a caller-chosen delay.

type RuntimeObject

type RuntimeObject interface {
	runtime.Object
	v1.Object
	// GetConditions returns the status conditions of the object (must be implemented in respective types)
	GetConditions() greenhousemetav1alpha1.StatusConditions
	// SetCondition sets the status conditions of the object (must be implemented in respective types)
	SetCondition(greenhousemetav1alpha1.Condition)
	// RemoveCondition removes a condition from the object (must be implemented in respective types)
	RemoveCondition(greenhousemetav1alpha1.ConditionType)
	// CanBeSuspended returns whether the resource type supports suspension
	CanBeSuspended() bool
}

RuntimeObject is an interface that generalizes the CR object that is being reconciled

type SubRoutine added in v0.16.0

type SubRoutine func(context.Context) (Result, error)

SubRoutine is a single step in a reconciliation chain. It closes over the resource being reconciled and any per-reconcile state held on the phase struct; the only argument is the context, so chains can be assembled as plain slices.

Jump to

Keyboard shortcuts

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