managed

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2025 License: Apache-2.0 Imports: 34 Imported by: 152

Documentation

Overview

Package managed provides a reconciler that manages the lifecycle of a resource in an external system.

Index

Constants

View Source
const (
	// FinalizerName is the string that is used as finalizer on managed resource
	// objects.
	FinalizerName = "finalizer.managedresource.crossplane.io"
)

Variables

This section is empty.

Functions

func ControllerName

func ControllerName(kind string) string

ControllerName returns the recommended name for controllers that use this package to reconcile a particular kind of managed resource.

Types

type APILocalSecretPublisher

type APILocalSecretPublisher struct {
	// contains filtered or unexported fields
}

An APILocalSecretPublisher publishes ConnectionDetails by submitting a Secret to a Kubernetes API server.

func NewAPILocalSecretPublisher

func NewAPILocalSecretPublisher(c client.Client, ot runtime.ObjectTyper) *APILocalSecretPublisher

NewAPILocalSecretPublisher returns a new APILocalSecretPublisher.

func (*APILocalSecretPublisher) PublishConnection

PublishConnection publishes the supplied ConnectionDetails to a Secret in the same namespace as the supplied Managed resource. It is a no-op if the secret already exists with the supplied ConnectionDetails.

func (*APILocalSecretPublisher) UnpublishConnection

UnpublishConnection is no-op since PublishConnection only creates resources that will be garbage collected by Kubernetes when the managed resource is deleted.

type APISecretPublisher

type APISecretPublisher struct {
	// contains filtered or unexported fields
}

An APISecretPublisher publishes ConnectionDetails by submitting a Secret to a Kubernetes API server.

func NewAPISecretPublisher

func NewAPISecretPublisher(c client.Client, ot runtime.ObjectTyper) *APISecretPublisher

NewAPISecretPublisher returns a new APISecretPublisher.

func (*APISecretPublisher) PublishConnection

PublishConnection publishes the supplied ConnectionDetails to a Secret in the same namespace as the supplied Managed resource. It is a no-op if the secret already exists with the supplied ConnectionDetails.

func (*APISecretPublisher) UnpublishConnection

UnpublishConnection is no-op since PublishConnection only creates resources that will be garbage collected by Kubernetes when the managed resource is deleted.

type APISimpleReferenceResolver

type APISimpleReferenceResolver struct {
	// contains filtered or unexported fields
}

An APISimpleReferenceResolver resolves references from one managed resource to others by calling the referencing resource's ResolveReferences method, if any.

func NewAPISimpleReferenceResolver

func NewAPISimpleReferenceResolver(c client.Client) *APISimpleReferenceResolver

NewAPISimpleReferenceResolver returns a ReferenceResolver that resolves references from one managed resource to others by calling the referencing resource's ResolveReferences method, if any.

func (*APISimpleReferenceResolver) ResolveReferences

func (a *APISimpleReferenceResolver) ResolveReferences(ctx context.Context, mg resource.Managed) error

ResolveReferences of the supplied managed resource by calling its ResolveReferences method, if any.

type AdditionalDetails

type AdditionalDetails map[string]string

AdditionalDetails represent any additional details the external client wants to return about an operation that has been performed. These details will be included in the change logs.

type ChangeLogger

type ChangeLogger interface {
	Log(ctx context.Context, managed resource.Managed, opType v1alpha1.OperationType, changeErr error, ad AdditionalDetails) error
}

ChangeLogger is an interface for recording changes made to resources to the change logs.

type ConnectionDetails

type ConnectionDetails map[string][]byte

ConnectionDetails created or updated during an operation on an external resource, for example usernames, passwords, endpoints, ports, etc.

type ConnectionDetailsFetcher

type ConnectionDetailsFetcher interface {
	FetchConnection(ctx context.Context, so resource.ConnectionSecretOwner) (ConnectionDetails, error)
}

A ConnectionDetailsFetcher fetches connection details for the supplied Connection Secret owner.

type ConnectionPublisher

