reconciler

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package reconciler implements the function of resource reconcile

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseStatefulReconciler added in v0.11.0

type BaseStatefulReconciler[T StatefulResource] struct {
	Logger logr.Logger
}

BaseStatefulReconciler provides a base implementation of StatefulReconciler that handles the common annotation-based state tracking logic

func NewBaseStatefulReconciler added in v0.11.0

func NewBaseStatefulReconciler[T StatefulResource](logger logr.Logger) *BaseStatefulReconciler[T]

NewBaseStatefulReconciler creates a new BaseStatefulReconciler instance

func (*BaseStatefulReconciler[T]) HasStateChanged added in v0.11.0

func (r *BaseStatefulReconciler[T]) HasStateChanged(previous, current interface{}) bool

HasStateChanged is a utility method to check if two states are different

func (*BaseStatefulReconciler[T]) Reconcile added in v0.11.0

func (r *BaseStatefulReconciler[T]) Reconcile(ctx context.Context, resource T, impl StatefulReconciler[T]) error

Reconcile performs the complete stateful reconciliation workflow: 1. Extract current desired state from resource 2. Retrieve previous state from annotation 3. Compare states to determine required operations 4. Apply operations to external system 5. Update state annotation on success

func (*BaseStatefulReconciler[T]) UpdateAnnotation added in v0.11.0

func (r *BaseStatefulReconciler[T]) UpdateAnnotation(resource T, annotationKey string, state interface{}) error

UpdateAnnotation is a helper method to update the state annotation

type Dummy

type Dummy struct {
}

Dummy is a dummy reconciler that does nothing.

func (*Dummy) Observe

func (d *Dummy) Observe(context.Context) error

Observe is a fake implements of Observe

func (*Dummy) Reconcile

func (d *Dummy) Reconcile(context.Context) error

Reconcile is a fake implements of Reconcile

type Interface

type Interface interface {
	Observe(ctx context.Context) error
	Reconcile(ctx context.Context) error
}

Interface implements the functions to observe and reconcile resource object

type Object

type Object interface {
	metav1.Object
	runtime.Object
}

Object is a abstract interface

type StateChangeOperations added in v0.11.0

type StateChangeOperations struct {
	// ItemsToAdd represents items that need to be added to the external system
	ItemsToAdd []interface{} `json:"itemsToAdd,omitempty"`

	// ItemsToRemove represents items that need to be removed from the external system
	ItemsToRemove []interface{} `json:"itemsToRemove,omitempty"`

	// ItemsToUpdate represents items that need to be updated in the external system
	ItemsToUpdate []interface{} `json:"itemsToUpdate,omitempty"`

	// ContextChanged indicates that the context (like resource type or name) has changed
	// and requires special handling like cleanup of old context
	ContextChanged bool `json:"contextChanged,omitempty"`

	// PreviousContext contains the previous context information for cleanup
	PreviousContext interface{} `json:"previousContext,omitempty"`
}

StateChangeOperations represents the operations needed to reconcile state changes

type StatefulReconciler added in v0.11.0

type StatefulReconciler[T StatefulResource] interface {
	// GetStateAnnotationKey returns the annotation key used to store the previous state
	GetStateAnnotationKey() string

	// ExtractCurrentState extracts the current desired state from the resource spec
	// that needs to be compared with the previous state for change detection
	ExtractCurrentState(resource T) (interface{}, error)

	// CompareStates compares the previous state with the current state and returns
	// the operations that need to be performed to reconcile the differences
	CompareStates(previous, current interface{}) (StateChangeOperations, error)

	// ApplyOperations applies the state change operations to the external system
	ApplyOperations(ctx context.Context, resource T, ops StateChangeOperations) error

	// UpdateStateAnnotation updates the annotation with the current state after
	// successful reconciliation
	UpdateStateAnnotation(resource T, currentState interface{}) error
}

StatefulReconciler provides a framework for managing resources that need to track their previous state to perform proper cleanup operations during reconciliation. It uses annotations to store the previous state and compares it with the current desired state to determine what changes need to be made.

type StatefulResource added in v0.11.0

type StatefulResource interface {
	runtime.Object
	metav1.Object
}

StatefulResource represents a Kubernetes resource that needs stateful reconciliation

Jump to

Keyboard shortcuts

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