Documentation
¶
Overview ¶
+kubebuilder:object:generate=true +kubebuilder:unservedversion
Index ¶
- Constants
- func ErrNoop() error
- func ErrSkipReconciliation() error
- func ErrStatusUnknown(e error) error
- func ForceRequeue(ctx context.Context)
- func ForceStatusUpdate(ctx context.Context)
- func HandleFinalizer[T ConditionedType](ctx context.Context, c client.Client, obj T, finalizer string, ...) (bool, error)
- type AnyConditionedReconciler
- type Condition
- func Available() Condition
- func Creating() Condition
- func Deleting() Condition
- func ErrorCondition(condType ConditionType, reason ConditionReason, err error) Condition
- func ReadyCondition(condType ConditionType) Condition
- func ReconcileError(err error) Condition
- func ReconcilePending() Condition
- func ReconcileSuccess() Condition
- func Unavailable() Condition
- func UnknownCondition(condType ConditionType, reason ConditionReason, message string) Condition
- type ConditionReason
- type ConditionType
- type ConditionedReconciler
- func (r *ConditionedReconciler[T]) AddPostHook(fn func(context.Context, T) error)
- func (r *ConditionedReconciler[T]) AddPreHook(fn func(context.Context, T) error)
- func (r *ConditionedReconciler[T]) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
- func (r *ConditionedReconciler[T]) SetCondition(ct ConditionType, fn func(context.Context, T) error)
- func (r *ConditionedReconciler[T]) SetFinalizer(finalizer string, fn func(context.Context, T) error)
- type ConditionedStatus
- func (s *ConditionedStatus) AllTrue(condTypes ...ConditionType) bool
- func (s *ConditionedStatus) AnyUnknown(condTypes ...ConditionType) bool
- func (in *ConditionedStatus) DeepCopy() *ConditionedStatus
- func (in *ConditionedStatus) DeepCopyInto(out *ConditionedStatus)
- func (s *ConditionedStatus) Equal(other *ConditionedStatus) bool
- func (s *ConditionedStatus) ErrAllTrue(condTypes ...ConditionType) error
- func (s *ConditionedStatus) GetCondition(ct ConditionType) Condition
- func (s *ConditionedStatus) IsAvailable() bool
- func (s *ConditionedStatus) SetConditions(c ...Condition)
- type ConditionedType
- type FinalizerFunc
- type ReconcilerContext
Constants ¶
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 ¶
ErrStatusUnknown wraps an error with a status unknown error. Used to indicate the status of a given condition is unknown during reconciliation.
func ForceRequeue ¶
ForceRequeue forces an immediate requeue, regardless if status has changed.
func ForceStatusUpdate ¶
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 ¶
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 ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Condition.
func (*Condition) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (Condition) Equal ¶
Equal returns true if the condition is identical to the supplied condition, ignoring the LastTransitionTime.
type ConditionReason ¶
type ConditionReason string
A ConditionReason represents the reason a resource is in a condition. nolint
const ( ReasonAvailable ConditionReason = "Available" 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 ¶
func (r *ConditionedReconciler[T]) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error)
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.
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