managed

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: Apache-2.0 Imports: 17 Imported by: 904

Documentation

Overview

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

Index

Constants

This section is empty.

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.

func IsReferencesAccessError

func IsReferencesAccessError(err error) bool

IsReferencesAccessError returns true if the given error indicates that some of the `AttributeReferencer` fields are referring to objects that are not accessible, either they are not ready or they do not yet exist

Types

type APIFinalizer

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

An APIFinalizer adds and removes finalizers to and from a resource.

func NewAPIFinalizer

func NewAPIFinalizer(c client.Client, finalizer string) *APIFinalizer

NewAPIFinalizer returns a new APIFinalizer.

func (*APIFinalizer) AddFinalizer

func (a *APIFinalizer) AddFinalizer(ctx context.Context, mg resource.Managed) error

AddFinalizer to the supplied Managed resource.

func (*APIFinalizer) RemoveFinalizer

func (a *APIFinalizer) RemoveFinalizer(ctx context.Context, mg resource.Managed) error

RemoveFinalizer from the supplied Managed resource.

type APIReferenceResolver

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

An APIReferenceResolver finds and resolves a resource's references, then updates it in the Kubernetes API.

func NewAPIReferenceResolver

func NewAPIReferenceResolver(c client.Client, o ...APIReferenceResolverOption) *APIReferenceResolver

NewAPIReferenceResolver returns an APIReferenceResolver. The resolver uses reflection to recursively finds all pointer types in a struct that satisfy AttributeReferencer by default. It assesses only pointers, structs, and slices because it is assumed that only struct fields or slice elements that are pointers to a struct will satisfy AttributeReferencer.

func (*APIReferenceResolver) ResolveReferences

func (r *APIReferenceResolver) ResolveReferences(ctx context.Context, res resource.CanReference) error

ResolveReferences resolves references made to other managed resources

type APIReferenceResolverOption

type APIReferenceResolverOption func(*APIReferenceResolver)

An APIReferenceResolverOption configures an APIReferenceResolver.

func WithAttributeReferencerFinder

func WithAttributeReferencerFinder(f AttributeReferencerFinder) APIReferenceResolverOption

WithAttributeReferencerFinder specifies an AttributeReferencerFinder used to find AttributeReferencers.

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

func (a *APISecretPublisher) PublishConnection(ctx context.Context, mg resource.Managed, c ConnectionDetails) error

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

func (a *APISecretPublisher) UnpublishConnection(ctx context.Context, mg resource.Managed, c ConnectionDetails) error

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

type AttributeReferencerFinder

type AttributeReferencerFinder interface {
	FindReferencers(obj interface{}) []resource.AttributeReferencer
}

An AttributeReferencerFinder returns all types within the supplied object that satisfy AttributeReferencer.

type AttributeReferencerFinderFn

type AttributeReferencerFinderFn func(obj interface{}) []resource.AttributeReferencer

An AttributeReferencerFinderFn satisfies AttributeReferencerFinder.

func (AttributeReferencerFinderFn) FindReferencers

func (fn AttributeReferencerFinderFn) FindReferencers(obj interface{}) []resource.AttributeReferencer