type ConnectionPublisher interface {
	// PublishConnection details for the supplied Managed resource. Publishing
	// must be additive; i.e. if details (a, b, c) are published, subsequently
	// publicing details (b, c, d) should update (b, c) but not remove a.
	PublishConnection(ctx context.Context, so resource.ConnectionSecretOwner, c ConnectionDetails) (published bool, err error)

	// UnpublishConnection details for the supplied Managed resource.
	UnpublishConnection(ctx context.Context, so resource.ConnectionSecretOwner, c ConnectionDetails) error
}

A ConnectionPublisher manages the supplied ConnectionDetails for the supplied Managed resource. ManagedPublishers must handle the case in which the supplied ConnectionDetails are empty.

type ConnectionPublisherFns

type ConnectionPublisherFns struct {
	PublishConnectionFn   func(ctx context.Context, o resource.ConnectionSecretOwner, c ConnectionDetails) (bool, error)
	UnpublishConnectionFn func(ctx context.Context, o resource.ConnectionSecretOwner, c ConnectionDetails) error
}

ConnectionPublisherFns is the pluggable struct to produce objects with ConnectionPublisher interface.

func (ConnectionPublisherFns) PublishConnection

PublishConnection details for the supplied Managed resource.

func (ConnectionPublisherFns) UnpublishConnection

UnpublishConnection details for the supplied Managed resource.

type CriticalAnnotationUpdateFn

type CriticalAnnotationUpdateFn func(ctx context.Context, o client.Object) error

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 = TypedExternalClient[resource.Managed]

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 = TypedExternalClientFns[resource.Managed]

ExternalClientFns are a series of functions that satisfy the ExternalClient interface.

type ExternalConnectDisconnecterFns

type ExternalConnectDisconnecterFns = ExternalConnectDisconnectorFns

ExternalConnectDisconnecterFns aliases ExternalConnectDisconnectorFns. Deprecated: use ExternalConnectDisconnectorFns.

type ExternalConnectDisconnector

type ExternalConnectDisconnector = TypedExternalConnectDisconnector[resource.Managed]

An ExternalConnectDisconnector produces a new ExternalClient given the supplied Managed resource.

func NewNopDisconnecter

func NewNopDisconnecter(c ExternalConnector) ExternalConnectDisconnector

NewNopDisconnecter an alias to NewNopDisconnector. Deprecated: use NewNopDisconnector.

func NewNopDisconnector

func NewNopDisconnector(c ExternalConnector) ExternalConnectDisconnector

NewNopDisconnector converts an ExternalConnector into an ExternalConnectDisconnector with a no-op Disconnect method.

type ExternalConnectDisconnectorFns

type ExternalConnectDisconnectorFns = TypedExternalConnectDisconnectorFns[resource.Managed]

ExternalConnectDisconnectorFns are functions that satisfy the ExternalConnectDisconnector interface.

type ExternalConnecter

type ExternalConnecter = ExternalConnector

ExternalConnecter an alias to ExternalConnector. Deprecated: use ExternalConnector.

type ExternalConnector

type ExternalConnector = TypedExternalConnector[resource.Managed]

An ExternalConnector produces a new ExternalClient given the supplied Managed resource.

type ExternalConnectorFn

type ExternalConnectorFn = TypedExternalConnectorFn[resource.Managed]

An ExternalConnectorFn is a function that satisfies the ExternalConnector interface.

type ExternalCreation

type ExternalCreation struct {
	// ConnectionDetails required to connect to this resource. These details
	// are a set that is collated throughout the managed resource's lifecycle -
	// i.e. returning new connection details will have no affect on old details
	// unless an existing key is overwritten. Crossplane may publish these
	// credentials to a store (e.g. a Secret).
	ConnectionDetails ConnectionDetails

	// AdditionalDetails represent any additional details the external client
	// wants to return about the creation operation that was performed.
	AdditionalDetails AdditionalDetails
}

An ExternalCreation is the result of the creation of an external resource.

type ExternalDelete

type ExternalDelete struct {
	// AdditionalDetails represent any additional details the external client
	// wants to return about the delete operation that was performed.
	AdditionalDetails AdditionalDetails
}

An ExternalDelete is the result of a deletion of an external resource.

type ExternalDisconnecter deprecated

type ExternalDisconnecter interface {
	ExternalDisconnector
}

