lifecycle

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 9 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Annotate added in v0.3.0

func Annotate(ctx context.Context, target LabelAnnotatableFrom, key, value string)

Annotate uses any LabelAnnotatableFrom object to assign the given annotation.

func Finalize

func Finalize(ctx context.Context, cl client.Client, name string, obj FinalizablePersister, run func() error) (bool, error)

Finalize provides a lifecycle for finalization for an entity that implements FinalizablePersister.

If the entity is not in a finalizing state, a finalizer is added with the given name. The entity is automatically persisted.

If the entity is in a finalizing state, the given callback function is run. If it succeeds, the finalizer is removed and the entity is persisted.

This function returns true if the finalization callback successfully ran and the entity was updated. It returns false otherwise.

func Label added in v0.2.0

func Label(ctx context.Context, target LabelAnnotatableFrom, key, value string)

Label uses any LabelAnnotatableFrom object to assign the given label.

func LabelManagedBy added in v0.2.0

func LabelManagedBy(ctx context.Context, target LabelAnnotatableFrom, value string)

LabelManagedBy sets the "app.kubernetes.io/managed-by" label to a particular value.

Types

type CacheBypasserClient added in v0.5.0

type CacheBypasserClient interface {
	client.Client
	BypassCache() client.Reader
}

func CacheBypasserClientForManager added in v0.5.0

func CacheBypasserClientForManager(mgr manager.Manager) CacheBypasserClient

type DeleteOption

type DeleteOption interface {
	// ApplyToDeleteOptions copies the configuration of this option to the given
	// deletion options.
	ApplyToDeleteOptions(target *DeleteOptions)
}

DeleteOption is a setter for one or more deletion options.

type DeleteOptions

type DeleteOptions struct {
	PropagationPolicy client.PropagationPolicy
}

DeleteOptions are the options that a deletable entity is required to support.

func (*DeleteOptions) ApplyOptions

func (o *DeleteOptions) ApplyOptions(opts []DeleteOption)

ApplyOptions runs each of the given options against this deletion options struct.

type DeleteWithPropagationPolicy

type DeleteWithPropagationPolicy client.PropagationPolicy

DeleteWithPropagationPolicy causes the deletion to use the specified propagation policy semantically.

If this option is not used, propagation policy will be determined by the entity being deleted.

func (DeleteWithPropagationPolicy) ApplyToDeleteOptions

func (dwpp DeleteWithPropagationPolicy) ApplyToDeleteOptions(target *DeleteOptions)

ApplyToDeleteOptions copies the configuration of this option to the given deletion options.

type Deleter

type Deleter interface {
	// Delete removes this entity from the cluster.
	Delete(ctx context.Context, cl client.Client, opts ...DeleteOption) (bool, error)
}

Deleter is the type of an entity that can be deleted from a cluster.

type Finalizable

type Finalizable interface {
	// Finalizing returns true if this entity is currently in a finalizing
	// state.
	//
	// Usually, this is indicated by the presence of a deletion timestamp in
	// Kubernetes object metadata.
	Finalizing() bool

	// AddFinalizer sets the given finalizer in object metadata. It returns true
	// if the finalizer was added, and false if it already exists.
	AddFinalizer(ctx context.Context, name string) bool

	// RemoveFinalizer removes the given finalizer from object metadata. It
	// returns true if the finalizer was removed, and false if the finalizer did
	// not exist.
	RemoveFinalizer(ctx context.Context, name string) bool
}

Finalizable is the type of an entity that supports finalizing.

type FinalizablePersister

type FinalizablePersister interface {
	Finalizable
	Persister
}

FinalizablePersister is a combined interface for a finalizable entity that can be saved to the cluster.

type IgnoreNilLabelAnnotatableFrom

type IgnoreNilLabelAnnotatableFrom struct {
	LabelAnnotatableFrom
}

IgnoreNilLabelAnnotatableFrom is an adapter for a label and annotation copier that makes sure its delegate has a value before copying.

