condition

package
v4.0.0-...-b0ab343 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package condition contains interfaces and primitives for use with our await logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type All

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

func NewAll

func NewAll(conditions ...Satisfier) (*All, error)

NewAll joins multiple Satisfiers and resolves when all of them are simultaneously satisfied. The conditions should all apply to the same object.

func (*All) Object

func (ac *All) Object() *unstructured.Unstructured

Object returns the first condition's current state.

func (*All) Observe

func (ac *All) Observe(e watch.Event) error

Observe sends the given event to all sub-conditions.

func (*All) Range

func (ac *All) Range(yield func(watch.Event) bool)

Range iterates over the first condition's events since all conditions are assumed to be watching the same object.

func (*All) Satisfied

func (ac *All) Satisfied() (bool, error)

Satisfied returns true when all the sub-conditions are true.

type Custom

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

Custom waits for a specific ".status.condition" matching a user-provided expression.

func NewCustom

func NewCustom(
	ctx context.Context,
	source Source,
	logger logger,
	uns *unstructured.Unstructured,
	expr string,
) (*Custom, error)

NewCustom creates a new Custom condition.

The expression's syntax is identical to `kubectl wait --for=condition=`. A condition type is required, optionally followed by a value:

"condition=Foo" or "condition=Foo=Bar"

The "condition=" prefix is also optional.

func (*Custom) Object

func (cc *Custom) Object() *unstructured.Unstructured

Object is a passthrough to the underlying Observer.

func (*Custom) Observe

func (cc *Custom) Observe(e watch.Event) error

Observe is a passthrough to the underlying Observer.

func (*Custom) Range

func (cc *Custom) Range(yield func(watch.Event) bool)

Range is a passthrough to the underlying Observer.

func (*Custom) Satisfied

func (cc *Custom) Satisfied() (bool, error)

Satisfied returns true when the object's last-known state matches the expected condition.

type Deleted

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

Deleted condition succeeds when GET on a resource 404s or when a Deleted event is received for the resource.

func NewDeleted

func NewDeleted(
	ctx context.Context,
	source Source,
	getter objectGetter,
	logger logger,
	obj *unstructured.Unstructured,
) (*Deleted, error)

NewDeleted constructs a new Deleted condition.

func (*Deleted) Object

func (dc *Deleted) Object() *unstructured.Unstructured

Object returns the last-known state of the object we're deleting.

func (*Deleted) Observe

func (dc *Deleted) Observe(e watch.Event) error

Observe watches for Deleted events.

func (*Deleted) Range

func (dc *Deleted) Range(yield func(watch.Event) bool)

Range establishes an Informer and confirms the object still existsr. If a Deleted event isn't Observed by the time the underlying Observer is exhausted, we attempt a final lookup on the cluster to be absolutely sure it still exists.

func (*Deleted) Satisfied

func (dc *Deleted) Satisfied() (bool, error)

Satisfied returns true if a Deleted event was Observed. Otherwise a status message will be logged, if available.

type DynamicSource

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

DynamicSource establishes Informers against the cluster.

func NewDynamicSource

func NewDynamicSource(
	ctx context.Context,
	clientset *clients.DynamicClientSet,
	namespace string,
) *DynamicSource

NewDynamicSource creates a new DynamicEventSource which will lazily establish a single dynamicinformer.DynamicSharedInformerFactory. Subsequent calls to Start will spawn informers.GenericInformer from that factory.

func (*DynamicSource) Start

func (des *DynamicSource) Start(_ context.Context, gvk schema.GroupVersionKind) (<-chan watch.Event, error)

Start establishes an Informer against the cluster for the given GVK.

type Failure

type Failure struct {
	Immediate
	// contains filtered or unexported fields
}

Failure is a no-op condition which raises an error when it is checked. This is primarily useful for testing.

func (*Failure) Satisfied

func (f *Failure) Satisfied() (bool, error)

Satisfied raises the given error.

type Immediate

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

Immediate is a no-op condition which is always satisfied. This is primarily used for skip-await behavior and testing.

func NewImmediate

func NewImmediate(logger logger, obj *unstructured.Unstructured) Immediate

NewImmediate creates a new Immediate condition.

func (Immediate) Object

func (i Immediate) Object() *unstructured.Unstructured

Object returns the observer's underlying object.

func (Immediate) Observe

func (Immediate) Observe(watch.Event) error

Observe is a no-op for Immediately conditions.

func (Immediate) Range

func (Immediate) Range(func(watch.Event) bool)

Range is a no-op for Immediately conditions.

func (Immediate) Satisfied

func (i Immediate) Satisfied() (bool, error)

Satisfied always returns true for Immediately conditions.

type JSONPath

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

JSONPath waits for the observed object to match a user-provided JSONPath expression.

func (*JSONPath) Object

func (jp *JSONPath) Object() *unstructured.Unstructured

Object is a passthrough to the underlying Observer.

func (*JSONPath) Observe

func (jp *JSONPath) Observe(e watch.Event) error

Observe is a passthrough to the underlying Observer.

func (*JSONPath) Range

func (jp *JSONPath) Range(yield func(watch.Event) bool)

Range is a passthrough to the underlying Observer.

func (*JSONPath) Satisfied

func (jp *JSONPath) Satisfied() (bool, error)

Satisfied returns true with the observed object's last-known state matches the provided JSONPath expression.

type Never

type Never struct {
	Immediate
}

Never is a no-op condition which is never satisfied. This is primarily useful for tests.

func NewNever