ExternalDisconnecter an alias to ExternalDisconnector.

Deprecated: Please use Disconnect() on the ExternalClient for disconnecting from the provider.

type ExternalDisconnecterFn

type ExternalDisconnecterFn = ExternalDisconnectorFn

ExternalDisconnecterFn aliases ExternalDisconnectorFn. Deprecated: use ExternalDisconnectorFn.

type ExternalDisconnector deprecated

type ExternalDisconnector interface {
	// Disconnect from the provider and close the ExternalClient.
	Disconnect(ctx context.Context) error
}

An ExternalDisconnector disconnects from a provider.

Deprecated: Please use Disconnect() on the ExternalClient for disconnecting from the provider.

type ExternalDisconnectorFn

type ExternalDisconnectorFn func(ctx context.Context) error

An ExternalDisconnectorFn is a function that satisfies the ExternalConnector 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. Crossplane 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.
	// Crossplane 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 Crossplane 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. Crossplane 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

	// ConnectionDetails required to connect to this resource. These details
	// are a set that is collated throughout the managed resource's lifecycle -
	// i.e. returning new connection details will have no affect on old details
	// unless an existing key is overwritten. Crossplane may publish these
	// credentials to a store (e.g. a Secret).
	ConnectionDetails ConnectionDetails

	// 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 ExternalUpdate

type ExternalUpdate struct {
	// ConnectionDetails required to connect to this resource. These details
	// are a set that is collated throughout the managed resource's lifecycle -
	// i.e. returning new connection details will have no affect on old details
	// unless an existing key is overwritten. Crossplane may publish these
	// credentials to a store (e.g. a Secret).
	ConnectionDetails ConnectionDetails

	// AdditionalDetails represent any additional details the external client
	// wants to return about the update operation that was performed.
	AdditionalDetails AdditionalDetails
}

An ExternalUpdate is the result of an update to an external resource.

type GRPCChangeLogger

type GRPCChangeLogger struct {
	// contains filtered or unexported fields
}

GRPCChangeLogger processes changes to resources and helps to send them to the change log gRPC service.

func NewGRPCChangeLogger

NewGRPCChangeLogger creates a new gRPC based ChangeLogger initialized with the given client.

func (*GRPCChangeLogger) Log

func (g *GRPCChangeLogger) Log(ctx context.Context, managed resource.Managed, opType v1alpha1.OperationType, changeErr error, ad AdditionalDetails) error

Log sends the given change log entry to the change log service.

type GRPCChangeLoggerOption

type GRPCChangeLoggerOption func(*GRPCChangeLogger)

A GRPCChangeLoggerOption configures a GRPCChangeLoggerOption.

func WithProviderVersion

func WithProviderVersion(version string) GRPCChangeLoggerOption

WithProviderVersion sets the provider version to be included in the change log entry.

func WithSendTimeout

func WithSendTimeout(timeout time.Duration) GRPCChangeLoggerOption

WithSendTimeout sets the timeout for sending and/or waiting for change log entries to the change log service.

type Initializer

type Initializer interface {
	Initialize(ctx context.Context, mg resource.Managed) error
}

Initializer establishes ownership of the supplied Managed resource. This typically involves the operations that are run before calling any ExternalClient methods.

type InitializerChain

type InitializerChain []Initializer

A InitializerChain chains multiple managed initializers.

func (InitializerChain) Initialize

func (cc InitializerChain) Initialize(ctx context.Context, mg resource.Managed) error

Initialize calls each Initializer serially. It returns the first error it encounters, if any.

type InitializerFn

type InitializerFn func(ctx context.Context, mg resource.Managed) error

A InitializerFn is a function that satisfies the Initializer interface.

func (InitializerFn) Initialize

func (m InitializerFn) Initialize(ctx context.Context, mg resource.Managed) error

Initialize calls InitializerFn function.

type LegacyManagementPoliciesResolver

type LegacyManagementPoliciesResolver struct {
	*ManagementPoliciesResolver
	// contains filtered or unexported fields
}

LegacyManagementPoliciesResolver is used to perform management policy checks based on the management policy and if the management policy feature is enabled. Deprecated: this is for LegacyManaged types, that had deletion policy. ModernManaged resources should use ManagementPoliciesResolver.

