controller

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 26 Imported by: 12

Documentation

Index

Constants

View Source
const (
	RunningPhase   shared.PhaseName     = "running"
	StartingPhase  shared.PhaseName     = "starting"
	ReadyCondition shared.ConditionName = "Ready"
	BaseAnnotation string               = "operator-sdk-extra.webcenter.fr"
	ShortenError   int                  = 100
)

Variables

View Source
var (
	ErrWhenCallConfigureFromReconciler      = errors.Sentinel("Error when call 'configure' from reconciler")
	ErrWhenCallReadFromReconciler           = errors.Sentinel("Error when call 'read' from reconciler")
	ErrWhenCallDeleteFromReconciler         = errors.Sentinel("Error when call 'delete' from reconciler")
	ErrWhenCallDiffFromReconciler           = errors.Sentinel("Error when call 'diff' from reconciler")
	ErrWhenCallCreateFromReconciler         = errors.Sentinel("Error when call 'create' from reconciler")
	ErrWhenCallUpdateFromReconciler         = errors.Sentinel("Error when call 'update' from reconciler")
	ErrWhenCallOnSuccessFromReconciler      = errors.Sentinel("Error when call 'onSuccess' from reconciler")
	ErrWhenCallStepReconcilerFromReconciler = errors.Sentinel("Error when call 'reconcile' from step reconciler")
	ErrWhenGetObjectFromReconciler          = errors.Sentinel("Error when get object from reconciler")
	ErrWhenAddFinalizer                     = errors.Sentinel("Error when add finalizer")
	ErrWhenDeleteFinalizer                  = errors.Sentinel("Error when delete finalizer")
	ErrWhenGetObjectStatus                  = errors.Sentinel("Error when get object status")
)

Functions

func SetupIndexerWithManager added in v0.1.3

func SetupIndexerWithManager(mgr ctrl.Manager, indexers ...Indexer) (err error)

SetupIndexerWithManager permit to registers indexers on manager

Types

type BaseReconciler added in v0.1.3

type BaseReconciler struct {
	client.Client
	Log      *logrus.Entry
	Recorder record.EventRecorder
}

BaseReconciler is the base attributes for all reconciler

type BasicController added in v0.1.3

type BasicController struct{}

BasicController is the default controller implementation

func (*BasicController) Reconcile added in v0.1.3

func (*BasicController) SetupWithManager added in v0.1.3

func (h *BasicController) SetupWithManager(mgr ctrl.Manager) error

type BasicMultiPhaseDiff added in v0.1.3

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

BasicMultiPhaseDiff is the basic implementation of MultiPhaseDiff interface

func (*BasicMultiPhaseDiff) AddDiff added in v0.1.3

func (h *BasicMultiPhaseDiff) AddDiff(diff string)

func (*BasicMultiPhaseDiff) Diff added in v0.1.3

func (h *BasicMultiPhaseDiff) Diff() string

func (*BasicMultiPhaseDiff) GetObjectsToCreate added in v0.1.3

func (h *BasicMultiPhaseDiff) GetObjectsToCreate() []client.Object

func (*BasicMultiPhaseDiff) GetObjectsToDelete added in v0.1.3

func (h *BasicMultiPhaseDiff) GetObjectsToDelete() []client.Object

func (*BasicMultiPhaseDiff) GetObjectsToUpdate added in v0.1.3

func (h *BasicMultiPhaseDiff) GetObjectsToUpdate() []client.Object

func (*BasicMultiPhaseDiff) IsDiff added in v0.1.3

func (h *BasicMultiPhaseDiff) IsDiff() bool

func (*BasicMultiPhaseDiff) NeedCreate added in v0.1.3

func (h *BasicMultiPhaseDiff) NeedCreate() bool

func (*BasicMultiPhaseDiff) NeedDelete added in v0.1.3

func (h *BasicMultiPhaseDiff) NeedDelete() bool

func (*BasicMultiPhaseDiff) NeedUpdate added in v0.1.3

func (h *BasicMultiPhaseDiff) NeedUpdate() bool

func (*BasicMultiPhaseDiff) SetObjectsToCreate added in v0.1.3

func (h *BasicMultiPhaseDiff) SetObjectsToCreate(objects []client.Object)

func (*BasicMultiPhaseDiff) SetObjectsToDelete added in v0.1.3

func (h *BasicMultiPhaseDiff) SetObjectsToDelete(objects []client.Object)

func (*BasicMultiPhaseDiff) SetObjectsToUpdate added in v0.1.3