func NewNever(obj *unstructured.Unstructured) *Never

NewNever creates a new Never condition.

func (Never) Satisfied

func (n Never) Satisfied() (bool, error)

Satisfied always returns false for Never conditions.

type ObjectObserver

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

ObjectObserver observes the given resource and keeps track of its last-known state.

func NewObjectObserver

func NewObjectObserver(
	ctx context.Context,
	source Source,
	obj *unstructured.Unstructured,
) *ObjectObserver

NewObjectObserver creates a new ObjectObserver that tracks changes to the provided object

func (*ObjectObserver) Object

Object returns the last-known state of the observed object.

func (*ObjectObserver) Observe

func (oo *ObjectObserver) Observe(e watch.Event) error

Observe updates the Observer's state with the observed object.

func (*ObjectObserver) Range

func (oo *ObjectObserver) Range(yield func(watch.Event) bool)

Range is an iterator over events visible to the Observer.

type Observer

type Observer interface {
	// Range iterates over all events visible to the Observer. The caller is
	// responsible for invoking Observe as part of the provided callback. Range
	// can be used to customize setup and teardown behavior if the Observer
	// wraps another Observer.
	Range(func(watch.Event) bool)

	// Observe handles events and can optionally update the Observer's state.
	// This should be invoked by the caller and not during Range.
	Observe(watch.Event) error
}

Observer acts on a watch.Event Source. Range is responsible for filtering events to only those relevant to the Observer, and Observe optionally updates the Observer's state.

func NewChildObserver

func NewChildObserver(
	ctx context.Context,
	source Source,
	owner *unstructured.Unstructured,
	gvk schema.GroupVersionKind,
) Observer

NewChildObserver creates a new ChildObserver subscribed to children of the owner with the given GVK.

func NewObserver

func NewObserver(
	ctx context.Context,
	source Source,
	gvk schema.GroupVersionKind,
	keep func(*unstructured.Unstructured) bool,
) Observer

NewObserver returns a new Observer with a watch.Event channel configured for the given GVK and filtered according to the given "keep" function.

type On

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

On is satisfied when it observes a specific event.

func NewOn

func NewOn(
	ctx context.Context,
	source Source,
	obj *unstructured.Unstructured,
	want watch.Event,
) *On

NewOn creates a new On condition.

func (*On) Object

func (o *On) Object() *unstructured.Unstructured

Object returns the observer's underlying object.

func (*On) Observe

func (o *On) Observe(e watch.Event) error

Observe checks whether the observed event is the one we want.

func (*On) Range

func (o *On) Range(yield func(watch.Event) bool)

Range iterates over the underlying observer.

func (*On) Satisfied

func (o *On) Satisfied() (bool, error)

Satisfied returns true if the expected event has been Observed.

type Ready

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

func NewReady

func NewReady(
	ctx context.Context,
	source Source,
	logger logger,
	obj *unstructured.Unstructured,
) *Ready

NewReady creates a new Ready condition.

func (*Ready) Object

func (r *Ready) Object() *unstructured.Unstructured

Object returns the last-known state of the object we're watching.

func (*Ready) Observe

func (r *Ready) Observe(e watch.Event) error

Observe is a passthrough to the underlying Observer.

func (*Ready) Range

func (r *Ready) Range(yield func(watch.Event) bool)

Range watches events on the object. It is the caller's responsibility to ensure the object exists on the cluster beforehand.

func (*Ready) Satisfied

func (r *Ready) Satisfied() (bool, error)

Satisfied returns `true` if the object doesn't have any recognizable status conditions.

type Satisfier

type Satisfier interface {
	Observer

	// Satisfied returns true when the criteria is met.
	Satisfied() (bool, error)

	// Object returns the last-known state of the object being observed.
	Object() *unstructured.Unstructured
}

Satisfier is an Observer which evaluates the observed object against some criteria.

func NewFailure

func NewFailure(err error) Satisfier

NewFailure creates a new Failure condition.

func NewJSONPath

func NewJSONPath(
	ctx context.Context,
	source Source,
	logger logger,
	obj *unstructured.Unstructured,
	jsp *jsonpath.Parsed,
) (Satisfier, error)

NewJSONPath creates a new JSONPath condition.

type Source

type Source interface {
	Start(context.Context, schema.GroupVersionKind) (<-chan watch.Event, error)
}

Source encapsulates logic responsible for establishing watch.Event channels.

type Static

type Static chan watch.Event

Static implements Source and allows a fixed event channel to be used as an Observer's Source. Static should not be shared across multiple Observers, instead give each Observer their own channel.

func (Static) Start

Start returns a fixed event channel.

type Stopped

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

Stopped is satisfied after its underlying Observer has been exhausted. This is primarily useful for testing behavior which occurs on shutdown.

func NewStopped

func NewStopped(logger logger, obj *unstructured.Unstructured) *Stopped

NewStopped creates a new Stopped condition.

func (*Stopped) Object

func (s *Stopped) Object() *unstructured.Unstructured

Object returns the observer's underlying object.

func (*Stopped) Observe

func (s *Stopped) Observe(e watch.Event) error

Observe invokes the underlying Observer.

func (*Stopped) Range

func (s *Stopped) Range(yield func(watch.Event) bool)

Range iterates over the underlying Observer and satisfies the condition.

func (*Stopped) Satisfied

func (s *Stopped) Satisfied() (bool, error)

Satisfied returns true if the underlying Observer has been fully iterated over.

Jump to

Keyboard shortcuts

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