control

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Requeue = Retry

Requeue equivalent to Retry.

View Source
var RequeueAfter = RetryAfter

RequeueAfter equivalent to RetryAfter

Functions

func Debug

func Debug(e *executor)

Types

type BaseReconcileContext

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

func NewBaseReconcileContext

func NewBaseReconcileContext(client client.Client, restConfig *rest.Config, clientSet *kubernetes.Clientset,
	scheme *runtime.Scheme, context context.Context, request reconcile.Request) *BaseReconcileContext

func NewBaseReconcileContextFrom

func NewBaseReconcileContextFrom(base *BaseReconcileContext, context context.Context, request reconcile.Request) *BaseReconcileContext

func (*BaseReconcileContext) Client

func (rc *BaseReconcileContext) Client() client.Client

func (*BaseReconcileContext) ClientSet

func (rc *BaseReconcileContext) ClientSet() *kubernetes.Clientset

func (*BaseReconcileContext) Close

func (rc *BaseReconcileContext) Close() error

func (*BaseReconcileContext) Context

func (rc *BaseReconcileContext) Context() context.Context

func (*BaseReconcileContext) Debug

func (rc *BaseReconcileContext) Debug() bool

func (*BaseReconcileContext) ExecuteCommandOn

func (rc *BaseReconcileContext) ExecuteCommandOn(pod *corev1.Pod, container string, command []string, opts ExecOptions) error

func (*BaseReconcileContext) ForceRequeueAfter

func (rc *BaseReconcileContext) ForceRequeueAfter() time.Duration

func (*BaseReconcileContext) GetCrd

func (*BaseReconcileContext) Name

func (rc *BaseReconcileContext) Name() string

func (*BaseReconcileContext) NameInto

func (rc *BaseReconcileContext) NameInto(f func(name string) string) string

func (*BaseReconcileContext) Namespace

func (rc *BaseReconcileContext) Namespace() string

func (*BaseReconcileContext) NamespacedNameInto

func (rc *BaseReconcileContext) NamespacedNameInto(f func(name string) string) types.NamespacedName

func (*BaseReconcileContext) Request

func (rc *BaseReconcileContext) Request() reconcile.Request

func (*BaseReconcileContext) ResetForceRequeueAfter

func (rc *BaseReconcileContext) ResetForceRequeueAfter(d time.Duration)

func (*BaseReconcileContext) RestConfig

func (rc *BaseReconcileContext) RestConfig() *rest.Config

func (*BaseReconcileContext) Scheme

func (rc *BaseReconcileContext) Scheme() *runtime.Scheme

type BindFunc

type BindFunc func(t *Task, deferred ...bool)

func Abort

func Abort(msg string) BindFunc

func AbortWhen

func AbortWhen(cond bool, msg string) BindFunc

func Block

func Block(binds ...BindFunc) BindFunc

func Branch

func Branch(cond bool, a, b BindFunc) BindFunc

func CombineBinders

func CombineBinders(binders ...BindFunc) BindFunc

func NewStepBinder

func NewStepBinder(step Step) BindFunc

func NewStepIfBinder

func NewStepIfBinder(cond Condition, step Step) BindFunc

func Retry

func Retry(msg string) BindFunc

func RetryAfter

func RetryAfter(d time.Duration, msg string) BindFunc

func ScheduleAfter

func ScheduleAfter(d time.Duration) BindFunc

func Wait

func Wait(msg string) BindFunc

func When

func When(cond bool, a ...BindFunc) BindFunc

type Condition

type Condition interface {
	Name() string
	Evaluate(rc ReconcileContext, log logr.Logger) (bool, error)
}

func NewCachedCondition

func NewCachedCondition(cond Condition) Condition

NewCachedCondition returns a condition which evaluates only once and caches the result. Note the error will be returned only when the first time the Evaluate method is invoked. Any sequential calls return the result with a nil error.

func NewCondition

func NewCondition(name string, f ConditionFunc) Condition

type ConditionFunc

type ConditionFunc func(rc ReconcileContext, log logr.Logger) (bool, error)

type ExecOptions

type ExecOptions struct {
	Logger  logr.Logger
	Stdin   io.Reader
	Stdout  io.Writer
	Stderr  io.Writer
	Timeout time.Duration
}

type ExecuteFunc

type ExecuteFunc = func(rc ReconcileContext, flow Flow) (reconcile.Result, error)

type Executor

type Executor interface {
	Execute(rc ReconcileContext, task *Task) (reconcile.Result, error)
}

