reconcile

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const DefaultInterval = 60 * time.Second

DefaultInterval is the default reconciliation interval.

Variables

This section is empty.

Functions

func BuildDriftReport

func BuildDriftReport(diff StateDiff) api.DriftReport

BuildDriftReport constructs an api.DriftReport from a StateDiff. Each drift item produces one DriftCorrection entry.

func NewStateSnapshot

func NewStateSnapshot() *stateSnapshot

NewStateSnapshot returns a new, empty snapshot.

Types

type Config

type Config struct {
	// Interval is the time between reconciliation cycles.
	// Default: 60s
	Interval time.Duration `yaml:"interval"`
}

Config holds the configuration for the reconciliation loop. Config is passed as a constructor argument — no file I/O in this package.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults sets default values for zero-valued fields.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that configuration values are acceptable.

type ReconcileHandler

type ReconcileHandler func(ctx context.Context, desired *api.StateResponse, diff StateDiff) error

ReconcileHandler is a function invoked when drift is detected.

type Reconciler

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

Reconciler periodically compares desired state against a local snapshot and invokes registered handlers to correct drift.

func NewReconciler

func NewReconciler(client StateFetcher, cfg Config, logger *slog.Logger) *Reconciler

NewReconciler creates a new Reconciler with the given configuration. Config defaults are applied automatically.

func (*Reconciler) RegisterHandler

func (r *Reconciler) RegisterHandler(handler ReconcileHandler)

RegisterHandler adds a reconciliation handler invoked on drift detection. Handlers are called in registration order. RegisterHandler must be called before Run; it is not safe for concurrent use.

func (*Reconciler) Run

func (r *Reconciler) Run(ctx context.Context, nodeID string) error

Run starts the reconciliation loop. It blocks until ctx is cancelled. The first cycle runs immediately; subsequent cycles run at cfg.Interval or when TriggerReconcile is called.

func (*Reconciler) TriggerReconcile

func (r *Reconciler) TriggerReconcile()

TriggerReconcile requests an immediate reconciliation cycle. Multiple rapid calls are coalesced — only one extra cycle runs.

type StateDiff

type StateDiff struct {
	PeersToAdd    []api.Peer
	PeersToRemove []string   // peer IDs
	PeersToUpdate []api.Peer // peers with changed fields

	PoliciesToAdd    []api.Policy
	PoliciesToRemove []string // policy IDs

	SigningKeysChanged bool
	NewSigningKeys     *api.SigningKeys

	MetadataChanged   bool
	DataChanged       bool
	SecretRefsChanged bool
}

StateDiff describes the drift between a desired state (from the control plane) and the current locally-observed state.

func ComputeDiff

func ComputeDiff(desired *api.StateResponse, current *api.StateResponse) StateDiff

ComputeDiff compares the desired state from the control plane against the current local snapshot and returns a StateDiff describing what has changed.

func (StateDiff) IsEmpty

func (d StateDiff) IsEmpty() bool

IsEmpty reports whether there is no drift at all.

type StateFetcher

type StateFetcher interface {
	FetchState(ctx context.Context, nodeID string) (*api.StateResponse, error)
	ReportDrift(ctx context.Context, nodeID string, req api.DriftReport) error
}

StateFetcher retrieves desired state and reports drift to the control plane.

Jump to

Keyboard shortcuts

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