func (*LegacyManagementPoliciesResolver) ShouldDelete

func (m *LegacyManagementPoliciesResolver) ShouldDelete() bool

ShouldDelete returns true based on the combination of the deletionPolicy and the managementPolicies. If the management policy feature is disabled, it returns true if the deletionPolicy is set to "Delete". Otherwise, it checks which field is set to a non-default value and makes a decision based on that. We need to be careful until we completely remove the deletionPolicy in favor of managementPolicies which conflict with the deletionPolicy regarding deleting of the external resource. This function implements the proposal in the Ignore Changes design doc under the "Deprecation of `deletionPolicy`".

type LocalConnectionPublisher

type LocalConnectionPublisher interface {
	// PublishConnection details for the supplied Managed resource. Publishing
	// must be additive; i.e. if details (a, b, c) are published, subsequently
	// publicing details (b, c, d) should update (b, c) but not remove a.
	PublishConnection(ctx context.Context, lso resource.LocalConnectionSecretOwner, c ConnectionDetails) (published bool, err error)

	// UnpublishConnection details for the supplied Managed resource.
	UnpublishConnection(ctx context.Context, lso resource.LocalConnectionSecretOwner, c ConnectionDetails) error
}

A LocalConnectionPublisher manages the supplied ConnectionDetails for the supplied Managed resource. ManagedPublishers must handle the case in which the supplied ConnectionDetails are empty.

type LocalConnectionPublisherFns

type LocalConnectionPublisherFns struct {
	PublishConnectionFn   func(ctx context.Context, o resource.LocalConnectionSecretOwner, c ConnectionDetails) (bool, error)
	UnpublishConnectionFn func(ctx context.Context, o resource.LocalConnectionSecretOwner, c ConnectionDetails) error
}

LocalConnectionPublisherFns is the pluggable struct to produce objects with LocalConnectionPublisher interface.

func (LocalConnectionPublisherFns) PublishConnection

PublishConnection details for the supplied Managed resource.

func (LocalConnectionPublisherFns) UnpublishConnection

UnpublishConnection details for the supplied Managed resource.

type MRMetricRecorder

type MRMetricRecorder struct {
	// contains filtered or unexported fields
}

MRMetricRecorder records the lifecycle metrics of managed resources.

func NewMRMetricRecorder

func NewMRMetricRecorder() *MRMetricRecorder

NewMRMetricRecorder returns a new MRMetricRecorder which records metrics for managed resources.

func (*MRMetricRecorder) Collect

func (r *MRMetricRecorder) Collect(ch chan<- prometheus.Metric)

Collect is called by the Prometheus registry when collecting metrics. The implementation sends each collected metric via the provided channel and returns once the last metric has been sent.

func (*MRMetricRecorder) Describe

func (r *MRMetricRecorder) Describe(ch chan<- *prometheus.Desc)

Describe sends the super-set of all possible descriptors of metrics collected by this Collector to the provided channel and returns once the last descriptor has been sent.

type ManagementPoliciesChecker

type ManagementPoliciesChecker interface {
	// Validate validates the management policies.
	Validate() error
	// IsPaused returns true if the resource is paused based
	// on the management policy.
	IsPaused() bool

	// ShouldOnlyObserve returns true if only the Observe action is allowed.
	ShouldOnlyObserve() bool
	// ShouldCreate returns true if the Create action is allowed.
	ShouldCreate() bool
	// ShouldLateInitialize returns true if the LateInitialize action is
	// allowed.
	ShouldLateInitialize() bool
	// ShouldUpdate returns true if the Update action is allowed.
	ShouldUpdate() bool
	// ShouldDelete returns true if the Delete action is allowed.
	ShouldDelete() bool
}

ManagementPoliciesChecker is used to perform checks on management policies to determine specific actions are allowed, or if they are the only allowed action.

func NewLegacyManagementPoliciesResolver

func NewLegacyManagementPoliciesResolver(managementPolicyEnabled bool, managementPolicy xpv1.ManagementPolicies, deletionPolicy xpv1.DeletionPolicy, o ...ManagementPoliciesResolverOption) ManagementPoliciesChecker