FindReferencers finds all AttributeReferencers.

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 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, mg resource.Managed, c ConnectionDetails) error

	// UnpublishConnection details for the supplied Managed resource.
	UnpublishConnection(ctx context.Context, mg resource.Managed, 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, mg resource.Managed, c ConnectionDetails) error
	UnpublishConnectionFn func(ctx context.Context, mg resource.Managed, 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

func (fn ConnectionPublisherFns) UnpublishConnection(ctx context.Context, mg resource.Managed, c ConnectionDetails) error

UnpublishConnection details for the supplied Managed resource.

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.
	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(ctx context.Context, mg resource.Managed) (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 resource.Managed) (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 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) (ExternalCreation, error)
	UpdateFn  func(ctx context.Context, mg resource.Managed) (ExternalUpdate, 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

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

func (ExternalClientFns) Update

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

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

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

An ExternalConnectorFn is a function that satisfies the ExternalConnecter interface.

func (ExternalConnectorFn) Connect

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

type ExternalCreation

type ExternalCreation struct {
	ConnectionDetails ConnectionDetails
}

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

type ExternalObservation

type ExternalObservation struct {
	ResourceExists    bool
	ResourceUpToDate  bool
	ConnectionDetails ConnectionDetails
}

An ExternalObservation is the result of an observation of an external resource.

type ExternalUpdate

type ExternalUpdate struct {
	ConnectionDetails ConnectionDetails
}

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

type Finalizer

type Finalizer interface {
	// AddFinalizer to the supplied Managed resource.
	AddFinalizer(ctx context.Context, mg resource.Managed) error

	// RemoveFinalizer from the supplied Managed resource.
	RemoveFinalizer(ctx context.Context, mg resource.Managed) error
}

A Finalizer finalizes the deletion of a resource claim.

type FinalizerFns

type FinalizerFns struct {
	AddFinalizerFn    func(ctx context.Context, mg resource.Managed) error
	RemoveFinalizerFn func(ctx context.Context, mg resource.Managed) error
}

A FinalizerFns satisfy the Finalizer interface.

func (FinalizerFns) AddFinalizer

func (f FinalizerFns) AddFinalizer(ctx context.Context, mg resource.Managed) error

AddFinalizer to the supplied Managed resource.

func (FinalizerFns) RemoveFinalizer

func (f FinalizerFns) RemoveFinalizer(ctx context.Context, mg resource.Managed) error

RemoveFinalizer from the supplied Managed resource.

type Initializer

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

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

func (c *NopClient) Delete(ctx context.Context, mg resource.Managed) error

Delete 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 struct{}

A NopConnecter does nothing.

func (*NopConnecter) Connect

Connect returns a NopClient. It never returns an error.

type PublisherChain

type PublisherChain []ConnectionPublisher

A PublisherChain chains multiple ManagedPublishers.

func (PublisherChain) PublishConnection

func (pc PublisherChain) PublishConnection(ctx context.Context, mg resource.Managed, c ConnectionDetails) error

PublishConnection calls each ConnectionPublisher.PublishConnection serially. It returns the first error it encounters, if any.

func (PublisherChain) UnpublishConnection

func (pc PublisherChain) UnpublishConnection(ctx context.Context, mg resource.Managed, c ConnectionDetails) error

UnpublishConnection calls each ConnectionPublisher.UnpublishConnection serially. It returns the first error it encounters, if any.

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(req reconcile.Request) (reconcile.Result, error)

Reconcile a managed resource with an external resource.

type ReconcilerOption

type ReconcilerOption func(*Reconciler)

A ReconcilerOption configures a Reconciler.

func WithConnectionPublishers

func WithConnectionPublishers(p ...ConnectionPublisher) ReconcilerOption

WithConnectionPublishers specifies how the Reconciler should publish its connection details such as credentials and endpoints.

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 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 WithLongWait

func WithLongWait(after time.Duration) ReconcilerOption

WithLongWait specifies how long the Reconciler should wait before queueing a new reconciliation in 'long wait' scenarios. The Reconciler requeues after a long wait 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 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 WithShortWait

func WithShortWait(after time.Duration) ReconcilerOption

WithShortWait specifies how long the Reconciler should wait before queueing a new reconciliation in 'short wait' scenarios. The Reconciler requeues after a short wait when it knows it is waiting for an external operation to complete, or when it encounters a potentially temporary error.

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 ReferenceResolver

type ReferenceResolver interface {
	// ResolveReferences finds all fields in the supplied CanReference that are
	// references to Kubernetes resources, then uses the fields of those
	// resources to update corresponding fields in CanReference, for example
	// setting .spec.network to the name of the Network resource specified as
	// .spec.networkRef.
	ResolveReferences(ctx context.Context, res resource.CanReference) error
}

A ReferenceResolver resolves references to other managed resources.

type ReferenceResolverFn

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

A ReferenceResolverFn is a function that satisfies the ReferenceResolver interface.

func (ReferenceResolverFn) ResolveReferences

func (m ReferenceResolverFn) ResolveReferences(ctx context.Context, res resource.CanReference) error

ResolveReferences calls ReferenceResolverFn function

Jump to

Keyboard shortcuts

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