func (h *BasicMultiPhaseDiff) SetObjectsToUpdate(objects []client.Object)

type BasicMultiPhaseRead added in v0.1.3

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

BasicMultiPhaseRead is the basic implementation if MultiPhaseRead

func (*BasicMultiPhaseRead) GetCurrentObjects added in v0.1.3

func (h *BasicMultiPhaseRead) GetCurrentObjects() []client.Object

func (*BasicMultiPhaseRead) GetExpectedObjects added in v0.1.3

func (h *BasicMultiPhaseRead) GetExpectedObjects() []client.Object

func (*BasicMultiPhaseRead) SetCurrentObjects added in v0.1.3

func (h *BasicMultiPhaseRead) SetCurrentObjects(objects []client.Object)

func (*BasicMultiPhaseRead) SetExpectedObjects added in v0.1.3

func (h *BasicMultiPhaseRead) SetExpectedObjects(objects []client.Object)

type BasicMultiPhaseReconciler added in v0.1.3

type BasicMultiPhaseReconciler struct {
	BasicReconciler
}

BasicMultiPhaseReconciler is the basic multi phase reconsiler you can used whe you should to create multiple k8s resources

func (*BasicMultiPhaseReconciler) Reconcile added in v0.1.3

func (h *BasicMultiPhaseReconciler) Reconcile(ctx context.Context, req ctrl.Request, o object.MultiPhaseObject, data map[string]interface{}, reconcilerAction MultiPhaseReconcilerAction, reconcilersStepAction ...MultiPhaseStepReconcilerAction) (res ctrl.Result, err error)

type BasicMultiPhaseReconcilerAction added in v0.1.3

type BasicMultiPhaseReconcilerAction struct {
	BasicReconcilerAction
}

BasicMultiPhaseReconcilerAction is the basic implementation of MultiPhaseReconcilerAction interface

func (*BasicMultiPhaseReconcilerAction) Configure added in v0.1.3

func (*BasicMultiPhaseReconcilerAction) Delete added in v0.1.3

func (*BasicMultiPhaseReconcilerAction) OnError added in v0.1.3

func (h *BasicMultiPhaseReconcilerAction) OnError(ctx context.Context, o object.MultiPhaseObject, data map[string]any, currentErr error) (res ctrl.Result, err error)

func (*BasicMultiPhaseReconcilerAction) OnSuccess added in v0.1.3

func (*BasicMultiPhaseReconcilerAction) Read added in v0.1.3

type BasicMultiPhaseStepReconciler added in v0.1.3

type BasicMultiPhaseStepReconciler struct {
	BaseReconciler
}

BasicMultiPhaseStepReconciler is the basic implementation of MultiPhaseStepReconciler interface

func (*BasicMultiPhaseStepReconciler) Reconcile added in v0.1.3

func (h *BasicMultiPhaseStepReconciler) Reconcile(ctx context.Context, req ctrl.Request, o object.MultiPhaseObject, data map[string]interface{}, reconcilerAction MultiPhaseStepReconcilerAction, ignoresDiff ...patch.CalculateOption) (res ctrl.Result, err error)

Reconcile permit to reconcile the step (one K8s resource)

type BasicMultiPhaseStepReconcilerAction added in v0.1.3

type BasicMultiPhaseStepReconcilerAction struct {
	BasicReconcilerAction
	// contains filtered or unexported fields
}

BasicMultiPhaseStepReconcilerAction is the basic implementation of MultiPhaseStepReconcilerAction

func (*BasicMultiPhaseStepReconcilerAction) Configure added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) Create added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) Delete added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) Diff added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) GetIgnoresDiff added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) GetPhaseName added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) OnError added in v0.1.3

func (h *BasicMultiPhaseStepReconcilerAction) OnError(ctx context.Context, o object.MultiPhaseObject, data map[string]any, currentErr error) (res ctrl.Result, err error)

func (*BasicMultiPhaseStepReconcilerAction) OnSuccess added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) Read added in v0.1.3

func (*BasicMultiPhaseStepReconcilerAction) Update added in v0.1.3

type BasicReconciler added in v0.1.3

type BasicReconciler struct {
	BaseReconciler
	// contains filtered or unexported fields
}

BasicReconciler is the basic implementation of BaseReconciler It also provide attributes needed by all reconciler

type BasicReconcilerAction added in v0.1.3

type BasicReconcilerAction struct {
	BaseReconciler
	// contains filtered or unexported fields
}