NewLegacyManagementPoliciesResolver returns an ManagementPolicyChecker based on the management policies and if the management policies feature is enabled. Deprecated: this is intended for LegacyManaged resources that had deletionPolicy ModernManaged resources should use NewManagementPoliciesResolver.

func NewManagementPoliciesResolver

func NewManagementPoliciesResolver(managementPolicyEnabled bool, managementPolicy xpv1.ManagementPolicies, o ...ManagementPoliciesResolverOption) ManagementPoliciesChecker

NewManagementPoliciesResolver returns an ManagementPolicyChecker based on the management policies and if the management policies feature is enabled.

type ManagementPoliciesResolver

type ManagementPoliciesResolver struct {
	// contains filtered or unexported fields
}

ManagementPoliciesResolver is used to perform management policy checks based on the management policy and if the management policy feature is enabled.

func (*ManagementPoliciesResolver) IsPaused

func (m *ManagementPoliciesResolver) IsPaused() bool

IsPaused returns true if the management policy is empty and the management policies feature is enabled.

func (*ManagementPoliciesResolver) ShouldCreate

func (m *ManagementPoliciesResolver) ShouldCreate() bool

ShouldCreate returns true if the Create action is allowed. If the management policy feature is disabled, it returns true.

func (*ManagementPoliciesResolver) ShouldDelete

func (m *ManagementPoliciesResolver) ShouldDelete() bool

ShouldDelete returns true based only on the managementPolicies. If the management policy feature is disabled, returns true. Otherwise, it checks whether the managementPolicies explicitly include Delete or * (all).

func (*ManagementPoliciesResolver) ShouldLateInitialize

func (m *ManagementPoliciesResolver) ShouldLateInitialize() bool

ShouldLateInitialize returns true if the LateInitialize action is allowed. If the management policy feature is disabled, it returns true.

func (*ManagementPoliciesResolver) ShouldOnlyObserve

func (m *ManagementPoliciesResolver) ShouldOnlyObserve() bool

ShouldOnlyObserve returns true if the Observe action is allowed and all other actions are not allowed. If the management policy feature is disabled, it returns false.

func (*ManagementPoliciesResolver) ShouldUpdate

func (m *ManagementPoliciesResolver) ShouldUpdate() bool

ShouldUpdate returns true if the Update action is allowed. If the management policy feature is disabled, it returns true.

func (*ManagementPoliciesResolver) Validate

func (m *ManagementPoliciesResolver) Validate() error

Validate checks if the management policy is valid. If the management policy feature is disabled, but uses a non-default value, it returns an error. If the management policy feature is enabled, but uses a non-supported value, it returns an error.

type ManagementPoliciesResolverOption

type ManagementPoliciesResolverOption func(*ManagementPoliciesResolver)

A ManagementPoliciesResolverOption configures a ManagementPoliciesResolver.

func WithSupportedManagementPolicies

func WithSupportedManagementPolicies(supportedManagementPolicies []sets.Set[xpv1.ManagementAction]) ManagementPoliciesResolverOption

WithSupportedManagementPolicies sets the supported management policies.

type MetricRecorder

type MetricRecorder interface {
	Describe(ch chan<- *prometheus.Desc)
	Collect(ch chan<- prometheus.Metric)
	// contains filtered or unexported methods
}

MetricRecorder records the managed resource metrics.

type NameAsExternalName

type NameAsExternalName struct {
	// contains filtered or unexported fields
}

NameAsExternalName writes the name of the managed resource to the external name annotation field in order to be used as name of the external resource in provider.

func NewNameAsExternalName

func NewNameAsExternalName(c client.Client) *NameAsExternalName

NewNameAsExternalName returns a new NameAsExternalName.

func (*NameAsExternalName) Initialize

func (a *NameAsExternalName) Initialize(ctx context.Context, mg resource.Managed) error

Initialize the given managed resource.

type NopClient

type NopClient struct{}

A NopClient does nothing.

func (*NopClient) Create

Create does nothing. It returns an empty ExternalCreation and no error.

func (*NopClient) Delete

Delete does nothing. It never returns an error.

