Documentation
¶
Index ¶
- Constants
- func ControllerName(kind string) string
- func IsReadyAssessed(err error) bool
- func ReadyAssessed(err error) error
- type CriticalAnnotationUpdateFn
- type CriticalAnnotationUpdater
- type ExternalClient
- type ExternalClientFns
- func (e ExternalClientFns) Create(ctx context.Context, mg resource.Managed) error
- func (e ExternalClientFns) Delete(ctx context.Context, mg resource.Managed) error
- func (e ExternalClientFns) Observe(ctx context.Context, mg resource.Managed) (ExternalObservation, error)
- func (e ExternalClientFns) Update(ctx context.Context, mg resource.Managed) error
- type ExternalConnectDisconnecter
- type ExternalConnectDisconnecterFns
- type ExternalConnecter
- type ExternalConnectorFn
- type ExternalDisconnecter
- type ExternalDisconnectorFn
- type ExternalObservation
- type MetricsRecorder
- type NopClient
- func (c *NopClient) Create(ctx context.Context, mg resource.Managed) error
- func (c *NopClient) Delete(ctx context.Context, mg resource.Managed) error
- func (c *NopClient) Observe(ctx context.Context, mg resource.Managed) (ExternalObservation, error)
- func (c *NopClient) Update(ctx context.Context, mg resource.Managed) error
- type NopConnecter
- type NopDisconnecter
- type PollIntervalHook
- type RateLimitKeyer
- type RateLimitKeysProvider
- type Reconciler
- type ReconcilerOption
- func WithCreateRecoveryGracePeriod(d time.Duration) ReconcilerOption
- func WithCreateRecoveryReobserveInterval(d time.Duration) ReconcilerOption
- func WithCreationGracePeriod(d time.Duration) ReconcilerOption
- func WithCriticalAnnotationUpdater(u CriticalAnnotationUpdater) ReconcilerOption
- func WithExternalConnectDisconnecter(c ExternalConnectDisconnecter) ReconcilerOption
- func WithExternalConnecter(c ExternalConnecter) ReconcilerOption
- func WithFinalizer(f resource.Finalizer) ReconcilerOption
- func WithLogger(l logging.Logger) ReconcilerOption
- func WithMetrics(m MetricsRecorder) ReconcilerOption
- func WithPollInterval(after time.Duration) ReconcilerOption
- func WithPollIntervalHook(hook PollIntervalHook) ReconcilerOption
- func WithPollJitterHook(jitter time.Duration) ReconcilerOption
- func WithRateLimitGovernor(g *ratelimit.Governor) ReconcilerOption
- func WithRecorder(er event.Recorder) ReconcilerOption
- func WithThrottledRecorder(er event.Recorder) ReconcilerOption
- func WithTimeout(duration time.Duration) ReconcilerOption
- type RetryingCriticalAnnotationUpdater
Constants ¶
const ( // FinalizerName is the string that is used as finalizer on managed resource // objects. FinalizerName = "finalizer.managedresource.krateo.io" )
const ReasonReadyNotSetAfterObserve event.Reason = "ReadyNotSetAfterObserve"
Event reasons. ReasonReadyNotSetAfterObserve is the reason of the Warning event the runtime records when a provider breaks the Ready contract: Observe succeeded but left Ready at NotObserved. Exported so providers' tests can assert on the event. See the Ready contract on ExternalClient.Observe.
Variables ¶
This section is empty.
Functions ¶
func ControllerName ¶
ControllerName returns the recommended name for controllers that use this package to reconcile a particular kind of managed resource.
func IsReadyAssessed ¶ added in v1.8.0
IsReadyAssessed reports whether err, or any error it wraps, was marked with ReadyAssessed. It is false for a nil error.
func ReadyAssessed ¶ added in v1.8.0
ReadyAssessed marks err, returned by Connect or Observe, as one that does not concern readiness: the provider set the Ready condition itself during this call, and the error is about something else (for example a write that failed after the external resource was read). The runtime then leaves Ready as the provider set it, instead of setting it to NotObserved. Synced still reports err as a ReconcileError. See the Ready contract on ExternalClient.Observe.
Wrap only when the provider really set Ready on this call. An error that means "I could not tell" must not be wrapped: there Ready=NotObserved is the truthful answer.
The message of the returned error is err's, and errors.Is, errors.As and errors.Unwrap see through it to err. ReadyAssessed(nil) returns nil, so
return obs, reconciler.ReadyAssessed(err)
is safe whether or not err is nil.
Types ¶
type CriticalAnnotationUpdateFn ¶
A CriticalAnnotationUpdateFn may be used when it is critical that annotations must be updated before returning from the Reconcile loop.
func (CriticalAnnotationUpdateFn) UpdateCriticalAnnotations ¶
func (fn CriticalAnnotationUpdateFn) UpdateCriticalAnnotations(ctx context.Context, o client.Object) error
UpdateCriticalAnnotations of the supplied object.
type CriticalAnnotationUpdater ¶
type CriticalAnnotationUpdater interface {
UpdateCriticalAnnotations(ctx context.Context, o client.Object) error
}
A CriticalAnnotationUpdater is used when it is critical that annotations must be updated before returning from the Reconcile loop.
type ExternalClient ¶
type ExternalClient interface {
// Observe the external resource the supplied Managed resource
// represents, if any. Observe implementations must not modify the
// external resource, but may update the supplied Managed resource to
// reflect the state of the external resource. Status modifications are
// automatically persisted unless ResourceLateInitialized is true - see
// ResourceLateInitialized for more detail.
//
// When the external resource does not exist, return ResourceExists: false
// with a nil error. An error ends the reconcile before Create and before
// an unresolved create handshake can be resolved, which needs Observe's
// answer. Before returning an error, ask whether answering
// ResourceExists: false could make Create duplicate the resource. If not,
// answer. If so, return an error only for a transient failure that a
// retry can resolve; a permanent one (for example a local template that
// never renders) keeps the resource stuck until the provider changes.
// See docs/overview.md.
//
// Every Observe that returns a nil error must set the Ready condition on
// mg, on every path, including those that report ResourceExists: false.
// When Connect or Observe returns an error, the runtime sets Ready to
// NotObserved (Status Unknown) next to the error on Synced, unless Ready
// is Deleting or the error is wrapped with ReadyAssessed, which an Observe
// returns when it set Ready itself and the error concerns something else.
// The runtime never sets Ready on recovery: a successful Observe that
// leaves Ready at NotObserved is reported as a provider defect.
// reconcilertest.AssertObserveSetsReady checks this in a provider's tests.
Observe(ctx context.Context, mg resource.Managed) (ExternalObservation, error)
// Create an external resource per the specifications of the supplied
// Managed resource. Called when Observe reports that the associated
// external resource does not exist. Create implementations may update
// managed resource annotations, and those updates will be persisted.
// All other updates will be discarded.
Create(ctx context.Context, mg resource.Managed) error
// Update the external resource represented by the supplied Managed
// resource, if necessary. Called unless Observe reports that the
// associated external resource is up to date.
Update(ctx context.Context, mg resource.Managed) error
// Delete the external resource upon deletion of its associated Managed
// resource. Called when the managed resource has been deleted.
Delete(ctx context.Context, mg resource.Managed) error
}
An ExternalClient manages the lifecycle of an external resource. None of the calls here should be blocking. All of the calls should be idempotent. For example, Create call should not return AlreadyExists error if it's called again with the same parameters or Delete call should not return error if there is an ongoing deletion or resource does not exist.
type ExternalClientFns ¶
type ExternalClientFns struct {
ObserveFn func(ctx context.Context, mg resource.Managed) (ExternalObservation, error)
CreateFn func(ctx context.Context, mg resource.Managed) error
UpdateFn func(ctx context.Context, mg resource.Managed) error
DeleteFn func(ctx context.Context, mg resource.Managed) error
}
ExternalClientFns are a series of functions that satisfy the ExternalClient interface.
func (ExternalClientFns) Create ¶
Create an external resource per the specifications of the supplied Managed resource.
func (ExternalClientFns) Delete ¶
Delete the external resource upon deletion of its associated Managed resource.
func (ExternalClientFns) Observe ¶
func (e ExternalClientFns) Observe(ctx context.Context, mg resource.Managed) (ExternalObservation, error)
Observe the external resource the supplied Managed resource represents, if any.
type ExternalConnectDisconnecter ¶
type ExternalConnectDisconnecter interface {
ExternalConnecter
ExternalDisconnecter
}
An ExternalConnectDisconnecter produces a new ExternalClient given the supplied Managed resource.
func NewNopDisconnecter ¶
func NewNopDisconnecter(c ExternalConnecter) ExternalConnectDisconnecter
NewNopDisconnecter converts an ExternalConnecter into an ExternalConnectDisconnecter with a no-op Disconnect method.
type ExternalConnectDisconnecterFns ¶
type ExternalConnectDisconnecterFns struct {
ConnectFn func(ctx context.Context, mg resource.Managed) (ExternalClient, error)
DisconnectFn func(ctx context.Context) error
}
ExternalConnectDisconnecterFns are functions that satisfy the ExternalConnectDisconnecter interface.
func (ExternalConnectDisconnecterFns) Connect ¶
func (fns ExternalConnectDisconnecterFns) Connect(ctx context.Context, mg resource.Managed) (ExternalClient, error)
Connect to the provider specified by the supplied managed resource and produce an ExternalClient.
func (ExternalConnectDisconnecterFns) Disconnect ¶
func (fns ExternalConnectDisconnecterFns) Disconnect(ctx context.Context) error
Disconnect from the provider and close the ExternalClient.
type ExternalConnecter ¶
type ExternalConnecter interface {
// Connect to the provider specified by the supplied managed resource and
// produce an ExternalClient.
Connect(ctx context.Context, mg resource.Managed) (ExternalClient, error)
}
An ExternalConnecter produces a new ExternalClient given the supplied Managed resource.
type ExternalConnectorFn ¶
An ExternalConnectorFn is a function that satisfies the ExternalConnecter interface.
func (ExternalConnectorFn) Connect ¶
func (ec ExternalConnectorFn) Connect(ctx context.Context, mg resource.Managed) (ExternalClient, error)
Connect to the provider specified by the supplied managed resource and produce an ExternalClient.
type ExternalDisconnecter ¶
type ExternalDisconnecter interface {
// Disconnect from the provider and close the ExternalClient.
Disconnect(ctx context.Context) error
}
An ExternalDisconnecter disconnects from a provider.
type ExternalDisconnectorFn ¶
An ExternalDisconnectorFn is a function that satisfies the ExternalConnecter interface.
func (ExternalDisconnectorFn) Disconnect ¶
func (ed ExternalDisconnectorFn) Disconnect(ctx context.Context) error
Disconnect from provider and close the ExternalClient.
type ExternalObservation ¶
type ExternalObservation struct {
// ResourceExists must be true if a corresponding external resource exists
// for the managed resource. Typically this is proven by the presence of an
// external resource of the expected kind whose unique identifier matches
// the managed resource's external name. The Provider Runtime uses this information to
// determine whether it needs to create or delete the external resource.
ResourceExists bool
// ResourceUpToDate should be true if the corresponding external resource
// appears to be up-to-date - i.e. updating the external resource to match
// the desired state of the managed resource would be a no-op. Keep in mind
// that often only a subset of external resource fields can be updated.
// The Provider Runtime uses this information to determine whether it needs to update
// the external resource.
ResourceUpToDate bool
// ResourceLateInitialized should be true if the managed resource's spec was
// updated during its observation. A provider may update a
// managed resource's spec fields after it is created or updated, as long as
// the updates are limited to setting previously unset fields, and adding
// keys to maps. Provider Runtime uses this information to determine whether
// changes to the spec were made during observation that must be persisted.
// Note that changes to the spec will be persisted before changes to the
// status, and that pending changes to the status may be lost when the spec
// is persisted. Status changes will be persisted by the first subsequent
// observation that _does not_ late initialize the managed resource, so it
// is important that Observe implementations do not late initialize the
// resource every time they are called.
ResourceLateInitialized bool
// Diff is a Debug level message that is sent to the reconciler when
// there is a change in the observed Managed Resource. It is useful for
// finding where the observed diverges from the desired state.
// The string should be a cmp.Diff that details the difference.
Diff string
}
An ExternalObservation is the result of an observation of an external resource.
type MetricsRecorder ¶
type MetricsRecorder interface {
RecordGetDuration(ctx context.Context, d time.Duration)
IncGetFailure(ctx context.Context)
RecordConnectDuration(ctx context.Context, d time.Duration)
IncConnectFailure(ctx context.Context)
RecordObserveDuration(ctx context.Context, d time.Duration)
IncObserveFailure(ctx context.Context)
RecordCreateDuration(ctx context.Context, d time.Duration)
IncCreateFailure(ctx context.Context)
RecordUpdateDuration(ctx context.Context, d time.Duration)
IncUpdateFailure(ctx context.Context)
RecordDeleteDuration(ctx context.Context, d time.Duration)
IncDeleteFailure(ctx context.Context)
RecordFinalizerAddDuration(ctx context.Context, d time.Duration)
IncFinalizerAddFailure(ctx context.Context)
RecordFinalizerRemoveDuration(ctx context.Context, d time.Duration)
IncFinalizerRemoveFailure(ctx context.Context)
RecordStatusUpdateDuration(ctx context.Context, d time.Duration)
IncStatusUpdateFailure(ctx context.Context)
RecordReconcileDuration(ctx context.Context, d time.Duration)
IncReconcileSuccess(ctx context.Context)
IncReconcileFailure(ctx context.Context)
IncReconcileRequeueAfter(ctx context.Context)
IncReconcileRequeueImmediate(ctx context.Context)
IncReconcileErrorRequeue(ctx context.Context)
AddReconcileInFlight(delta int64)
}
MetricsRecorder records high-level reconcile metrics.
type NopClient ¶
type NopClient struct{}
A NopClient does nothing.
type NopConnecter ¶
type NopConnecter struct{}
A NopConnecter does nothing.
func (*NopConnecter) Connect ¶
func (c *NopConnecter) Connect(_ context.Context, _ resource.Managed) (ExternalClient, error)
Connect returns a NopClient. It never returns an error.
type NopDisconnecter ¶
type NopDisconnecter struct {
// contains filtered or unexported fields
}
A NopDisconnecter converts an ExternalConnecter into an ExternalConnectDisconnecter with a no-op Disconnect method.
func (*NopDisconnecter) Connect ¶
func (c *NopDisconnecter) Connect(ctx context.Context, mg resource.Managed) (ExternalClient, error)
Connect calls the underlying ExternalConnecter's Connect method.
func (*NopDisconnecter) Disconnect ¶
func (c *NopDisconnecter) Disconnect(_ context.Context) error
Disconnect does nothing. It never returns an error.
type PollIntervalHook ¶
PollIntervalHook represents the function type passed to the WithPollIntervalHook option to support dynamic computation of the poll interval.
type RateLimitKeyer ¶ added in v1.9.0
RateLimitKeyer names the rate-limited scope a managed resource's external calls belong to, typically the endpoint host, or host|credential when the quota is per identity. It must not do I/O: it is called before every gated call, including when the endpoint is throttled.
It is needed only for per-endpoint API rate limits. Implement it on the ExternalConnecter, the ExternalClient, or both. With a Governor configured (WithRateLimitGovernor):
- Connect is gated on the connecter's key, when the connecter implements it.
- Observe, Create, Update and Delete are gated on the client's key, or on the connecter's when only the connecter implements it.
- A connecter and client that implement neither are not gated per endpoint. With saturation enabled, their calls still need a slot in the process-wide local capacity: saturation bounds every gated call.
Key on the credential's reference (for example the Secret's namespace and name), never its value: credentials rotate, and a key that changes on rotation splits one quota into several, each believing it has all of it. Return the same string the provider reports in ratelimit.Signal.Key (for an HTTP API, httpsignal.HostKey of its base URL), or signals throttle a key no call is gated on.
An empty key means the object's calls are not gated per endpoint. An error is a provider defect: the call proceeds without per-endpoint gating (still bounded by saturation when that is on), and the runtime logs it once per object.
type RateLimitKeysProvider ¶ added in v1.10.0
RateLimitKeysProvider is RateLimitKeyer for an object whose calls reach several rate-limited scopes, such as a sync from one endpoint to another. One key can't describe that honestly: a throttled scope the call isn't gated on keeps being called, and a single shared key slows the healthy scope too.
A gated call then needs a slot in every key plus the local one, all or nothing, and is deferred when any of them is held or full. Its deferral names the key that stopped it. Return only the scopes the object's calls really reach, so return one key for an object whose endpoints are the same.
Everything RateLimitKeyer says about keys holds for each one: it must not do I/O, key on the credential's reference, and return the strings the provider reports in ratelimit.Signal.Key. Implement it on the ExternalConnecter, the ExternalClient, or both; it follows the same rules as RateLimitKeyer, and wins on a type that implements both. Empty keys are ignored. A nil or empty result means the object's calls are not gated per endpoint, and an error is treated as for RateLimitKeyer.
type Reconciler ¶
type Reconciler struct {
// contains filtered or unexported fields
}
A Reconciler reconciles managed resources by creating and managing the lifecycle of an external resource, i.e. a resource in an external system such as a cloud provider API. Each controller must watch the managed resource kind for which it is responsible.
func NewReconciler ¶
func NewReconciler(m manager.Manager, of resource.ManagedKind, o ...ReconcilerOption) *Reconciler
NewReconciler returns a Reconciler that reconciles managed resources of the supplied ManagedKind with resources in an external system such as a cloud provider API. It panics if asked to reconcile a managed resource kind that is not registered with the supplied manager's runtime.Scheme. The returned Reconciler reconciles with a dummy, no-op 'external system' by default; callers should supply an ExternalConnector that returns an ExternalClient capable of managing resources in a real system.
type ReconcilerOption ¶
type ReconcilerOption func(*Reconciler)
A ReconcilerOption configures a Reconciler.
func WithCreateRecoveryGracePeriod ¶ added in v1.4.0
func WithCreateRecoveryGracePeriod(d time.Duration) ReconcilerOption
WithCreateRecoveryGracePeriod specifies how long an UNRESOLVED create handshake keeps refusing before the reconciler concludes the create never reached the external system and retries it.
This is the confirm-the-negative window. Inside it nothing is recreated, so a create that DID land but is not yet visible in an eventually-consistent API is adopted rather than duplicated. Once it elapses with the resource still absent, refusing further would strand the resource forever — see the recovery branch in Reconcile. Defaults to 2 minutes.
Providers whose external API is slower to converge should raise this. Setting it to zero makes recovery retry immediately, which is only safe when the external API is strongly consistent.
func WithCreateRecoveryReobserveInterval ¶ added in v1.4.0
func WithCreateRecoveryReobserveInterval(d time.Duration) ReconcilerOption
WithCreateRecoveryReobserveInterval specifies how soon to re-observe an unresolved create while still inside the recovery grace period. Defaults to 15 seconds.
func WithCreationGracePeriod ¶
func WithCreationGracePeriod(d time.Duration) ReconcilerOption
WithCreationGracePeriod configures an optional period during which we will wait for the external API to report that a newly created external resource exists. This allows us to tolerate eventually consistent APIs that do not immediately report that newly created resources exist when queried. All resources have a 30 second grace period by default.
func WithCriticalAnnotationUpdater ¶
func WithCriticalAnnotationUpdater(u CriticalAnnotationUpdater) ReconcilerOption
WithCriticalAnnotationUpdater specifies how the Reconciler should update a managed resource's critical annotations. Implementations typically contain some kind of retry logic to increase the likelihood that critical annotations (like non-deterministic external names) will be persisted.
func WithExternalConnectDisconnecter ¶
func WithExternalConnectDisconnecter(c ExternalConnectDisconnecter) ReconcilerOption
WithExternalConnectDisconnecter specifies how the Reconciler should connect and disconnect to the API used to sync and delete external resources.
func WithExternalConnecter ¶
func WithExternalConnecter(c ExternalConnecter) ReconcilerOption
WithExternalConnecter specifies how the Reconciler should connect to the API used to sync and delete external resources.
func WithFinalizer ¶
func WithFinalizer(f resource.Finalizer) ReconcilerOption
WithFinalizer specifies how the Reconciler should add and remove finalizers to and from the managed resource.
func WithLogger ¶
func WithLogger(l logging.Logger) ReconcilerOption
WithLogger specifies how the Reconciler should log messages.
func WithMetrics ¶
func WithMetrics(m MetricsRecorder) ReconcilerOption
WithMetrics specifies how the Reconciler should record telemetry.
func WithPollInterval ¶
func WithPollInterval(after time.Duration) ReconcilerOption
WithPollInterval specifies how long the Reconciler should wait before queueing a new reconciliation after a successful reconcile. The Reconciler requeues after a specified duration when it is not actively waiting for an external operation, but wishes to check whether an existing external resource needs to be synced to its Managed resource.
func WithPollIntervalHook ¶
func WithPollIntervalHook(hook PollIntervalHook) ReconcilerOption
WithPollIntervalHook adds a hook that can be used to configure the delay before an up-to-date resource is reconciled again after a successful reconcile. If this option is passed multiple times, only the latest hook will be used.
func WithPollJitterHook ¶
func WithPollJitterHook(jitter time.Duration) ReconcilerOption
WithPollJitterHook adds a simple PollIntervalHook to add jitter to the poll interval used when queuing a new reconciliation after a successful reconcile. The added jitter will be a random duration between -jitter and +jitter. This option wraps WithPollIntervalHook, and is subject to the same constraint that only the latest hook will be used.
func WithRateLimitGovernor ¶ added in v1.9.0
func WithRateLimitGovernor(g *ratelimit.Governor) ReconcilerOption
WithRateLimitGovernor gates Connect and every ExternalClient call through g, for connecters and clients that implement RateLimitKeyer, and installs g as the ratelimit sink of the context those calls receive, so ratelimit.Report reaches it. A deferred call is not made: the pass writes Synced=False/ReconcileDeferred, leaves Ready unchanged, and requeues after the deferral's delay with a nil error, so no failure backoff is consumed. The one exception is a deferral on the startup ramp, which requeues quietly; see deferReconcile.
Share one Governor across the process's reconcilers; each one registers with it, which raises its ceiling by MaxConcurrentReconciles. Build it with controller.Options.SetupRateLimitGovernor, which also adds it to the manager so its saturation sampler runs. A nil g, the default, gates nothing and leaves Report a no-op, so
reconciler.WithRateLimitGovernor(o.RateLimitGovernor)
is safe whether or not the provider's chart enabled the governor.
func WithRecorder ¶
func WithRecorder(er event.Recorder) ReconcilerOption
WithRecorder specifies how the Reconciler should record events.
func WithThrottledRecorder ¶
func WithThrottledRecorder(er event.Recorder) ReconcilerOption
WithThrottledRecorder specifies a separate event recorder for events that are emitted when an error is encountered during reconciliation. This allows users of the Reconciler to choose to emit these events at a different level (e.g. Warning instead of Normal) without having to use the same level for all events. Defaults to the same recorder as the one set by WithRecorder if not specified.
func WithTimeout ¶
func WithTimeout(duration time.Duration) ReconcilerOption
WithTimeout specifies the timeout duration cumulatively for all the calls happen in the reconciliation function. In case the deadline exceeds, reconciler will still have some time to make the necessary calls to report the error such as status update.
type RetryingCriticalAnnotationUpdater ¶
type RetryingCriticalAnnotationUpdater struct {
// contains filtered or unexported fields
}
A RetryingCriticalAnnotationUpdater is a CriticalAnnotationUpdater that retries annotation updates in the face of API server errors.
func NewRetryingCriticalAnnotationUpdater ¶
func NewRetryingCriticalAnnotationUpdater(c client.Client) *RetryingCriticalAnnotationUpdater
NewRetryingCriticalAnnotationUpdater returns a CriticalAnnotationUpdater that retries annotation updates in the face of API server errors.
func (*RetryingCriticalAnnotationUpdater) UpdateCriticalAnnotations ¶
func (u *RetryingCriticalAnnotationUpdater) UpdateCriticalAnnotations(ctx context.Context, o client.Object) error
UpdateCriticalAnnotations updates (i.e. persists) the annotations of the supplied Object. It retries in the face of any API server error several times in order to ensure annotations that contain critical state are persisted. Any pending changes to the supplied Object's spec, status, or other metadata are reset to their current state according to the API server.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package reconcilertest helps providers test their ExternalClient against the contracts pkg/reconciler relies on.
|
Package reconcilertest helps providers test their ExternalClient against the contracts pkg/reconciler relies on. |