BasicReconcilerAction provide attribute needed by all reconciler action

type BasicRemoteDiff added in v0.1.3

type BasicRemoteDiff[T any] struct {
	// contains filtered or unexported fields
}

BasicRemoteDiff is the basic implementation of RemoteDiff interface

func (*BasicRemoteDiff[T]) AddDiff added in v0.1.3

func (h *BasicRemoteDiff[T]) AddDiff(diff string)

func (*BasicRemoteDiff[T]) Diff added in v0.1.3

func (h *BasicRemoteDiff[T]) Diff() string

func (*BasicRemoteDiff[T]) GetObjectToCreate added in v0.1.3

func (h *BasicRemoteDiff[T]) GetObjectToCreate() T

func (*BasicRemoteDiff[T]) GetObjectToUpdate added in v0.1.3

func (h *BasicRemoteDiff[T]) GetObjectToUpdate() T

func (*BasicRemoteDiff[T]) IsDiff added in v0.1.3

func (h *BasicRemoteDiff[T]) IsDiff() bool

func (*BasicRemoteDiff[T]) NeedCreate added in v0.1.3

func (h *BasicRemoteDiff[T]) NeedCreate() bool

func (*BasicRemoteDiff[T]) NeedUpdate added in v0.1.3

func (h *BasicRemoteDiff[T]) NeedUpdate() bool

func (*BasicRemoteDiff[T]) SetObjectToCreate added in v0.1.3

func (h *BasicRemoteDiff[T]) SetObjectToCreate(object T)

func (*BasicRemoteDiff[T]) SetObjectToUpdate added in v0.1.3

func (h *BasicRemoteDiff[T]) SetObjectToUpdate(object T)

type BasicRemoteExternalReconciler added in v0.1.3

type BasicRemoteExternalReconciler[k8sObject comparable, apiObject comparable, apiClient any] struct {
	// contains filtered or unexported fields
}

BasicRemoteExternalReconciler is the basic implementation of RemoteExternalReconciler It only implement the Diff method, because of is generic with 3-way merge patch

func NewBasicRemoteExternalReconciler added in v0.1.3

func NewBasicRemoteExternalReconciler[k8sObject comparable, apiObject comparable, apiClient any](handler apiClient) *BasicRemoteExternalReconciler[k8sObject, apiObject, apiClient]

func (*BasicRemoteExternalReconciler[k8sObject, apiObject, apiClient]) Client added in v0.1.3

func (h *BasicRemoteExternalReconciler[k8sObject, apiObject, apiClient]) Client() apiClient

func (*BasicRemoteExternalReconciler[k8sObject, apiObject, apiClient]) Diff added in v0.1.3

func (h *BasicRemoteExternalReconciler[k8sObject, apiObject, apiClient]) Diff(currentOject apiObject, expectedObject apiObject, originalObject apiObject, ignoresDiff ...patch.CalculateOption) (patchResult *patch.PatchResult, err error)

type BasicRemoteRead added in v0.1.3

type BasicRemoteRead[T any] struct {
	// contains filtered or unexported fields
}

BasicMultiPhaseRead is the basic implementation if MultiPhaseRead

func (*BasicRemoteRead[T]) GetCurrentObject added in v0.1.3

func (h *BasicRemoteRead[T]) GetCurrentObject() T

func (*BasicRemoteRead[T]) GetExpectedObject added in v0.1.3

func (h *BasicRemoteRead[T]) GetExpectedObject() T

func (*BasicRemoteRead[T]) SetCurrentObject added in v0.1.3

func (h *BasicRemoteRead[T]) SetCurrentObject(object T)

func (*BasicRemoteRead[T]) SetExpectedObject added in v0.1.3

func (h *BasicRemoteRead[T]) SetExpectedObject(object T)

type BasicRemoteReconciler added in v0.1.3

type BasicRemoteReconciler[k8sObject comparable, apiObject comparable, apiClient any] struct {
	BasicReconciler
}

BasicRemoteReconciler is the basic implementation of RemoteReconciler interface

func (*BasicRemoteReconciler[k8sObject, apiObject, apiClient]) Reconcile added in v0.1.3

func (h *BasicRemoteReconciler[k8sObject, apiObject, apiClient]) Reconcile(ctx context.Context, req ctrl.Request, o object.RemoteObject, data map[string]interface{}, reconciler RemoteReconcilerAction[k8sObject, apiObject, apiClient]) (res ctrl.Result, err error)

