control

package
v0.0.0-...-d57715f Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: GPL-3.0 Imports: 32 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 {
	ReconcileHelper
	// contains filtered or unexported fields
}

func NewBaseReconcileContext

func NewBaseReconcileContext(h ReconcileHelper, context context.Context, request reconcile.Request, owner client.FieldOwner, recorder record.EventRecorder) *BaseReconcileContext

func (*BaseReconcileContext) Apply

func (rc *BaseReconcileContext) Apply(object client.Object) error

apply sends an apply patch to object's endpoint in the Kubernetes API and updates object with any returned content. The fieldManager is set to r.Owner and the force parameter is true. - https://docs.k8s.io/reference/using-api/server-side-apply/#managers - https://docs.k8s.io/reference/using-api/server-side-apply/#conflicts

func (*BaseReconcileContext) CSAApply

func (rc *BaseReconcileContext) CSAApply(object client.Object, oldObject ...client.Object) error

when not support server-side apply, use it

func (*BaseReconcileContext) Close

func (rc *BaseReconcileContext) Close() error

func (*BaseReconcileContext) Context

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

func (*BaseReconcileContext) Get

func (rc *BaseReconcileContext) Get(object client.Object) error

func (*BaseReconcileContext) List

func (rc *BaseReconcileContext) List(list client.ObjectList, selector labels.Selector) error

func (*BaseReconcileContext) Name

func (rc *BaseReconcileContext) Name() string

func (*BaseReconcileContext) Namespace

func (rc *BaseReconcileContext) Namespace() string

func (*BaseReconcileContext) Owner

func (*BaseReconcileContext) Patch

func (rc *BaseReconcileContext) Patch(object client.Object,
	patch client.Patch, options ...client.PatchOption,
) error

Patch sends patch to object's endpoint in the Kubernetes API and updates object with any returned content. The fieldManager is set to r.Owner, but can be overridden in options. - https://docs.k8s.io/reference/using-api/server-side-apply/#managers

func (*BaseReconcileContext) Recorder

func (rc *BaseReconcileContext) Recorder() record.EventRecorder

func (*BaseReconcileContext) Request

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

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 DefaultReconcileHelper

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

func NewDefaultReconcileHelper

func NewDefaultReconcileHelper(
	client client.Client,
	restConfig *rest.Config,
	clientSet *kubernetes.Clientset,
	scheme *runtime.Scheme,
) *DefaultReconcileHelper

func NewDefaultReconcileHelperWithManager

func NewDefaultReconcileHelperWithManager(mgr manager.Manager) (helper *DefaultReconcileHelper, err error)

func (*DefaultReconcileHelper) Client

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

func (*DefaultReconcileHelper) ClientSet

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

func (*DefaultReconcileHelper) Debug

func (rc *DefaultReconcileHelper) Debug() bool

func (*DefaultReconcileHelper) ForceRequeueAfter

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

func (*DefaultReconcileHelper) PodExec

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

func (*DefaultReconcileHelper) ResetForceRequeueAfter

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

func (*DefaultReconcileHelper) RestConfig

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

func (*DefaultReconcileHelper) Scheme

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

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 {
	ReconcileHelper

	// 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
	// Context returns the current reconcile context.
	Context() context.Context
	// Request returns the current reconcile request.
	Request() reconcile.Request
	// Owner returns the current reconcile fieldOwner.
	Owner() client.FieldOwner
	// Recorder returns the current reconcile recorder.
	Recorder() record.EventRecorder

	Get(object client.Object) error
	List(list client.ObjectList, selector labels.Selector) error
	Patch(object client.Object, patch client.Patch, options ...client.PatchOption) error
	Apply(object client.Object) error                       // Server-Side Apply
	CSAApply(new client.Object, old ...client.Object) error // Client-Side Apply
	Close() error
}

ReconcileContext declares the context for reconciliation.

type ReconcileHelper

type ReconcileHelper interface {
	ReconcilePodExecCommandHelper

	Debug() bool

	ForceRequeueAfter() time.Duration
	ResetForceRequeueAfter(d time.Duration)

	// 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
}

ReconcileHelper declares the reconcile helper.

type ReconcilePodExecCommandHelper

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

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