condition

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

+kubebuilder:object:generate=true +kubebuilder:unservedversion

Index

Constants

View Source
const (
	ConditionTrue    = corev1.ConditionTrue
	ConditionFalse   = corev1.ConditionFalse
	ConditionUnknown = corev1.ConditionUnknown
)

Variables

This section is empty.

Functions

func ErrNoop

func ErrNoop() error

ErrNoop is an error that indicates no changes should be made to the status. Used to indicate the reconciler is not ready to change the condition status yet.

func ErrSkipReconciliation

func ErrSkipReconciliation() error

ErrSkipReconciliation is an error that indicates the reconciliation should be skipped. Used to indicate that the object is not ready for reconciliation or not owned by the controller. Only checked in PreHooks.

func ErrStatusUnknown

func ErrStatusUnknown(e error) error

ErrStatusUnknown wraps an error with a status unknown error. Used to indicate the status of a given condition is unknown during reconciliation.

func ForceRequeue

func ForceRequeue(ctx context.Context)

ForceRequeue forces an immediate requeue, regardless if status has changed.

func ForceStatusUpdate

func ForceStatusUpdate(ctx context.Context)

ForceStatusUpdate forces a full "Status" update, regardless if conditions have changed.

func HandleFinalizer

func HandleFinalizer[T ConditionedType](
	ctx context.Context,
	c client.Client,
	obj T,
	finalizer string,
	finalizeFunc FinalizerFunc[T]) (bool, error)

HandleFinalizer ensures that the finalizer is present on the object. If the finalizer is not present, it adds it and updates the object. If the finalizer is present, it calls the finalizeFunc and removes the finalizer. It returns true if the object was updated. Reconcilers can use this to requeue.

Types

type AnyConditionedReconciler

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

AnyConditionedReconciler is an interface for reconcilers that reconcile objects with conditions. The ConditionedReconciler is a typed version of this interface. +kubebuilder:object:generate=false

type Condition

type Condition struct {
	// Type of this condition. At most one of each condition type may apply to
	// a resource at any point in time.
	Type ConditionType `json:"type"`

	// If set, this represents the .metadata.generation that the object condition was set based upon.
	// +optional
	ObservedGeneration int64 `json:"observedGeneration,omitempty"`

	// Status of this condition; is it currently True, False, or Unknown.
	Status corev1.ConditionStatus `json:"status"`

	// LastTransitionTime is the last time this condition transitioned from one
	// status to another.
	// +optional
	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`

	// Last time we probed the condition.
	// +optional
	LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`

	// A Reason for this condition's last transition from one status to another.
	// +optional
	Reason ConditionReason `json:"reason,omitempty"`

	// A Message containing details about this condition's last transition from
	// one status to another, if any.
	// +optional
	Message string `json:"message,omitempty"`
}

A Condition that may apply to a resource.

func Available

func Available() Condition

Available returns a condition that indicates the resource is currently observed to be available for use.

func Creating

func Creating() Condition

Creating returns a condition that indicates the resource is currently being created.

func Deleting

func Deleting() Condition

Deleting returns a condition that indicates the resource is currently being deleted.

func ErrorCondition

func ErrorCondition(condType ConditionType, reason ConditionReason, err error) Condition

ErrorCondition generate error condition for conditionType and error

func ReadyCondition

func ReadyCondition(condType ConditionType) Condition

ReadyCondition generate ready condition for conditionType

func ReconcileError

func ReconcileError(err error) Condition

ReconcileError returns a condition indicating that Crossplane encountered an error while reconciling the resource. This could mean Crossplane was unable to update the resource to reflect its desired state, or that Crossplane was unable to determine the current actual state of the resource.

func ReconcilePending

func ReconcilePending() Condition

ReconcilePending returns a condition indicating the beginning of a reconciliation.

func ReconcileSuccess

func ReconcileSuccess() Condition

ReconcileSuccess returns a condition indicating that Crossplane successfully completed the most recent reconciliation of the resource.