type BasicRemoteReconcilerAction added in v0.1.3

type BasicRemoteReconcilerAction[k8sObject comparable, apiObject comparable, apiClient any] struct {
	BasicReconcilerAction
}

BasicRemoteReconcilerAction is the basic implementation of RemoteReconcilerAction

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Configure added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Configure(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient]) (res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Create added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Create(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], object apiObject) (res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Delete added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Delete(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient]) (err error)

Delete can be call on your own version It only add some log / events

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Diff added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Diff(ctx context.Context, o object.RemoteObject, read RemoteRead[apiObject], data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], ignoreDiff ...patch.CalculateOption) (diff RemoteDiff[apiObject], res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) GetIgnoresDiff added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) GetIgnoresDiff() []patch.CalculateOption

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) GetRemoteHandler added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) GetRemoteHandler(ctx context.Context, req ctrl.Request, o object.RemoteObject) (handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) OnError added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) OnError(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], currentErr error) (res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) OnSuccess added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) OnSuccess(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], diff RemoteDiff[apiObject]) (res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Read added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Read(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient]) (read RemoteRead[apiObject], res ctrl.Result, err error)

func (*BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Update added in v0.1.3

func (h *BasicRemoteReconcilerAction[k8sObject, apiObject, apiClient]) Update(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], object apiObject) (res ctrl.Result, err error)

Update can be call on your own version It only add some log / events

type Controller added in v0.1.3

type Controller interface {
	Reconcile(context.Context, reconcile.Request) (reconcile.Result, error)

	// SetupWithManager permit to setup controller with manager
	SetupWithManager(mgr ctrl.Manager) error
}

Controller is the controller interface

func NewBasicController added in v0.1.3

func NewBasicController() Controller

NewBasicController is the default constructor for Controller index can be nil

type Diff

type Diff struct {
	NeedCreate bool
	NeedUpdate bool
	Diff       string
}

type Indexer added in v0.1.3

type Indexer func(mgr ctrl.Manager) error

Indexer is a function to add indexer on manager

type K8sDiff added in v0.1.0

type K8sDiff struct {
	NeedCreate bool
	NeedUpdate bool
	NeedDelete bool
	Diff       strings.Builder
}

type K8sPhaseReconciler deprecated added in v0.1.0

type K8sPhaseReconciler interface {
	// Configure permit to init condition on status
	Configure(ctx context.Context, req ctrl.Request, resource client.Object) (res ctrl.Result, err error)

	// Read permit to read kubernetes resources
	Read(ctx context.Context, r client.Object, data map[string]any) (res ctrl.Result, err error)

	// Create permit to create resources on kubernetes
	Create(ctx context.Context, r client.Object, data map[string]any) (res ctrl.Result, err error)

	// Update permit to update resources on kubernetes
	Update(ctx context.Context, r client.Object, data map[string]any) (res ctrl.Result, err error)

	// Delete permit to delete resources on kubernetes
	Delete(ctx context.Context, r client.Object, data map[string]any) (res ctrl.Result, err error)

	// OnError is call when error is throwing on current phase
	// It the right way to set status condition when error
	OnError(ctx context.Context, r client.Object, data map[string]any, currentErr error) (res ctrl.Result, err error)

	// OnSuccess is call at the end of current phase, if not error
	// It's the right way to set status condition when everithink is good
	OnSuccess(ctx context.Context, r client.Object, data map[string]any, diff K8sDiff) (res ctrl.Result, err error)

	// Diff permit to compare the actual state and the expected state
	Diff(ctx context.Context, r client.Object, data map[string]any) (diff K8sDiff, res ctrl.Result, err error)

	// GetName return the reconciler name
	GetName() string
}

Deprecated: use MultiPhaseStepReconcilerAction instead

type K8sReconciler deprecated added in v0.1.0

type K8sReconciler interface {
	// Configure permit to init condition on status
	Configure(ctx context.Context, req ctrl.Request, resource client.Object) (res ctrl.Result, err error)

	// Read permit to read kubernetes resources
	Read(ctx context.Context, r client.Object, data map[string]any) (res ctrl.Result, err error)

	// Delete permit to delete resources on kubernetes
	Delete(ctx context.Context, r client.Object, data map[string]any) (err error)

	// OnError is call when error is throwing on current phase
	// It the right way to set status condition when error
	OnError(ctx context.Context, r client.Object, data map[string]any, currentErr error) (res ctrl.Result, err error)

	// OnSuccess is call at the end of current phase, if not error
	// It's the right way to set status condition when everithink is good
	OnSuccess(ctx context.Context, r client.Object, data map[string]any) (res ctrl.Result, err error)
}

