reconciler

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package reconciler provides infrastructure state reconciliation driven by event queue processing.

Package reconciler handles instance lifecycle management: scaling managed groups to desired size, detecting and replacing unhealthy instances, coordinating graceful drains, and expiring old instances. It processes events from a queue and only acts when the server is the shard leader.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPermanentError

func NewPermanentError(err error) error

NewPermanentError wraps an error as non-retryable

Types

type EventType

type EventType string

EventType represents the type of reconciliation event

const (
	EventCheckInstance     EventType = "CheckInstance" // e.g. on gRPC disconnect or missed health report
	EventGroupChanged      EventType = "GroupChanged"
	EventInstanceDeleted   EventType = "InstanceDeleted"
	EventDrainAcked        EventType = "DrainAcked"        // Operator acknowledged drain complete
	EventTerminationNotice EventType = "TerminationNotice" // Instance termination notice received
	EventInitialReconcile  EventType = "InitialReconcile"
)

type InstanceManager

type InstanceManager interface {
	CreateInstance(ctx context.Context, req instances.CreateInstanceRequest) (*instances.CreateInstanceResponse, error)
	DeleteInstance(ctx context.Context, instanceID string) error
}

InstanceManager defines the interface for instance management operations required by the reconciler

type Options

type Options struct {
	InstanceManager InstanceManager
	ConfigLoader    *config.Loader
	LocalDB         *localdb.DB
	Provider        infra.Provider
	NotifyDrain     func(instanceID, group, reason string, unhealthyAt, deleteAt time.Time)
	NotifyError     func(group, instanceID, errMsg string)
	IsLeader        func() bool
	CreateRateLimit time.Duration
	Logger          *slog.Logger
}

Options contains options for creating a Reconciler

type PermanentError

type PermanentError struct {
	Err error
}

PermanentError wraps an error to indicate it should not be retried

func (*PermanentError) Error

func (e *PermanentError) Error() string

func (*PermanentError) Unwrap

func (e *PermanentError) Unwrap() error

type ReconcileEvent

type ReconcileEvent struct {
	Type             EventType
	Tenant           string
	GroupKey         string
	InstanceID       string
	Timestamp        time.Time
	PreventDuplicate bool   // Skip if same event recently processed
	Cause            string // Why this event was triggered (e.g. "disconnect")
	Attempt          int    // Retry attempt number for follow-up polling
}

ReconcileEvent represents an event that triggers reconciliation

type Reconciler

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

Reconciler handles instance reconciliation (matching actual instance count to desired group size)

func New

func New(opts Options) (*Reconciler, error)

New creates a new Reconciler

func (*Reconciler) Enqueue

func (r *Reconciler) Enqueue(event ReconcileEvent)

Enqueue adds a reconciliation event to the queue

func (*Reconciler) Start

func (r *Reconciler) Start(ctx context.Context) error

Start starts the reconciliation loop

func (*Reconciler) Stop

func (r *Reconciler) Stop()

Stop stops the reconciliation loop

type RetryPolicy

type RetryPolicy struct {
	BaseDelay   time.Duration
	MaxDelay    time.Duration
	MaxAttempts int
	JitterFrac  float64 // Fraction of delay to add as jitter (0.25 = 25%)
}

RetryPolicy defines the retry behavior for a specific event type

Jump to

Keyboard shortcuts

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