func (*NopClient) Disconnect

func (c *NopClient) Disconnect(_ context.Context) error

Disconnect does nothing. It never returns an error.

func (*NopClient) Observe

Observe does nothing. It returns an empty ExternalObservation and no error.

func (*NopClient) Update

Update does nothing. It returns an empty ExternalUpdate and no error.

type NopConnecter

type NopConnecter = NopConnector

NopConnecter aliases NopConnector. Deprecated: use NopConnector.

type NopConnector

type NopConnector struct{}

A NopConnector does nothing.

func (*NopConnector) Connect

Connect returns a NopClient. It never returns an error.

type NopDisconnecter

type NopDisconnecter = NopDisconnector

NopDisconnecter aliases NopDisconnector. Deprecated: Use NopDisconnector.

type NopDisconnector

type NopDisconnector = TypedNopDisconnector[resource.Managed]

A NopDisconnector converts an ExternalConnector into an ExternalConnectDisconnector with a no-op Disconnect method.

type NopMetricRecorder

type NopMetricRecorder struct{}

A NopMetricRecorder does nothing.

func NewNopMetricRecorder

func NewNopMetricRecorder() *NopMetricRecorder

NewNopMetricRecorder returns a MRMetricRecorder that does nothing.

func (*NopMetricRecorder) Collect

func (r *NopMetricRecorder) Collect(_ chan<- prometheus.Metric)

Collect does nothing.

func (*NopMetricRecorder) Describe

func (r *NopMetricRecorder) Describe(_ chan<- *prometheus.Desc)

Describe does nothing.

type PollIntervalHook

type PollIntervalHook func(managed resource.Managed, pollInterval time.Duration) time.Duration

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.

func (*Reconciler) Reconcile

func (r *Reconciler) Reconcile(ctx context.Context, req reconcile.Request) (result reconcile.Result, err error)

Reconcile a managed resource with an external resource.

type ReconcilerOption

type ReconcilerOption func(*Reconciler)

A ReconcilerOption configures a Reconciler.

func WithChangeLogger

func WithChangeLogger(c ChangeLogger) ReconcilerOption

WithChangeLogger enables support for capturing change logs during reconciliation.

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 WithDeterministicExternalName

func WithDeterministicExternalName(b bool) ReconcilerOption

WithDeterministicExternalName specifies that the external name of the MR is deterministic. If this value is not "true", the provider will not re-queue the managed resource in scenarios where creation is deemed incomplete. This behaviour is a safeguard to avoid a leaked resource due to a non-deterministic name generated by the external system. Conversely, if this value is "true", signifying that the managed resources is deterministically named by the external system, then this safeguard is ignored as it is safe to re-queue a deterministically named resource.

func WithExternalConnectDisconnecter

func WithExternalConnectDisconnecter(c ExternalConnectDisconnector) ReconcilerOption

WithExternalConnectDisconnecter aliases WithExternalConnectDisconnector. Deprecated: Please use Disconnect() on the ExternalClient for disconnecting from the provider.

func WithExternalConnectDisconnector deprecated

func WithExternalConnectDisconnector(c ExternalConnectDisconnector) ReconcilerOption

WithExternalConnectDisconnector specifies how the Reconciler should connect and disconnect to the API used to sync and delete external resources.

Deprecated: Please use Disconnect() on the ExternalClient for disconnecting from the provider.

func WithExternalConnecter

func WithExternalConnecter(c ExternalConnector) ReconcilerOption

WithExternalConnecter aliases WithExternalConnector. Deprecated: use WithExternalConnector.

func WithExternalConnector

func WithExternalConnector(c ExternalConnector) ReconcilerOption

WithExternalConnector 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 WithInitializers

func WithInitializers(i ...Initializer) ReconcilerOption

WithInitializers specifies how the Reconciler should initialize a managed resource before calling any of the ExternalClient functions.

func WithLogger

func WithLogger(l logging.Logger) ReconcilerOption

WithLogger specifies how the Reconciler should log messages.

func WithManagementPolicies

func WithManagementPolicies() ReconcilerOption

WithManagementPolicies enables support for management policies.

func WithMetricRecorder