Deprecated: use MultiPhaseReconcilerAction instead

type MultiPhaseDiff added in v0.1.3

type MultiPhaseDiff interface {

	// NeedCreate is true when need to create K8s object
	NeedCreate() bool

	// NeedUpdate is true when need to update K8s object
	NeedUpdate() bool

	// NeedDelete is true when need to delete K8s object
	NeedDelete() bool

	// GetObjectsToCreate is the list of object to create on K8s
	GetObjectsToCreate() []client.Object

	// SetObjectsToCreate permit to set the list of object to create on K8s
	SetObjectsToCreate(objects []client.Object)

	// GetObjectsToUpdate is the list of object to update on K8s
	GetObjectsToUpdate() []client.Object

	// SetObjectsToUpdate permit to set the list of object to update on K8s
	SetObjectsToUpdate(objects []client.Object)

	// GetObjectsToDelete is the list of Object to delete on K8s
	GetObjectsToDelete() []client.Object

	// SetObjectsToDelete permit to set the list of object to delete
	SetObjectsToDelete(objects []client.Object)

	// AddDiff permit to add diff
	// It add return line at the end
	AddDiff(diff string)

	// Diff permit to print human diff
	Diff() string

	// IsDiff permit to know is there are current diff to print
	IsDiff() bool
}

MultiPhaseDiff is used to know if currents resources differ with expected

func NewBasicMultiPhaseDiff added in v0.1.3

func NewBasicMultiPhaseDiff() MultiPhaseDiff

NewBasicMultiPhaseDiff is the basic contructor of MultiPhaseDiff interface

type MultiPhaseRead added in v0.1.3

type MultiPhaseRead interface {

	// GetCurrentObjects permit to get the list of current objects
	GetCurrentObjects() []client.Object

	// SetCurrentObjects permit to set the list of current objects
	SetCurrentObjects(objects []client.Object)

	// GetExpectedObjects permit to get the list of expected objects
	GetExpectedObjects() []client.Object

	// SetExpectedObjects permit to set the list of expected objects
	SetExpectedObjects(objects []client.Object)
}

MultiPhaseRead is the interface to store the result of read step on multi phase reconciler

func NewBasicMultiPhaseRead added in v0.1.3

func NewBasicMultiPhaseRead() MultiPhaseRead

NewBasicMultiPhaseRead is the basic constructor of MultiPhaseRead interface

type MultiPhaseReconciler added in v0.1.3

type MultiPhaseReconciler interface {

	// Reconcile permit to orchestrate all phase needed to successfully reconcile the object
	Reconcile(ctx context.Context, req ctrl.Request, o object.MultiPhaseObject, data map[string]interface{}, reconciler MultiPhaseReconcilerAction, reconcilersStep ...MultiPhaseStepReconcilerAction) (res ctrl.Result, err error)
}

MultiPhaseReconciler the reconciler to implement whe you need to create multiple resources on k8s

func NewBasicMultiPhaseReconciler added in v0.1.3

func NewBasicMultiPhaseReconciler(client client.Client, name string, finalizer shared.FinalizerName, logger *logrus.Entry, recorder record.EventRecorder) (multiPhaseReconciler MultiPhaseReconciler)

NewBasicMultiPhaseReconciler permit to instanciate new basic multiphase resonciler

type MultiPhaseReconcilerAction added in v0.1.3

type MultiPhaseReconcilerAction interface {

	// Configure permit to init condition on status
	Configure(ctx context.Context, req ctrl.Request, o object.MultiPhaseObject) (res ctrl.Result, err error)

	// Read permit to read kubernetes resources
	Read(ctx context.Context, o object.MultiPhaseObject, data map[string]any) (res ctrl.Result, err error)

	// Delete permit to delete resources on kubernetes
	Delete(ctx context.Context, o object.MultiPhaseObject, data map[string]any) (err error)

	// OnError is call when error is throwing on current phase
	// It the right way to set status condition when error
	OnError(ctx context.Context, o object.MultiPhaseObject, data map[string]any, currentErr error) (res ctrl.Result, err error)

	// OnSuccess is call at the end of current phase, if not error
	// It's the right way to set status condition when everithink is good
	OnSuccess(ctx context.Context, o object.MultiPhaseObject, data map[string]any) (res ctrl.Result, err error)
}