func (IgnoreNilLabelAnnotatableFrom) LabelAnnotateFrom

func (inlaf IgnoreNilLabelAnnotatableFrom) LabelAnnotateFrom(ctx context.Context, from metav1.Object)

LabelAnnotateFrom copies the labels from the given object metadata to this entity, or does nothing if the underlying entity is nil or is an interface with a nil value.

type IgnoreNilLoader

type IgnoreNilLoader struct {
	Loader
}

IgnoreNilLoader is an adapter for a loader that makes sure the loader has a value before attempting to load from it.

This loader is useful for loading optional dependencies.

func (IgnoreNilLoader) Load

func (inl IgnoreNilLoader) Load(ctx context.Context, cl client.Client) (bool, error)

Load finds this entity in the cluster and populates any necessary fields. If the underlying loader is nil or an interface with a nil value, this method always returns true with no error.

type IgnoreNilOwnable

type IgnoreNilOwnable struct {
	Ownable
}

IgnoreNilOwnable is an adapter for an ownable entity that makes sure the entity has a value.

func (IgnoreNilOwnable) Owned

func (ino IgnoreNilOwnable) Owned(ctx context.Context, owner TypedObject) error

Owned sets the ownerReferences controller for this entity to the given object, or does nothing if the underlying entity is nil or an interface with a nil value.

type IgnoreNilOwnablePersister added in v0.2.0

type IgnoreNilOwnablePersister struct {
	OwnablePersister
}

IgnoreNilOwnablePersister combines IgnoreNilOwnable and IgnoreNilPersister.

func (IgnoreNilOwnablePersister) Owned added in v0.2.0

Owned sets the ownerReferences controller for this entity to the given object, or does nothing if the underlying entity is nil or an interface with a nil value.

func (IgnoreNilOwnablePersister) Persist added in v0.2.0

Persist saves this entity using the given client, or does nothing if the underlying entity is nil or is an interface with a nil value.

type IgnoreNilPersister

type IgnoreNilPersister struct {
	Persister
}

IgnoreNilPersister is an adapter for a persistable entity that makes sure the entity has a value.

func (IgnoreNilPersister) Persist

func (inp IgnoreNilPersister) Persist(ctx context.Context, cl client.Client) error

Persist saves this entity using the given client, or does nothing if the underlying entity is nil or is an interface with a nil value.

type LabelAnnotatableFrom

type LabelAnnotatableFrom interface {
	// LabelAnnotateFrom copies the labels from the given object metadata to
	// this entity.
	LabelAnnotateFrom(ctx context.Context, from metav1.Object)
}

LabelAnnotatableFrom is the type of an entity that can copy labels and annotations from the given metadata.

type Loader

type Loader interface {
	// Load finds this entity in the cluster and populates any necessary fields.
	// If there was an error locating the entity, this function returns false.
	Load(ctx context.Context, cl client.Client) (bool, error)
}

Loader is the type of an entity that can be retrieved from a cluster.

func NewPredicateLoader added in v0.3.0

func NewPredicateLoader(delegate Loader, cond func(ctx context.Context) bool) Loader

NewPredicateLoader creates a new loader that delegates to a given loader if a condition, evaluated upon Load being called, returns true.

func NewPrereqLoader added in v0.3.0

func NewPrereqLoader(delegate Loader, obj client.Object) Loader

NewPrereqLoader creates a loader that only delegates to another loader if the given object exists at the time Load is called.

type LoaderFunc

type LoaderFunc func(ctx context.Context, cl client.Client) (bool, error)

LoaderFunc allows a function to be used as a loader.

func (LoaderFunc) Load

func (lf LoaderFunc) Load(ctx context.Context, cl client.Client) (bool, error)

Load finds this entity in the cluster and populates any necessary fields.

type Loaders

type Loaders []Loader

Loaders allows multiple loaders to be loaded at once, as if they were a single entity.

func (Loaders) Load

