Documentation
¶
Index ¶
- Constants
- func ControllerName(kind string) string
- 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 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 Reconciler
- type 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 WithPollInterval(after time.Duration) ReconcilerOption
- func WithPollIntervalHook(hook PollIntervalHook) ReconcilerOption
- func WithPollJitterHook(jitter time.Duration) ReconcilerOption
- func WithRecorder(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" )
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.
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. 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 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 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 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 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 WithRecorder ¶
func WithRecorder(er event.Recorder) ReconcilerOption
WithRecorder specifies how the Reconciler should record events.
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.