MultiPhaseReconcilerAction is the methode needed by step reconciler to reconcile your custom resource

func NewBasicMultiPhaseReconcilerAction added in v0.1.3

func NewBasicMultiPhaseReconcilerAction(client client.Client, conditionName shared.ConditionName, logger *logrus.Entry, recorder record.EventRecorder) (multiPhaseReconciler MultiPhaseReconcilerAction)

NewBasicMultiPhaseReconcilerAction is the basic contructor of MultiPhaseReconcilerAction interface

type MultiPhaseStepReconciler added in v0.1.3

type MultiPhaseStepReconciler interface {

	// Reconcile permit to reconcile the step (one K8s resource)
	Reconcile(ctx context.Context, req ctrl.Request, o object.MultiPhaseObject, data map[string]interface{}, reconciler MultiPhaseStepReconcilerAction, ignoresDiff ...patch.CalculateOption) (res ctrl.Result, err error)
}

MultiPhaseStepReconciler is the reconciler to implement to create one step for MultiPhaseReconciler

func NewBasicMultiPhaseStepReconciler added in v0.1.3

func NewBasicMultiPhaseStepReconciler(client client.Client, logger *logrus.Entry, recorder record.EventRecorder) (multiPhaseStepReconciler MultiPhaseStepReconciler)

NewBasicMultiPhaseStepReconciler is the basic constructor of MultiPhaseStepReconciler interface

type MultiPhaseStepReconcilerAction added in v0.1.3

type MultiPhaseStepReconcilerAction interface {

	// Configure permit to init condition on status
	Configure(ctx context.Context, req ctrl.Request, o object.MultiPhaseObject) (res ctrl.Result, err error)

	// Read permit to read kubernetes resources
	Read(ctx context.Context, o object.MultiPhaseObject, data map[string]any) (read MultiPhaseRead, res ctrl.Result, err error)

	// Create permit to create resources on kubernetes
	Create(ctx context.Context, o object.MultiPhaseObject, data map[string]any, objects []client.Object) (res ctrl.Result, err error)

	// Update permit to update resources on kubernetes
	Update(ctx context.Context, o object.MultiPhaseObject, data map[string]any, objects []client.Object) (res ctrl.Result, err error)

	// Delete permit to delete resources on kubernetes
	Delete(ctx context.Context, o object.MultiPhaseObject, data map[string]any, objects []client.Object) (res ctrl.Result, err error)

	// OnError is call when error is throwing on current phase
	// It the right way to set status condition when error
	OnError(ctx context.Context, o object.MultiPhaseObject, data map[string]any, currentErr error) (res ctrl.Result, err error)

	// OnSuccess is call at the end of current phase, if not error
	// It's the right way to set status condition when everithink is good
	OnSuccess(ctx context.Context, o object.MultiPhaseObject, data map[string]any, diff MultiPhaseDiff) (res ctrl.Result, err error)

	// Diff permit to compare the actual state and the expected state
	Diff(ctx context.Context, o object.MultiPhaseObject, read MultiPhaseRead, data map[string]any, ignoreDiff ...patch.CalculateOption) (diff MultiPhaseDiff, res ctrl.Result, err error)

	// GetPhaseName permit to get the phase name
	GetPhaseName() shared.PhaseName

	GetIgnoresDiff() []patch.CalculateOption
}

MultiPhaseStepReconcilerAction is the interface that use by reconciler step to reconcile your intermediate K8s resources

func NewBasicMultiPhaseStepReconcilerAction added in v0.1.3

func NewBasicMultiPhaseStepReconcilerAction(client client.Client, phaseName shared.PhaseName, conditionName shared.ConditionName, logger *logrus.Entry, recorder record.EventRecorder) (multiPhaseStepReconciler MultiPhaseStepReconcilerAction)

NewBasicMultiPhaseStepReconcilerAction is the basic constructor of MultiPhaseStepReconcilerAction interface

type Reconciler deprecated

