Documentation ¶
Index ¶
- Constants
- func DefaultCreateFunc[T any, Obj types.FSMResource[T]](req ctrl.Request) Obj
- func GetUnreadyResources(ctx context.Context, c client.Client, scheme *runtime.Scheme, ...) ([]client.Object, error)
- func MakeCustomReadyFunc[T any](readyFunc func(T) bool) customResourceReadyFunc
- func WithGetUnreadyResourcesFn(...) func(*transitionWhenReadyOpts)
- func WithRequeueAfter(requeueAfter time.Duration) func(*transitionWhenReadyOpts)
- func WithResources(resources ...client.Object) func(*transitionWhenReadyOpts)
- type GetUnreadyResourcesOption
- type MetricsOptions
- type OutputObject
- type OutputSet
- func (s *OutputSet) Apply(o client.Object, applyOpts ...io.ApplyOption)
- func (s *OutputSet) ApplyAll(objs ...client.Object)
- func (s *OutputSet) Delete(o client.Object)
- func (s *OutputSet) DeleteByRef(typedObjRef api.TypedObjectRef)
- func (s *OutputSet) GetApplied() *sets.ObjectSet
- func (s *OutputSet) GetDeleted() *sets.ObjectSet
- func (s *OutputSet) ListApplied() []client.Object
- func (s *OutputSet) ListAppliedOutputs() []OutputObject
- func (s *OutputSet) ListDeleted() []client.Object
- type ReconcilerOptions
- type ResourceManagerObject
- type Result
- func DoneAndRequeueResult(msg string, requeueAfter time.Duration) Result
- func DoneResult() Result
- func ErrorResult(err error) Result
- func ErrorResultWithReason(err error, reason string) Result
- func ErrorResultf(format string, args ...any) Result
- func RequeueResult(msg string, requeueAfter time.Duration) Result
- func RequeueResultWithBackoff(msg string) Result
- func RequeueResultWithReason(msg string, reason string, requeueAfter time.Duration) Result
- func RequeueResultWithReasonAndBackoff(msg, reason string) Result
- type State
- type TransitionFunc
- type TransitionWhenReadyOption
Constants ¶
const ( // DefaultErrorReason is the default status condition reason used for reconciler errors. DefaultErrorReason = "InternalError" // DefaultRequeueReason is the default status condition reason used for reconciler requeues. DefaultRequeueReason = "WaitingForCondition" )
Variables ¶
This section is empty.
Functions ¶
func DefaultCreateFunc ¶
func DefaultCreateFunc[T any, Obj types.FSMResource[T]](req ctrl.Request) Obj
DefaultCreateFunc is the default CreateFunc invoked if CreateFunc is not specified.
func GetUnreadyResources ¶
func GetUnreadyResources( ctx context.Context, c client.Client, scheme *runtime.Scheme, log *zap.SugaredLogger, obj ResourceManagerObject, options ...GetUnreadyResourcesOption, ) ([]client.Object, error)
GetUnreadyResources returns a list of child resources managed by obj that are not marked as ready, determined by reading the state of the child resources from the kube-apiserver. This function understands readiness of Achilles CRDs, and can be extended with custom resource readiness checks by providing a list of customResourceReadyFunc.
Custom resource checks are performed in the order they are provided, with the first matching readiness function that returns ready determining the readiness of the resource. The resource is considered unready if and only if no custom readiness function matches and returns true.
func MakeCustomReadyFunc ¶
MakeCustomReadyFunc creates a customResourceReadyFunc from a function that determines if a resource is ready.
func WithGetUnreadyResourcesFn ¶
func WithGetUnreadyResourcesFn(fn func( ctx context.Context, c client.Client, scheme *runtime.Scheme, log *zap.SugaredLogger, obj ResourceManagerObject, options ...GetUnreadyResourcesOption, ) ([]client.Object, error)) func(*transitionWhenReadyOpts)
WithGetUnreadyResourcesFn sets the function to use for getting unready resources in TransitionWhenReady. If not set, GetUnreadyResources is used.
func WithRequeueAfter ¶
WithRequeueAfter sets the requeue duration for TransitionWhenReady. If not set, the default is 10 seconds.
func WithResources ¶
WithResources sets the resources to check for readiness in TransitionWhenReady. If not set, all child resources of the parent object are checked.
Types ¶
type GetUnreadyResourcesOption ¶
type GetUnreadyResourcesOption func(*getUnreadyResourcesOptions)
GetUnreadyResourcesOption adds optional semantics to GetUnreadyResources.
func WithCustomReadyFuncs ¶
func WithCustomReadyFuncs(customReadyFuncs ...customResourceReadyFunc) GetUnreadyResourcesOption
WithCustomReadyFuncs adds custom resource readiness checks to GetUnreadyResources.
type MetricsOptions ¶
type MetricsOptions struct { // ConditionTypes is a list of additional condition types for which to instrument status condition metrics. ConditionTypes []api.ConditionType }
MetricsOptions are options for tuning the metrics instrumentation of this reconciler.
type OutputObject ¶
type OutputObject struct { Object client.Object ApplyOpts []io.ApplyOption }
OutputObject is a tuple of an object and an optional list of client apply options.
type OutputSet ¶
type OutputSet struct {
// contains filtered or unexported fields
}
OutputSet represents a set of objects that should be applied (with optional client apply options) to the server and that should be deleted from the server.
func NewOutputSet ¶
NewOutputSet returns a new OutputSet with a given scheme and objects.
func (*OutputSet) Apply ¶
func (s *OutputSet) Apply(o client.Object, applyOpts ...io.ApplyOption)
Apply signals creation or update of an object to the server, with optional client apply options.
func (*OutputSet) DeleteByRef ¶
func (s *OutputSet) DeleteByRef(typedObjRef api.TypedObjectRef)
DeleteByRef is the same as Delete, but takes an api.TypedObjectRef instead of an object.
func (*OutputSet) GetApplied ¶
GetApplied returns the set of objects to be applied.
func (*OutputSet) GetDeleted ¶
GetDeleted returns the set of objects to be deleted.
func (*OutputSet) ListApplied ¶
ListApplied returns a slice of all objects to be applied against the server.
func (*OutputSet) ListAppliedOutputs ¶
func (s *OutputSet) ListAppliedOutputs() []OutputObject
ListAppliedOutputs lists all objects from the output set along with their associated apply options.
func (*OutputSet) ListDeleted ¶
ListDeleted returns a slice of all objects to be deleted from the server.
type ReconcilerOptions ¶
type ReconcilerOptions[T any, Obj types.FSMResource[T]] struct { // CreateIfNotFound, if true, will create the object when queued for reconciliation but not found. CreateIfNotFound bool // CreateFunc, if populated, and if CreateIfNotFound is true, will be invoked to create the object when queued for reconciliation but not found. // If not populated, the object will be created with its name and namespace (if namespace-scoped) set. CreateFunc func(req ctrl.Request) Obj // DisableReadyCondition, if true, will disable injection of the status condition of type "Ready" that is otherwise // provided by default. DisableReadyCondition bool // MetricsOptions are options for tuning the metrics instrumentation of this reconciler. MetricsOptions MetricsOptions }
ReconcilerOptions are options for tuning the behavior of an FSM reconciler.
type ResourceManagerObject ¶
type ResourceManagerObject interface { client.Object // must be a k8s resource apitypes.ResourceManager // must manage a set of child resources }
type Result ¶
type Result struct { Err error Reason api.ConditionReason RequeueMsg string RequeueAfter time.Duration Done bool }
Result is the result of executing a state transition function. If err is populated, the FSM will terminate and requeue with exponential backoff. If requeueAfter is populated, the FSM will terminate and requeue with the specified duration. If done is true, the FSM will continue to the next transition function. The state's corresponding status condition's status will be False if err or requeueAfter is populated, and True if done is true. The status condition's message will be populated with the err or requeueMsg string.
func DoneAndRequeueResult ¶
DoneAndRequeueResult returns a new requeue result, which will trigger a requeue after the specified duration.
func DoneResult ¶
func DoneResult() Result
DoneResult returns a new result that signals a completed reconciliation. No retry is queued.
func ErrorResult ¶
ErrorResult returns a new error result, which will trigger a requeue with rate-limited backoff. The error will be logged and surfaced as a status condition message on the reconciled object.
func ErrorResultWithReason ¶
ErrorResultWithReason returns a new error result, which will trigger a requeue with rate-limited backoff. err is the error itself and reason is a concise upper camel case string summarizing or categorizing the error
func ErrorResultf ¶
ErrorResultf is the same as ErrorResult but performs error formatting.
func RequeueResult ¶
RequeueResult returns a new requeue result, which will trigger a requeue after the specified duration. The message will be logged and surfaced as a status condition message on the reconciled object.
func RequeueResultWithBackoff ¶
RequeueResultWithBackoff returns a new requeue result, which will trigger a requeue with exponential backoff.
func RequeueResultWithReason ¶
RequeueResultWithReason returns a new requeue result, which will trigger a requeue after the specified duration. msg is the requeue log message and reason is a concise upper camel case string summarizing or categorizing the message
func RequeueResultWithReasonAndBackoff ¶
RequeueResultWithReasonAndBackoff returns a new requeue result, which will trigger a requeue with exponential backoff. msg is the requeue log message and reason is a concise upper camel case string summarizing or categorizing the message
func (Result) Get ¶
Get resolves the Result into controller-runtime's reconcile.Result and error. If the result contains an error, the controller will log an error message and requeue with exponential backoff. Else if the result contains a requeue message without a specified duration, the controller will log an info message and requeue with exponential backoff. Else if the result contains a requeue message with a specified duration, the controller will log an info message and requeue after the specified duration. Else, the controller will not requeue.
func (Result) GetMessageAndReason ¶
func (r Result) GetMessageAndReason() (string, api.ConditionReason)
GetMessageAndReason returns the message and reason for failed states.
func (Result) HasRequeue ¶
type State ¶
type State[T client.Object] struct { // Name is the name of this state. Must be unique across all states. Name string // Transition transitions the state of the reconciler. Transition TransitionFunc[T] // Condition is an api.Condition that represents the status for this particular FSM state. // Only Type and Message should be set, all other fields are managed by the SDK, including the status, which // is set to true (if the state has completed successfully) or false, // (indicating the state has not completed successfully and will be retried). // The condition Type should be exported so they can be consumed by external systems. Condition api.Condition }
State represents a state transition function for the reconciler.
type TransitionFunc ¶
type TransitionFunc[T client.Object] func( ctx context.Context, obj T, out *OutputSet, ) (next *State[T], result Result)
TransitionFunc is a function that transitions a controller from one internal state to the next. The in ObjectSet contains the state of all resources managed by the reconciled object. The out ObjectSet is initialized as a copy of in, and the transition function is responsible for mutating the out ObjectSet until it is the intended state of resources that the controller should manage. Resources deleted from out are also deleted from the cluster. Out is shared across all states, so changes are visible to all subsequent states.
TransitionFunc can return nil as the next state to indicate that the controller has reached a terminal state. Any non-nil error aborts the controller.
func DeleteChildrenForeground ¶
func DeleteChildrenForeground[T ResourceManagerObject]( c *io.ClientApplicator, scheme *runtime.Scheme, log *zap.SugaredLogger, next *State[T], ) TransitionFunc[T]
DeleteChildrenForeground is a generic state that implements foreground cascading deletion of children resources (i.e. resources managed by the parent resource).
The state will requeue until all child resources are fully deleted. Any child resources that remain in terminating state but not deleted will cause the state to requeue.
This state is useful for preventing accidental orphaning of child resources. The parent resource's existence serves as a signal that underlying child resources have yet to be cleaned up.
See the Kubernetes documentation for more information on foreground cascading deletion: https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion/
func TransitionWhenReady ¶
func TransitionWhenReady[T ResourceManagerObject]( c client.Client, scheme *runtime.Scheme, log *zap.SugaredLogger, next *State[T], options ...TransitionWhenReadyOption, ) TransitionFunc[T]
TransitionWhenReady is a state transition function that returns the next state if all specified resources are marked Ready. If no resources are specified, the function will check all child resources of the parent object. Crossplane resources must have both Ready and Synced conditions set to True. If any in-scope resources are not ready, requeues reconcile loop in 10 seconds.
type TransitionWhenReadyOption ¶
type TransitionWhenReadyOption func(*transitionWhenReadyOpts)