func WithMetricRecorder(recorder MetricRecorder) ReconcilerOption

WithMetricRecorder configures the Reconciler to use the supplied MetricRecorder.

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 Crossplane 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 WithReconcilerSupportedManagementPolicies

func WithReconcilerSupportedManagementPolicies(supported []sets.Set[xpv1.ManagementAction]) ReconcilerOption

WithReconcilerSupportedManagementPolicies configures which management policies are supported by the reconciler.

func WithRecorder

func WithRecorder(er event.Recorder) ReconcilerOption

WithRecorder specifies how the Reconciler should record events.

func WithReferenceResolver

func WithReferenceResolver(rr ReferenceResolver) ReconcilerOption

WithReferenceResolver specifies how the Reconciler should resolve any inter-resource references it encounters while reconciling managed resources.

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.

func WithTypedExternalConnectDisconnecter

func WithTypedExternalConnectDisconnecter[managed resource.Managed](c TypedExternalConnectDisconnector[managed]) ReconcilerOption

WithTypedExternalConnectDisconnecter aliases WithTypedExternalConnectDisconnector. Deprecated: Please use Disconnect() on the ExternalClient for disconnecting from the provider.

func WithTypedExternalConnectDisconnector deprecated

func WithTypedExternalConnectDisconnector[managed resource.Managed](c TypedExternalConnectDisconnector[managed]) ReconcilerOption

WithTypedExternalConnectDisconnector specifies how the Reconciler should connect and disconnect to the API used to sync and delete external resources.

Deprecated: Please use Disconnect() on the ExternalClient for disconnecting from the provider.

func WithTypedExternalConnector

func WithTypedExternalConnector[managed resource.Managed](c TypedExternalConnector[managed]) ReconcilerOption

WithTypedExternalConnector specifies how the Reconciler should connect to the API used to sync and delete external resources.

type ReferenceResolver

type ReferenceResolver interface {
	// ResolveReferences resolves all fields in the supplied managed resource
	// that are references to other managed resources by updating corresponding
	// fields, for example setting spec.network to the Network resource
	// specified by spec.networkRef.name.
	ResolveReferences(ctx context.Context, mg resource.Managed) error
}

A ReferenceResolver resolves references to other managed resources.

type ReferenceResolverFn

type ReferenceResolverFn func(context.Context, resource.Managed) error

A ReferenceResolverFn is a function that satisfies the ReferenceResolver interface.

func (ReferenceResolverFn) ResolveReferences

func (m ReferenceResolverFn) ResolveReferences(ctx context.Context, mg resource.Managed) error

ResolveReferences calls ReferenceResolverFn function.

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. Pending changes to the supplied Object's spec, status, or other metadata might get reset to their current state according to the API server, e.g. in case of a conflict error.

type TypedExternalClient

type TypedExternalClient[managedType resource.Managed] 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 managedType) (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 managedType) (ExternalCreation, 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 managedType) (ExternalUpdate, 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 managedType) (ExternalDelete, error)

	// Disconnect from the provider and close the ExternalClient.
	// Called at the end of reconcile loop. An ExternalClient not requiring
	// to explicitly disconnect to cleanup it resources, can provide a no-op
	// implementation which just return nil.
	Disconnect(ctx context.Context) error
}

A TypedExternalClient 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 TypedExternalClientFns

type TypedExternalClientFns[managed resource.Managed] struct {
	ObserveFn    func(ctx context.Context, mg managed) (ExternalObservation, error)
	CreateFn     func(ctx context.Context, mg managed) (ExternalCreation, error)
	UpdateFn     func(ctx context.Context, mg managed) (ExternalUpdate, error)
	DeleteFn     func(ctx context.Context, mg managed) (ExternalDelete, error)
	DisconnectFn func(ctx context.Context) error
}

TypedExternalClientFns are a series of functions that satisfy the ExternalClient interface.

func (TypedExternalClientFns[managed]) Create

func (e TypedExternalClientFns[managed]) Create(ctx context.Context, mg managed) (ExternalCreation, error)

Create an external resource per the specifications of the supplied Managed resource.

func (TypedExternalClientFns[managed]) Delete

