operand

package
v0.0.0-...-c510420 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2022 License: MIT Imports: 8 Imported by: 1

Documentation

Overview

Package operand defines an operand interface. Operands constitutes the core of an operator. Operands are operated by the operator in some order based on the scenario. Generally, an operand is a small unit of task on a specific object. Multiple operands are combined together to perform a complete task.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotReady = errors.New("operand not ready")

ErrNotReady is returned by operand when the ready check fails.

Functions

func CallCleanup

CallCleanup is an OperandRunCall type function that calls the Cleanup function of a given operand.

func CallEnsure

CallEnsure is an OperandRunCall type function that calls the Ensure function and the ReadyCheck of a given operand. The Ensure function ensures that the desired change is applied to the world and ReadyCheck helps proceed only when the desired state of the world is reached. This helps run dependent operands only after a successful operand execution.

Types

type Operand

type Operand interface {
	// Name of the operand.
	Name() string

	// Requires defines the relationship between the operands of an operator.
	Requires() []string

	// Ensure creates, or updates a target object with the wanted
	// configurations. It also returns an event that can be posted on the
	// parent object's event list.
	Ensure(context.Context, client.Object, metav1.OwnerReference) (eventv1.ReconcilerEvent, error)

	// Delete deletes a target object. It also returns an event that can be
	// posted on the parent object's event list.
	Delete(context.Context, client.Object) (eventv1.ReconcilerEvent, error)

	// Requeue is the requeue strategy for this operand.
	RequeueStrategy() RequeueStrategy

	// ReadyCheck allows writing custom logic for checking if an object is
	// ready.
	ReadyCheck(context.Context, client.Object) (bool, error)

	// PostReady allows performing actions once the target object of the
	// operand is ready.
	PostReady(context.Context, client.Object) error
}

Operand defines a single operation that's part of a composite operator. It contains implementation details about how an action is performed, maybe for creating a resource, and how to reverse/undo the action, maybe for cleanup purposes. It also contains relationship information about the operand with other operands and details about checking the ready status of target objects.

type OperandOrder

type OperandOrder [][]Operand

OperandOrder stores the operands in order of their execution. The first dimension of the slice depicts the execution step and the second dimention contains the operands that can be run in parallel.

func (OperandOrder) Reverse

func (o OperandOrder) Reverse() OperandOrder

Reverse returns the OperandOrder in reverse order.

func (OperandOrder) String

func (o OperandOrder) String() string

String implements the Stringer interface for OperandOrder. Example string result: [

0: [ A B ]
1: [ C ]
2: [ D F ]
3: [ E ]

]

type OperandRunCall

OperandRunCall defines a function type used to define a function that returns an operand execute call. This is used for passing the operand execute function (Ensure or Delete) in a generic way.

type RequeueStrategy

type RequeueStrategy int

RequeueStrategy defines the requeue strategy of an operand.

const (
	// RequeueOnError is used for requeue on error only.
	RequeueOnError RequeueStrategy = iota

	// RequeueAlways is used to requeue result after every applied change.
	RequeueAlways
)

func StepRequeueStrategy

func StepRequeueStrategy(step []Operand) RequeueStrategy

StepRequeueStrategy returns the requeue strategy of a step. By default, the operands are requeued on error. Since the operands in a step run concurrently, if an operand has RequeueAlways strategy, the whole step gets RequeueAlways strategy.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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