func Unavailable

func Unavailable() Condition

Unavailable returns a condition that indicates the resource is not currently available for use. Unavailable should be set only when Crossplane expects the resource to be available but knows it is not, for example because its API reports it is unhealthy.

func UnknownCondition

func UnknownCondition(condType ConditionType, reason ConditionReason, message string) Condition

UnknownCondition generate error condition for conditionType and error

func (*Condition) DeepCopy

func (in *Condition) DeepCopy() *Condition

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition.

func (*Condition) DeepCopyInto

func (in *Condition) DeepCopyInto(out *Condition)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (Condition) Equal

func (c Condition) Equal(other Condition) bool

Equal returns true if the condition is identical to the supplied condition, ignoring the LastTransitionTime.

func (Condition) WithMessage

func (c Condition) WithMessage(msg string) Condition

WithMessage returns a condition by adding the provided message to existing condition.

type ConditionReason

type ConditionReason string

A ConditionReason represents the reason a resource is in a condition. nolint

const (
	ReasonAvailable   ConditionReason = "Available"
	ReasonUnavailable ConditionReason = "Unavailable"
	ReasonCreating    ConditionReason = "Creating"
	ReasonDeleting    ConditionReason = "Deleting"
)

Reasons a resource is or is not ready.

const (
	ReasonReconcilePending ConditionReason = "ReconcilePending"
	ReasonReconcileSuccess ConditionReason = "ReconcileSuccess"
	ReasonReconcileError   ConditionReason = "ReconcileError"
)

Reasons a resource is or is not synced.

type ConditionType

type ConditionType string

A ConditionType represents a condition a resource could be in. nolint

const (
	// TypeReady resources are believed to be ready to handle work.
	TypeReady ConditionType = "Ready"

	// TypeSynced resources are believed to be in sync with the
	// Kubernetes resources that manage their lifecycle.
	TypeSynced ConditionType = "Synced"
)

Managed Condition types.

type ConditionedReconciler

type ConditionedReconciler[T ConditionedType] struct {
	// contains filtered or unexported fields
}

ConditionedReconciler is a reconciler that reconciles objects with many conditions. It encodes the core kubernetes pattern of reconciling objects with conditions & finalizer. Each condition is a function that updates the object's status. Functions are executed in first-in/first-out order, and all functions are called for each reconciliation. The status is updated after all functions have been called. A finalizer name is required to use the finalizer, and the finalizer function is called before the object is deleted. A useful pattern is to have a "Ready" condition as the last condition, validating the status of all previous ones. +kubebuilder:object:generate=false

func NewConditionedReconciler

func NewConditionedReconciler[T ConditionedType](
	c client.Client,
	scheme *runtime.Scheme,
	obj T,
	interval time.Duration,
) *ConditionedReconciler[T]

NewConditionedReconciler creates a new Typed ConditionedReconciler. Objects will be reconciled at the given interval.

func (*ConditionedReconciler[T]) AddPostHook

func (r *ConditionedReconciler[T]) AddPostHook(fn func(context.Context, T) error)

AddPostHook adds a function to be called after the conditions are evaluated. Functions are executed in first-in/first-out order. Post-hooks are AFTER conditions, and AFTER the object status has been updated. To skip the remaining post-hooks, return `ErrSkipReconciliation`.

func (*ConditionedReconciler[T]) AddPreHook

func (r *ConditionedReconciler[T]) AddPreHook(fn func(context.Context, T) error)

AddPreHook adds a function to be called before the conditions are evaluated. Functions are executed in first-in/first-out order. A failure in a pre-hook will prevent the conditions from being evaluated. To completely skip reconciliation, return `ErrSkipReconciliation`.

func (*ConditionedReconciler[T]) Reconcile

Reconcile reconciles the object with the given request. implements the `AnyConditionedReconciler` and `reconcile.Reconciler` interfaces.

func (*ConditionedReconciler[T]) SetCondition