func (e TypedExternalClientFns[managed]) Delete(ctx context.Context, mg managed) (ExternalDelete, error)

Delete the external resource upon deletion of its associated Managed resource.

func (TypedExternalClientFns[managed]) Disconnect

func (e TypedExternalClientFns[managed]) Disconnect(ctx context.Context) error

Disconnect the external client.

func (TypedExternalClientFns[managed]) Observe

func (e TypedExternalClientFns[managed]) Observe(ctx context.Context, mg managed) (ExternalObservation, error)

Observe the external resource the supplied Managed resource represents, if any.

func (TypedExternalClientFns[managed]) Update

func (e TypedExternalClientFns[managed]) Update(ctx context.Context, mg managed) (ExternalUpdate, error)

Update the external resource represented by the supplied Managed resource, if necessary.

type TypedExternalConnectDisconnector

type TypedExternalConnectDisconnector[managed resource.Managed] interface {
	TypedExternalConnector[managed]
	ExternalDisconnector
}

A TypedExternalConnectDisconnector produces a new ExternalClient given the supplied Managed resource.

func NewTypedNopDisconnector

func NewTypedNopDisconnector[managed resource.Managed](c TypedExternalConnector[managed]) TypedExternalConnectDisconnector[managed]

NewTypedNopDisconnector converts an TypedExternalConnector into an ExternalConnectDisconnector with a no-op Disconnect method.

type TypedExternalConnectDisconnectorFns

type TypedExternalConnectDisconnectorFns[managed resource.Managed] struct {
	ConnectFn    func(ctx context.Context, mg managed) (TypedExternalClient[managed], error)
	DisconnectFn func(ctx context.Context) error
}

TypedExternalConnectDisconnectorFns are functions that satisfy the TypedExternalConnectDisconnector interface.

func (TypedExternalConnectDisconnectorFns[managed]) Connect

func (fns TypedExternalConnectDisconnectorFns[managed]) Connect(ctx context.Context, mg managed) (TypedExternalClient[managed], error)

Connect to the provider specified by the supplied managed resource and produce an ExternalClient.

func (TypedExternalConnectDisconnectorFns[managed]) Disconnect

func (fns TypedExternalConnectDisconnectorFns[managed]) Disconnect(ctx context.Context) error

Disconnect from the provider and close the ExternalClient.

type TypedExternalConnecter

type TypedExternalConnecter[managed resource.Managed] interface {
	TypedExternalConnector[managed]
}

TypedExternalConnecter an alias to TypedExternalConnector. Deprecated: use TypedExternalConnector.

type TypedExternalConnector

type TypedExternalConnector[managed resource.Managed] interface {
	// Connect to the provider specified by the supplied managed resource and
	// produce an ExternalClient.
	Connect(ctx context.Context, mg managed) (TypedExternalClient[managed], error)
}

A TypedExternalConnector produces a new ExternalClient given the supplied Managed resource.

type TypedExternalConnectorFn

type TypedExternalConnectorFn[managed resource.Managed] func(ctx context.Context, mg managed) (TypedExternalClient[managed], error)

An TypedExternalConnectorFn is a function that satisfies the TypedExternalConnector interface.

func (TypedExternalConnectorFn[managed]) Connect

func (ec TypedExternalConnectorFn[managed]) Connect(ctx context.Context, mg managed) (TypedExternalClient[managed], error)

Connect to the provider specified by the supplied managed resource and produce an ExternalClient.

type TypedNopDisconnector

type TypedNopDisconnector[managed resource.Managed] struct {
	// contains filtered or unexported fields
}

A TypedNopDisconnector converts an ExternalConnector into an ExternalConnectDisconnector with a no-op Disconnect method.

func (*TypedNopDisconnector[managed]) Connect

func (c *TypedNopDisconnector[managed]) Connect(ctx context.Context, mg managed) (TypedExternalClient[managed], error)

Connect calls the underlying ExternalConnector's Connect method.

func (*TypedNopDisconnector[managed]) Disconnect

func (c *TypedNopDisconnector[managed]) Disconnect(_ context.Context) error

Disconnect does nothing. It never returns an error.

Jump to

Keyboard shortcuts

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