type Reconciler interface {
	// Confirgure permit to init external provider driver (API client REST)
	// It can also permit to init condition on status
	Configure(ctx context.Context, req ctrl.Request, resource client.Object) (meta any, err error)

	// Read permit to read the actual resource state from provider and set it on data map
	Read(ctx context.Context, r client.Object, data map[string]any, meta any) (res ctrl.Result, err error)

	// Create permit to create resource on provider
	// It only call if diff.NeeCreated is true
	Create(ctx context.Context, r client.Object, data map[string]any, meta any) (res ctrl.Result, err error)

	// Update permit to update resource on provider
	// It only call if diff.NeedUpdated is true
	Update(ctx context.Context, r client.Object, data map[string]any, meta any) (res ctrl.Result, err error)

	// Delete permit to delete resource on provider
	// It only call if you have specified finalizer name when you create reconciler and if resource as marked to be deleted
	Delete(ctx context.Context, r client.Object, data map[string]any, meta any) (err error)

	// OnError is call when error is throwing
	// It the right way to set status condition when error
	OnError(ctx context.Context, r client.Object, data map[string]any, meta any, err error)

	// OnSuccess is call at the end if no error
	// It's the right way to set status condition when everithink is good
	OnSuccess(ctx context.Context, r client.Object, data map[string]any, meta any, diff Diff) (err error)

	// Diff permit to compare the actual state and the expected state
	Diff(r client.Object, data map[string]any, meta any) (diff Diff, err error)
}

Deprecated: Use RemoteReconcilerAction instead

type RemoteDiff added in v0.1.3

type RemoteDiff[T any] interface {

	// NeedCreate is true when need to create K8s object
	NeedCreate() bool

	// NeedUpdate is true when need to update K8s object
	NeedUpdate() bool

	// GetObjectsToCreate is the list of object to create on K8s
	GetObjectToCreate() T

	// SetObjectsToCreate permit to set the list of object to create on K8s
	SetObjectToCreate(object T)

	// GetObjectsToUpdate is the list of object to update on K8s
	GetObjectToUpdate() T

	// SetObjectsToUpdate permit to set the list of object to update on K8s
	SetObjectToUpdate(object T)

	// AddDiff permit to add diff
	// It add return line at the end
	AddDiff(diff string)

	// Diff permit to print human diff
	Diff() string

	// IsDiff permit to know is there are current diff to print
	IsDiff() bool
}

func NewBasicRemoteDiff added in v0.1.3

func NewBasicRemoteDiff[T any]() RemoteDiff[T]

NewBasicRemoteDiff is the basic contructor of RemoteDiff interface

type RemoteExternalReconciler added in v0.1.3

type RemoteExternalReconciler[k8sObject comparable, apiObject comparable, apiClient any] interface {
	Build(k8sO k8sObject) (object apiObject, err error)
	Get(k8sO k8sObject) (object apiObject, err error)
	Create(apiO apiObject, k8sO k8sObject) (err error)
	Update(apiO apiObject, k8sO k8sObject) (err error)
	Delete(k8sO k8sObject) (err error)
	Diff(currentOject apiObject, expectedObject apiObject, originalObject apiObject, ignoresDiff ...patch.CalculateOption) (patchResult *patch.PatchResult, err error)
	Client() apiClient
}

RemoteExternalReconciler is the interface to call the remote API to handler resource

type RemoteRead added in v0.1.3

type RemoteRead[T any] interface {

	// GetCurrentObject permit to get the current object
	GetCurrentObject() T

	// SetCurrentObject permit to set the current object
	SetCurrentObject(object T)

	// GetExpectedObject permit to get the  expected object
	GetExpectedObject() T

	// SetExpectedObject permit to set the expected object
	SetExpectedObject(object T)
}

RemoteRead is the interface to store the result of read on remote reconciler

func NewBasicRemoteRead added in v0.1.3

func NewBasicRemoteRead[T any]() RemoteRead[T]

NewBasicRemoteRead is the basic constructor of RemoteRead interface

type RemoteReconciler added in v0.1.3

type RemoteReconciler[k8sObject comparable, apiObject comparable, apiClient any] interface {

	// Reconcile permit to reconcile the step (one K8s resource)
	Reconcile(ctx context.Context, req ctrl.Request, o object.RemoteObject, data map[string]interface{}, reconciler RemoteReconcilerAction[k8sObject, apiObject, apiClient]) (res ctrl.Result, err error)
}

RemoteReconciler is the reconciler to reconcile the remote resource

func NewBasicRemoteReconciler added in v0.1.3

func NewBasicRemoteReconciler[k8sObject comparable, apiObject comparable, apiClient any](client client.Client, name string, finalizer shared.FinalizerName, logger *logrus.Entry, recorder record.EventRecorder) (remoteReconciler RemoteReconciler[k8sObject, apiObject, apiClient])

NewBasicMultiPhaseReconciler permit to instanciate new basic multiphase resonciler

type RemoteReconcilerAction added in v0.1.3

