reconcile

package
v0.0.0-...-c7d55cc Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseStep

type BaseStep[T client.Object, R Req[T]] struct {
}

BaseStep is an empty struct that gives default implementation for some of the not mandatory Step functions like Setup.

func (BaseStep[T, R]) Cleanup

func (s BaseStep[T, R]) Cleanup(r R, log logr.Logger) Result

func (BaseStep[T, R]) Post

func (s BaseStep[T, R]) Post(r R, log logr.Logger) Result

func (BaseStep[T, R]) Setup

func (s BaseStep[T, R]) Setup(steps []Step[T, R], log logr.Logger)

type DefaultReq

type DefaultReq[T client.Object] struct {
	Ctx              context.Context
	Log              logr.Logger
	Request          ctrl.Request
	Client           client.Client
	Instance         T
	InstanceSnapshot T
	RequeueTimeout   time.Duration
}

DefaultReq provides the minimal implementation of a reconcile request. This can be used to embed into a CRD specific request type

func (DefaultReq[T]) Error

func (r DefaultReq[T]) Error(err error, log logr.Logger) Result

func (*DefaultReq[T]) GetClient

func (r *DefaultReq[T]) GetClient() client.Client

func (*DefaultReq[T]) GetCtx

func (r *DefaultReq[T]) GetCtx() context.Context

func (DefaultReq[T]) GetDefaultRequeueTimeout

func (r DefaultReq[T]) GetDefaultRequeueTimeout() time.Duration

func (DefaultReq[T]) GetFinalizer

func (r DefaultReq[T]) GetFinalizer() string

func (*DefaultReq[T]) GetInstance

func (r *DefaultReq[T]) GetInstance() T

func (DefaultReq[T]) GetInstanceSnapshot

func (r DefaultReq[T]) GetInstanceSnapshot() T

func (*DefaultReq[T]) GetLog

func (r *DefaultReq[T]) GetLog() logr.Logger

func (*DefaultReq[T]) GetRequest

func (r *DefaultReq[T]) GetRequest() ctrl.Request

func (DefaultReq[T]) OK

func (r DefaultReq[T]) OK() Result

func (DefaultReq[T]) Requeue

func (r DefaultReq[T]) Requeue(msg string) Result

func (DefaultReq[T]) RequeueAfter

func (r DefaultReq[T]) RequeueAfter(msg string, after *time.Duration) Result

func (*DefaultReq[T]) SnapshotInstance

func (r *DefaultReq[T]) SnapshotInstance()

type DefaultResult

type DefaultResult struct {
	ctrl.Result
	// contains filtered or unexported fields
}

func (DefaultResult) Err

func (r DefaultResult) Err() error

func (DefaultResult) IsError

func (r DefaultResult) IsError() bool

func (DefaultResult) IsOK

func (r DefaultResult) IsOK() bool

func (DefaultResult) IsRequeue

func (r DefaultResult) IsRequeue() bool

func (DefaultResult) String

func (r DefaultResult) String() string

func (DefaultResult) Unwrap

func (r DefaultResult) Unwrap() (ctrl.Result, error)

type Req

type Req[T client.Object] interface {
	GetCtx() context.Context
	GetLog() logr.Logger
	GetRequest() ctrl.Request
	GetClient() client.Client
	GetInstance() T
	SnapshotInstance()
	GetInstanceSnapshot() T
	GetDefaultRequeueTimeout() time.Duration
	GetFinalizer() string

	ResultGenerator
}

Req holds a single reconcile request T is the CRD type the reconcile request running on

type ReqHandlerBuilder

type ReqHandlerBuilder[T client.Object, R Req[T]] struct {
	// contains filtered or unexported fields
}

ReqHandlerBuilder helps building a ReqHandler. It is not intended for direct use. Use NewReqHandler() instead.

func NewReqHandler

func NewReqHandler[T client.Object, R Req[T]]() *ReqHandlerBuilder[T, R]

NewReqHandler builds up a function that can handle the current reconcile request for CRD type T with reconcile request type R. It can be configured with the functions on the returned builder to add reconciliation steps.

Step.Do() is called in the order of the Steps added to the handler when CR is reconciled normally. Step.Cleanup() called in the reverse order of the Steps added when the CR is being deleted. Step.Post() is called in order of the Steps added after all the Step's Do or Cleanup function is executed, or one of those functions returned error or requested requeue.

func (*ReqHandlerBuilder[T, R]) Handle

func (builder *ReqHandlerBuilder[T, R]) Handle(request R) (ctrl.Result, error)

Handle builds the request handler for the request and executes defined steps to reconcile the request

func (*ReqHandlerBuilder[T, R]) WithSteps

func (builder *ReqHandlerBuilder[T, R]) WithSteps(steps ...Step[T, R]) *ReqHandlerBuilder[T, R]

WithSteps adds steps to handle the reconciliation of the instance T

type Result

type Result interface {
	Unwrap() (ctrl.Result, error)
	String() string
	Err() error
	IsError() bool
	IsRequeue() bool
	IsOK() bool
}

Result defines the outcome of a given reconciliation call

type ResultGenerator

type ResultGenerator interface {
	OK() Result
	Error(error, logr.Logger) Result
	Requeue(msg string) Result
	RequeueAfter(msg string, after *time.Duration) Result
}

type Step

type Step[T client.Object, R Req[T]] interface {
	// GetName returns the name of the step
	GetName() string
	// Setup allow late initialization of the step based on all the
	// other steps added to the RequestHandler. It runs before any Step
	// execution.
	Setup(steps []Step[T, R], log logr.Logger)
	// Do actual reconciliation step on the request.
	// The passed in logger is already set up to have the step name as a
	// context.
	// If Do returns error or requests a requeue then no other Step's Do()
	// function run and the engine moves to execute the Post calls
	// of each Step and then saves the CR.
	Do(r R, log logr.Logger) Result
	// Cleanup resources and finalizers during the deletion of the CR.
	// If Cleanup returns an error or requests a requeue then no other Step's
	// Cleanup run and the engine moves to execute the Post calls
	// of each Step and then saves the CR.
	Cleanup(r R, log logr.Logger) Result
	// Post is called after each step's Do or Cleanup to do late actions
	// just before persisting the CR and returning a result to the
	// controller-runtime.
	// If Post returns an error or requests a requeue then no other Step's
	// Post runs and the engine just saves the CR.
	Post(r R, log logr.Logger) Result
}

Step defines a logical step during the reconciliation of the T CRD type with the R reconcile request type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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