composed

package
v0.1.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StopAndForget   error
	StopWithRequeue error
	Break           error
)

Functions

func Handle

func Handle(err error, _ context.Context) (ctrl.Result, error)

func IsBreak

func IsBreak(err error) bool

func IsFlowControl

func IsFlowControl(err error) bool

func IsMarkedForDeletion added in v0.1.4

func IsMarkedForDeletion(obj client.Object) bool

func IsStopAndForget

func IsStopAndForget(err error) bool

func IsStopWithRequeue

func IsStopWithRequeue(err error) bool

func IsStopWithRequeueDelay

func IsStopWithRequeueDelay(err error) bool

func IsTerminal

func IsTerminal(err error) bool

func LoadObj

func LoadObj(ctx context.Context, state State) (error, context.Context)

func LogErrorAndReturn

func LogErrorAndReturn(err error, msg string, result error, ctx context.Context) (error, context.Context)

func LoggerFromCtx

func LoggerFromCtx(ctx context.Context) logr.Logger

func LoggerIntoCtx

func LoggerIntoCtx(ctx context.Context, logger logr.Logger) context.Context

func MarkedForDeletionPredicate

func MarkedForDeletionPredicate(_ context.Context, state State) bool

func StopAndForgetAction

func StopAndForgetAction(_ context.Context, _ State) (error, context.Context)

func StopWithRequeueAction

func StopWithRequeueAction(_ context.Context, _ State) (error, context.Context)

func StopWithRequeueDelay

func StopWithRequeueDelay(d time.Duration) error

Types

type Action

type Action func(ctx context.Context, state State) (error, context.Context)

func BreakIf

func BreakIf(predicate Predicate) Action

func BuildBranchingAction

func BuildBranchingAction(name string, predicate Predicate, trueAction Action, falseAction Action) Action

func BuildSwitchAction

func BuildSwitchAction(name string, defaultAction Action, cases ...Case) Action

func ComposeActions

func ComposeActions(name string, actions ...Action) Action

func StopWithRequeueDelayAction

func StopWithRequeueDelayAction(d time.Duration) Action

type Case

type Case interface {
	Predicate(ctx context.Context, state State) bool
	Action(ctx context.Context, state State) (error, context.Context)
}

func NewCase

func NewCase(p Predicate, a Action) Case

type CaseStruct

type CaseStruct struct {
	P Predicate
	A Action
}

func (*CaseStruct) Action

func (cs *CaseStruct) Action(ctx context.Context, state State) (error, context.Context)

func (*CaseStruct) Predicate

func (cs *CaseStruct) Predicate(ctx context.Context, state State) bool

type FlowControlError

type FlowControlError interface {
	error
	ShouldReturnError() bool
}

type ObjWithConditions

type ObjWithConditions interface {
	client.Object
	Conditions() *[]metav1.Condition
	GetObjectMeta() *metav1.ObjectMeta
}

type ObjWithConditionsAndState added in v0.1.4

type ObjWithConditionsAndState interface {
	ObjWithConditions
	State() string
	SetState(v string)
}

type ObjectList added in v0.1.4

type ObjectList interface {
	client.ObjectList
	GetItemCount() int
	GetItems() []client.Object
}

type Predicate

type Predicate func(ctx context.Context, state State) bool

func All

func All(predicates ...Predicate) Predicate

func Any

func Any(predicates ...Predicate) Predicate

func Not

func Not(p Predicate) Predicate

type State

type State interface {
	// Cluster returns the used cluster
	Cluster() StateCluster

	// K8sClient returns the client to the cluster
	//
	// Deprecated: Use Cluster().K8sClient() instead
	K8sClient() client.Client

	// EventRecorder returns the event recorder of the connected cluster
	//
	// Deprecated: Use Cluster().EventRecorder() instead
	EventRecorder() record.EventRecorder

	// Scheme returns the Scheme
	//
	// Deprecated: Use Cluster().Scheme() instead
	Scheme() *runtime.Scheme

	Name() types.NamespacedName
	Obj() client.Object
	SetObj(client.Object)

	LoadObj(ctx context.Context, opts ...client.GetOption) error
	UpdateObj(ctx context.Context, opts ...client.UpdateOption) error
	UpdateObjStatus(ctx context.Context, opts ...client.SubResourceUpdateOption) error
}

type StateCluster

type StateCluster interface {
	K8sClient() client.Client
	ApiReader() client.Reader
	EventRecorder() record.EventRecorder
	Scheme() *runtime.Scheme
}

func NewStateCluster

func NewStateCluster(
	client client.Client,
	reader client.Reader,
	eventRecorder record.EventRecorder,
	scheme *runtime.Scheme,
) StateCluster

func NewStateClusterFromCluster

func NewStateClusterFromCluster(cluster cluster.Cluster) StateCluster

type StateFactory

type StateFactory interface {
	NewState(name types.NamespacedName, obj client.Object) State
}

func NewStateFactory

func NewStateFactory(cluster StateCluster) StateFactory

type UpdateStatusBuilder

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

func UpdateStatus

func UpdateStatus(obj ObjWithConditions) *UpdateStatusBuilder

func (*UpdateStatusBuilder) ErrorLogMessage

func (b *UpdateStatusBuilder) ErrorLogMessage(msg string) *UpdateStatusBuilder

func (*UpdateStatusBuilder) FailedError

func (b *UpdateStatusBuilder) FailedError(err error) *UpdateStatusBuilder

func (*UpdateStatusBuilder) KeepConditions

func (b *UpdateStatusBuilder) KeepConditions(conditionTypes ...string) *UpdateStatusBuilder

func (*UpdateStatusBuilder) OnUpdateError

func (b *UpdateStatusBuilder) OnUpdateError(f func(ctx context.Context, err error) (error, context.Context)) *UpdateStatusBuilder

func (*UpdateStatusBuilder) OnUpdateSuccess

func (b *UpdateStatusBuilder) OnUpdateSuccess(f func(ctx context.Context) (error, context.Context)) *UpdateStatusBuilder

func (*UpdateStatusBuilder) RemoveConditionIfReasonMatched

func (b *UpdateStatusBuilder) RemoveConditionIfReasonMatched(conditionType, conditionReason string) *UpdateStatusBuilder

func (*UpdateStatusBuilder) RemoveConditions

func (b *UpdateStatusBuilder) RemoveConditions(conditionTypes ...string) *UpdateStatusBuilder

func (*UpdateStatusBuilder) Run

func (*UpdateStatusBuilder) SetCondition

func (*UpdateStatusBuilder) SetExclusiveConditions

func (b *UpdateStatusBuilder) SetExclusiveConditions(conditions ...metav1.Condition) *UpdateStatusBuilder

func (*UpdateStatusBuilder) SuccessError

func (b *UpdateStatusBuilder) SuccessError(err error) *UpdateStatusBuilder

func (*UpdateStatusBuilder) SuccessErrorNil

func (b *UpdateStatusBuilder) SuccessErrorNil() *UpdateStatusBuilder

func (*UpdateStatusBuilder) SuccessLogMsg

func (b *UpdateStatusBuilder) SuccessLogMsg(msg string) *UpdateStatusBuilder

func (*UpdateStatusBuilder) UpdateErrorWrapper

func (b *UpdateStatusBuilder) UpdateErrorWrapper(f func(err error) error) *UpdateStatusBuilder

Jump to

Keyboard shortcuts

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