sentinel

package
v2.0.10 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneObject

func CloneObject[objectType comparable](o objectType) objectType

CloneObject permit to clone current object type

func GetItems

func GetItems[k8sObjectList client.ObjectList, k8sObject client.Object](o k8sObjectList) (items []k8sObject)

GetItems permit to get items contend from ObjectList interface

func GetObjectType

func GetObjectType(o schema.ObjectKind) string

GetObjectType print the current object type

func GetObjectWithMeta

func GetObjectWithMeta[k8sObject client.Object](o k8sObject, s runtime.ObjectTyper) k8sObject

GetObjectWithMeta return current object with TypeMeta to kwons the object type

Types

type DefaultSentinelAction

type DefaultSentinelAction[k8sObject client.Object] struct {
	controller.ReconcilerAction
}

DefaultSentinelAction is the default implementation of SentinelAction

func (*DefaultSentinelAction[k8sObject]) Configure

func (h *DefaultSentinelAction[k8sObject]) Configure(ctx context.Context, req reconcile.Request, o k8sObject, data map[string]any, logger *logrus.Entry) (res reconcile.Result, err error)

func (*DefaultSentinelAction[k8sObject]) Create

func (h *DefaultSentinelAction[k8sObject]) Create(ctx context.Context, o k8sObject, data map[string]any, objects []client.Object, logger *logrus.Entry) (res reconcile.Result, err error)

func (*DefaultSentinelAction[k8sObject]) Delete

func (h *DefaultSentinelAction[k8sObject]) Delete(ctx context.Context, o k8sObject, data map[string]any, objects []client.Object, logger *logrus.Entry) (err error)

Delete delete objects

func (*DefaultSentinelAction[k8sObject]) Diff

func (h *DefaultSentinelAction[k8sObject]) Diff(ctx context.Context, o k8sObject, read SentinelRead, data map[string]any, logger *logrus.Entry, ignoreDiff ...patch.CalculateOption) (diff multiphase.MultiPhaseDiff[client.Object], res reconcile.Result, err error)

func (*DefaultSentinelAction[k8sObject]) GetIgnoresDiff

func (h *DefaultSentinelAction[k8sObject]) GetIgnoresDiff() []patch.CalculateOption

func (*DefaultSentinelAction[k8sObject]) OnError

func (h *DefaultSentinelAction[k8sObject]) OnError(ctx context.Context, o k8sObject, data map[string]any, currentErr error, logger *logrus.Entry) (res reconcile.Result, err error)

func (*DefaultSentinelAction[k8sObject]) OnSuccess

func (h *DefaultSentinelAction[k8sObject]) OnSuccess(ctx context.Context, o k8sObject, data map[string]any, diff multiphase.MultiPhaseDiff[client.Object], logger *logrus.Entry) (res reconcile.Result, err error)

func (*DefaultSentinelAction[k8sObject]) Read

func (h *DefaultSentinelAction[k8sObject]) Read(ctx context.Context, o k8sObject, data map[string]any, logger *logrus.Entry) (read SentinelRead, res reconcile.Result, err error)

func (*DefaultSentinelAction[k8sObject]) Update

func (h *DefaultSentinelAction[k8sObject]) Update(ctx context.Context, o k8sObject, data map[string]any, objects []client.Object, logger *logrus.Entry) (res reconcile.Result, err error)

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

type DefaultSentinelRead

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

DefaultSentinelRead is the default implementation of SentinelRead

func (*DefaultSentinelRead) AddCurrentObject

func (h *DefaultSentinelRead) AddCurrentObject(o client.Object)

func (*DefaultSentinelRead) AddExpectedObject

func (h *DefaultSentinelRead) AddExpectedObject(o client.Object)

func (*DefaultSentinelRead) GetReads

func (*DefaultSentinelRead) SetCurrentObjects

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

func (*DefaultSentinelRead) SetExpectedObjects

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

type DefaultSentinelReconciler

type DefaultSentinelReconciler[k8sObject client.Object] struct {
	controller.Reconciler
}

DefaultSentinelReconciler is the default implementation of SentinelReconciler interface

func (*DefaultSentinelReconciler[k8sObject]) Reconcile