func (r *ConditionedReconciler[T]) SetCondition(ct ConditionType, fn func(context.Context, T) error)

SetCondition sets a reconcile function for the given condition type.

func (*ConditionedReconciler[T]) SetFinalizer

func (r *ConditionedReconciler[T]) SetFinalizer(finalizer string, fn func(context.Context, T) error)

SetFinalizer sets the finalizer name and function for the reconciler. Only one finalizer per controller.

type ConditionedStatus

type ConditionedStatus struct {
	// Conditions of the resource.
	// +optional
	Conditions []Condition `json:"conditions,omitempty"`
}

A ConditionedStatus reflects the observed status of a resource. Only one condition of each type may exist.

func NewConditionedStatus

func NewConditionedStatus(c ...Condition) *ConditionedStatus

NewConditionedStatus returns a stat with the supplied conditions set.

func (*ConditionedStatus) AllTrue

func (s *ConditionedStatus) AllTrue(condTypes ...ConditionType) bool

AllTrue returns true if all of the supplied condition types are true.

func (*ConditionedStatus) AnyUnknown

func (s *ConditionedStatus) AnyUnknown(condTypes ...ConditionType) bool

AnyUnknown returns true if any of the supplied condition types are unknown.

func (*ConditionedStatus) DeepCopy

func (in *ConditionedStatus) DeepCopy() *ConditionedStatus

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConditionedStatus.

func (*ConditionedStatus) DeepCopyInto

func (in *ConditionedStatus) DeepCopyInto(out *ConditionedStatus)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*ConditionedStatus) Equal

func (s *ConditionedStatus) Equal(other *ConditionedStatus) bool

Equal returns true if the status is identical to the supplied status, ignoring the LastTransitionTimes and order of statuses.

func (*ConditionedStatus) ErrAllTrue

func (s *ConditionedStatus) ErrAllTrue(condTypes ...ConditionType) error

ErrAllTrue returns an error containing all of the supplied condition types that are NOT true. All conditions must have the same ObservedGeneration.

func (*ConditionedStatus) GetCondition

func (s *ConditionedStatus) GetCondition(ct ConditionType) Condition

GetCondition returns the condition for the given ConditionType if exists, otherwise returns an unknown condition.

func (*ConditionedStatus) IsAvailable

func (s *ConditionedStatus) IsAvailable() bool

IsAvailable returns true if the resource is available.

func (*ConditionedStatus) SetConditions

func (s *ConditionedStatus) SetConditions(c ...Condition)

SetConditions sets the supplied conditions, replacing any existing conditions of the same type. This is a no-op if all supplied conditions are identical, ignoring the last transition time, to those already set.

type ConditionedType

type ConditionedType interface {
	client.Object
	ConditionedStatus() *ConditionedStatus
	InitializeConditionedStatus()
}

ConditionedType is an interface for objects that have a ConditionedStatus. See `condition.ConditionedStatus` for more information. +kubebuilder:object:generate=false

type FinalizerFunc

type FinalizerFunc[T ConditionedType] func(context.Context, T) error

FinalizerFunc is a function that finalizes an object. +kubebuilder:object:generate=false

type ReconcilerContext

type ReconcilerContext struct {
	ForceUpdate       bool
	ForceRequeue      bool
	ReconcileInterval time.Duration
}

func GetReconcilerContext

func GetReconcilerContext(ctx context.Context) *ReconcilerContext

GetReconcilerContext retrieves the ReconcilerContext from the context.

func (*ReconcilerContext) DeepCopy

func (in *ReconcilerContext) DeepCopy() *ReconcilerContext

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReconcilerContext.

func (*ReconcilerContext) DeepCopyInto

func (in *ReconcilerContext) DeepCopyInto(out *ReconcilerContext)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

Source Files

  • condition.go
  • conditioned_reconciler.go
  • docs.go
  • helpers.go
  • zz_generated.deepcopy.go

Jump to

Keyboard shortcuts

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