type RemoteReconcilerAction[k8sObject comparable, apiObject comparable, apiClient any] interface {

	// GetRemoteHandler permit to get the handler to manage the remote resources
	GetRemoteHandler(ctx context.Context, req ctrl.Request, o object.RemoteObject) (handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], res ctrl.Result, err error)

	// Confirgure permit to init external provider driver (API client REST)
	// It can also permit to init condition on status
	Configure(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient]) (res ctrl.Result, err error)

	// Read permit to read the actual resource state from provider and set it on data map
	Read(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient]) (read RemoteRead[apiObject], res ctrl.Result, err error)

	// Create permit to create resource on provider
	// It only call if diff.NeeCreated is true
	Create(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], object apiObject) (res ctrl.Result, err error)

	// Update permit to update resource on provider
	// It only call if diff.NeedUpdated is true
	Update(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], object apiObject) (res ctrl.Result, err error)

	// Delete permit to delete resource on provider
	// It only call if you have specified finalizer name when you create reconciler and if resource as marked to be deleted
	Delete(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient]) (err error)

	// OnError is call when error is throwing
	// It the right way to set status condition when error
	OnError(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], currentErr error) (res ctrl.Result, err error)

	// OnSuccess is call at the end if no error
	// It's the right way to set status condition when everithink is good
	OnSuccess(ctx context.Context, o object.RemoteObject, data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], diff RemoteDiff[apiObject]) (res ctrl.Result, err error)

	// Diff permit to compare the actual state and the expected state
	Diff(ctx context.Context, o object.RemoteObject, read RemoteRead[apiObject], data map[string]any, handler RemoteExternalReconciler[k8sObject, apiObject, apiClient], ignoreDiff ...patch.CalculateOption) (diff RemoteDiff[apiObject], res ctrl.Result, err error)

	GetIgnoresDiff() []patch.CalculateOption
}

RemoteReconcilerAction is the interface that use by reconciler remote to reconcile your remote resource

func NewRemoteReconcilerAction added in v0.1.3

func NewRemoteReconcilerAction[k8sObject comparable, apiObject comparable, apiClient any](client client.Client, logger *logrus.Entry, recorder record.EventRecorder) (remoteReconciler RemoteReconcilerAction[k8sObject, apiObject, apiClient])

NewRemoteReconcilerAction is the basic constructor of RemoteReconcilerAction interface

type StdK8sReconciler added in v0.1.0

type StdK8sReconciler struct {
	client.Client
	// contains filtered or unexported fields
}

func NewStdK8sReconciler added in v0.1.0

func NewStdK8sReconciler(client client.Client, finalizer string, reconciler K8sReconciler, logger *logrus.Entry, recorder record.EventRecorder) (stdK8sReconciler *StdK8sReconciler, err error)

func (*StdK8sReconciler) Reconcile added in v0.1.0

func (h *StdK8sReconciler) Reconcile(ctx context.Context, req ctrl.Request, r client.Object, data map[string]interface{}, reconcilers ...K8sPhaseReconciler) (res ctrl.Result, err error)

ReconcileK8sResources permit to reconcile kubernetes resources, so the step is not the same on Reconcile. When handle kubernetes resources, you should to chain the reconcile on multiple resources It will run on following steps 1. Read the main object 2. Configure finalizer on the main object 3. Execute each phase that concist of: 3.1 Read kubernetes objects 3.2 Diff kubernetes resources with expected resources 3.3 Update / create resources if needed 3.4 Delete resources if needed 4. Delete finalizer if on delete action Deprecated: Use MultiPhaseReconciler instead

type StdReconciler

type StdReconciler struct {
	client.Client
	// contains filtered or unexported fields
}

func NewStdReconciler

func NewStdReconciler(client client.Client, finalizer string, reconciler Reconciler, logger *logrus.Entry, recorder record.EventRecorder) (stdReconciler *StdReconciler, err error)

func (*StdReconciler) Reconcile

func (h *StdReconciler) Reconcile(ctx context.Context, req ctrl.Request, r client.Object, data map[string]interface{}) (res ctrl.Result, err error)

Reconcile permit to reconcile resource one external service, throughtout API It will handle all aspect of that 1. Read resource on kubernetes 2. Configure finalizer 3. Read external resources 4. Check if on delete phase, delete external resources if on it 5. Diff external resources with the expected resources 6. Create or update external resources if needed Deprecated: Use RemoteReconciler instead

Jump to

Keyboard shortcuts

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