func (h *DefaultSentinelReconciler[k8sObject]) Reconcile(ctx context.Context, req reconcile.Request, o k8sObject, data map[string]interface{}, reconcilerAction SentinelReconcilerAction[k8sObject]) (res reconcile.Result, err error)

No need to add finalizer and manage delete All sub resources must be children of main parent. So the clean is handled by kubelet in lazy effort

type SentinelRead

type SentinelRead interface {
	// GetAllCurrentObjects premit to get the map of current objects, mapped by type
	GetReads() map[string]multiphase.MultiPhaseRead[client.Object]

	// SetCurrentObjects will add object on the right list
	SetCurrentObjects(objects []client.Object)

	// AddCurrentObject will add object on the right list
	AddCurrentObject(o client.Object)

	// AddExpectedObject will add object on the right list
	AddExpectedObject(o client.Object)

	// SetExpectedObjects will add object on the right list
	SetExpectedObjects(objects []client.Object)
}

SentinelRead is the interface to store the result of read from sentinel reconciler objectType is the key if you need to handle some type of object to not shuffle them

func NewSentinelRead

func NewSentinelRead(scheme runtime.ObjectTyper) SentinelRead

NewSentinelRead is the default implementation of SentinelRead interface

type SentinelReconciler

type SentinelReconciler[k8sObject client.Object] interface {
	controller.Reconciler

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

SentinelReconciler must be used when you look resource that your operator is not the owner like ingress, secret, configMap, etc. Some time you should to generate somme resource from labels or annotations ... It the use case of this controller

func NewSentinelReconciler

func NewSentinelReconciler[k8sObject client.Object](client client.Client, name string, logger *logrus.Entry, recorder record.EventRecorder) (sentinelReconciler SentinelReconciler[k8sObject])

NewSentinelReconciler is the default implementation of SentinelReconciler interface

type SentinelReconcilerAction

type SentinelReconcilerAction[k8sObject client.Object] interface {
	controller.ReconcilerAction

	// Confirgure permit to init external provider driver (API client REST)
	// It can also permit to init condition on status
	Configure(ctx context.Context, req reconcile.Request, o k8sObject, data map[string]any, logger *logrus.Entry) (res reconcile.Result, err error)

	// Read permit to read the actual resource state from provider and set it on data map
	Read(ctx context.Context, o k8sObject, data map[string]any, logger *logrus.Entry) (read SentinelRead, res reconcile.Result, err error)

	// Create permit to create resource on provider
	// It only call if diff.NeeCreated is true
	Create(ctx context.Context, o k8sObject, data map[string]any, objects []client.Object, logger *logrus.Entry) (res reconcile.Result, err error)

	// Update permit to update resource on provider
	// It only call if diff.NeedUpdated is true
	Update(ctx context.Context, o k8sObject, data map[string]any, objects []client.Object, logger *logrus.Entry) (res reconcile.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 k8sObject, data map[string]any, objects []client.Object, logger *logrus.Entry) (err error)

	// OnError is call when error is throwing
	// It the right way to set status condition when error
	OnError(ctx context.Context, o k8sObject, data map[string]any, currentErr error, logger *logrus.Entry) (res reconcile.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 k8sObject, data map[string]any, diff multiphase.MultiPhaseDiff[client.Object], logger *logrus.Entry) (res reconcile.Result, err error)

	// Diff permit to compare the actual state and the expected state
	Diff(ctx context.Context, o k8sObject, read SentinelRead, data map[string]any, logger *logrus.Entry, ignoreDiff ...patch.CalculateOption) (diff multiphase.MultiPhaseDiff[client.Object], res reconcile.Result, err error)

	GetIgnoresDiff() []patch.CalculateOption
}

SentinelReconcilerAction is the interface that use by sentinel reconciler Put logger param on each function, permit to set contextual fields like namespace and object name, object type

func NewSentinelAction

func NewSentinelAction[k8sObject client.Object](client client.Client, recorder record.EventRecorder) (sentinelReconciler SentinelReconcilerAction[k8sObject])

NewSentinelAction is the default implementation of SentinelReconcilerAction interface

Jump to

Keyboard shortcuts

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