func (ls Loaders) Load(ctx context.Context, cl client.Client) (bool, error)

Load finds this collection of entities in the cluster and loads each one.

If any loader returns false, this method returns false, but it attempts to continue loading the remaining entities. If any loader returns an error, the error is immediately returned and loading stops.

type Ownable

type Ownable interface {
	// Owned sets the ownerReferences controller for this entity to the given
	// object.
	Owned(ctx context.Context, owner TypedObject) error
}

Ownable is the type of an entity that can be a dependent of another object using the Kubernetes ownerReferences mechanism.

type OwnablePersister

type OwnablePersister interface {
	Ownable
	Persister
}

OwnablePersister is a combined interface for an object that can be owned and can be saved to the cluster.

type OwnablePersisters

type OwnablePersisters []OwnablePersister

OwnablePersisters allows a collection of ownable persisters to be used as a single entity.

func (OwnablePersisters) Owned

func (ops OwnablePersisters) Owned(ctx context.Context, owner TypedObject) error

Owned sets the ownerReferences controller for each entity in this collection to the given object.

func (OwnablePersisters) Persist

func (ops OwnablePersisters) Persist(ctx context.Context, cl client.Client) error

Persist saves each of the entities in this collection to the cluster using the given client.

type Owner

type Owner interface {
	// Own sets the owner of the specified dependent entity to this entity.
	Own(ctx context.Context, other Ownable) error
}

Owner is the type of an entity that can own other objects using the Kubernetes ownerReferences mechanism.

type OwnerPersister

type OwnerPersister interface {
	Owner
	Persister
}

OwnerPersister is a combined interface for an object that can own other objects and can be saved to the cluster.

type OwnershipPersister

type OwnershipPersister struct {
	Owner     OwnerPersister
	Dependent OwnablePersister
}

OwnershipPersister provides a lifecycle for managing the ownership of an entity or set of entities.

It first persists the owner so that its unique object ID is known. Then it sets the ownerReferences for the intended dependent. Finally, it persists all the dependents.

func (OwnershipPersister) Persist

func (op OwnershipPersister) Persist(ctx context.Context, cl client.Client) error

Persist saves the owner and dependent, guaranteeing an ownerReference relationship between the dependent and the owner.

type Persister

type Persister interface {
	// Persist saves this entity using the given client.
	Persist(ctx context.Context, cl client.Client) error
}

Persister is the type of an entity that can be saved to a cluster.

type RequiredError

type RequiredError struct {
	// Loader is the underlying loader that could not find the object.
	Loader Loader
}

RequiredError is an error reported by RequiredLoader if the target cannot be found.

func (*RequiredError) Error

func (e *RequiredError) Error() string

Error conforms a pointer to RequiredError to the error interface.

type RequiredLoader

type RequiredLoader struct {
	Loader
}

RequiredLoader is an adapter for a loader that ensures the entity exists.

func (RequiredLoader) Load

func (rl RequiredLoader) Load(ctx context.Context, cl client.Client) (bool, error)

Load finds this entity in the cluster and populates any necessary fields. If the underlying loader returns false, this loader converts it to an error of type *RequiredError.

type RetryLoader

type RetryLoader interface {
	Loader

	// WithWaitOptions sets the options, like a backoff, to use, for waiting on
	// the condition.
	WithWaitOptions(opts ...retry.WaitOption) Loader
}

RetryLoader is an adapter that continually retries loading until a condition is met.

func NewRetryLoader

func NewRetryLoader(delegate Loader, mapper func(bool, error) (bool, error)) RetryLoader

NewRetryLoader creates a new loader that delegates to the given loader. When the Load method is called, its result is mapped using the given condition function. This loader only successfully returns when the mapper function returns true (even in the case of errors).

type TypedObject

type TypedObject struct {
	GVK    schema.GroupVersionKind
	Object client.Object
}

TypedObject is a Kubernetes runtime object with its resource group-version-kind attached from its schema.

Jump to

Keyboard shortcuts

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