func NewExecutor

func NewExecutor(logger logr.Logger, opts ...ExecutorOption) Executor

type ExecutorOption

type ExecutorOption func(e *executor)

type Flow

type Flow interface {
	// Logger returns the logger
	Logger() logr.Logger

	// RetryAfter requeue the reconcile request after given duration and log the message and key-values.
	RetryAfter(duration time.Duration, msg string, kvs ...interface{}) (reconcile.Result, error)

	// Retry the reconcile request immediately and log the message and key-values.
	Retry(msg string, kvs ...interface{}) (reconcile.Result, error)

	// Continue the steps and log the message and key-values.
	Continue(msg string, kvs ...interface{}) (reconcile.Result, error)

	// Pass continues the steps without any logs.
	Pass() (reconcile.Result, error)

	// Wait breaks the current reconcile and wait for another reconcile request, and log the message and key-values.
	Wait(msg string, kvs ...interface{}) (reconcile.Result, error)

	// Break is same as Wait.
	Break(msg string, kvs ...interface{}) (reconcile.Result, error)

	// Error breaks the current reconcile with error and log the message and key-values.
	Error(err error, msg string, kvs ...interface{}) (reconcile.Result, error)

	// RetryErr is like Error but without returning error to the controller framework, but
	// give it a chance to retry later. Default retry period is 1s.
	RetryErr(err error, msg string, kvs ...interface{}) (reconcile.Result, error)

	// WithLogger return a flow binding to the old but with a new logger.
	WithLogger(log logr.Logger) Flow

	// WithLoggerValues returns a flow binding to the old but logs with extra values.
	WithLoggerValues(keyAndValues ...interface{}) Flow
}

Flow is a helper interface to interact with current reconcile loop and providing a logger method to get current logger (with some attached key-values).

type ReconcileContext

type ReconcileContext interface {
	ReconcileOptions

	ReconcileControl

	ReconcileRemoteCommandHelper
	ReconcileRequestHelper
	ReconcileCustomResourceDefinitionHelper

	// Client returns a API client of k8s.
	Client() client.Client
	// RestConfig returns the rest config used by client.
	RestConfig() *rest.Config
	// ClientSet returns the client set.
	ClientSet() *kubernetes.Clientset
	// Scheme returns the currently using scheme.
	Scheme() *runtime.Scheme

	// Context returns the current reconcile context.
	Context() context.Context
	// Request returns the current reconcile request.
	Request() reconcile.Request

	// Close closes the context to avoid resource leaks.
	Close() error
}

ReconcileContext declares the context for reconciliation.

type ReconcileControl

type ReconcileControl interface {
	ForceRequeueAfter() time.Duration
	ResetForceRequeueAfter(d time.Duration)
}

type ReconcileCustomResourceDefinitionHelper

type ReconcileCustomResourceDefinitionHelper interface {
	// GetCrd queries the api server and get the target custom resource definition if found.
	GetCrd(apiVersion, kind string) (*apiextensionsv1.CustomResourceDefinition, error)
}

type ReconcileOptions

type ReconcileOptions interface {
	Debug() bool
}

type ReconcileRemoteCommandHelper

type ReconcileRemoteCommandHelper interface {
	ExecuteCommandOn(pod *corev1.Pod, container string, command []string, opts ExecOptions) error
}

type ReconcileRequestHelper

type ReconcileRequestHelper interface {
	// Name is a helper method that returns the name of current reconcile object.
	Name() string
	// Namespace is a helper method that returns the namespace of current reconcile object.
	Namespace() string
	// NameInto is a helper method that returns a string like "f({name})" where name is
	// the name of current reconcile object.
	NameInto(f func(name string) string) string
	// NamespacedNameInto is a helper method that returns a namespaced name like "{namespace}/f({name})"
	// where "{namespace}/{name}" is of the current reconcile object.
	NamespacedNameInto(f func(name string) string) types.NamespacedName
}

type Step

type Step interface {
	Name() string
	Execute(rc ReconcileContext, flow Flow) (reconcile.Result, error)
}

func ExtractStepsFromBindFunc

func ExtractStepsFromBindFunc(binders ...BindFunc) []Step

func NewStep

func NewStep(name string, f ExecuteFunc) Step

func NewStepIf

func NewStepIf(cond Condition, step Step) Step

type Task

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

func NewTask

func NewTask() *Task

Jump to

Keyboard shortcuts

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