reconciler

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

README

pkg/controller/reconciler

Reconciler component - debounces resource changes and triggers reconciliation.

Overview

Stage 5 component that applies debouncing logic to prevent excessive reconciliations. Waits for quiet periods before triggering reconciliation events.

Features

  • Debouncing: Batches rapid resource changes
  • Immediate initial sync: Triggers reconciliation when all resources synced
  • Configurable interval: Default 500ms
  • Initial sync filtering: Ignores initial resource sync events

Quick Start

import "haptic/pkg/controller/reconciler"

// Default configuration (500ms debounce)
reconciler := reconciler.New(bus, logger, nil)
go reconciler.Start(ctx)

// Custom debounce interval
reconciler := reconciler.New(bus, logger, &reconciler.Config{
    DebounceInterval: 2 * time.Second,
})
go reconciler.Start(ctx)

How It Works

Resource Changes (Debounced)
  1. ResourceIndexUpdatedEvent received
  2. Debounce timer reset to 500ms
  3. If another change arrives, timer reset again
  4. When timer expires (no changes for 500ms), publish ReconciliationTriggeredEvent
Index Synchronized (Immediate)
  1. IndexSynchronizedEvent received (all resource watchers synced)
  2. Stop any pending debounce timer
  3. Immediately publish ReconciliationTriggeredEvent

This triggers the initial reconciliation after all resources are indexed, ensuring the first render has a complete view of cluster state.

Events

Subscribes To
  • ResourceIndexUpdatedEvent: Resource change (debounced)
  • IndexSynchronizedEvent: All resources synced (immediate)
  • HTTPResourceUpdatedEvent: HTTP content change (debounced)
  • HTTPResourceAcceptedEvent: HTTP content accepted (immediate)
  • DriftPreventionTriggeredEvent: Drift prevention (immediate)
Publishes
  • ReconciliationTriggeredEvent: Reconciliation requested

Configuration

type Config struct {
    DebounceInterval time.Duration  // Default: 500ms
}

Constants

const (
    DefaultDebounceInterval = 500 * time.Millisecond
    EventBufferSize        = 100
)

Example Timing

t=0ms:    Resource change → Start 500ms timer
t=100ms:  Resource change → Reset timer (now expires at t=600ms)
t=300ms:  Resource change → Reset timer (now expires at t=800ms)
t=800ms:  Timer expires → Trigger reconciliation

Result: 3 changes batched into 1 reconciliation.

License

See main repository for license information.

Documentation

Overview

Package reconciler implements the Reconciler component that debounces resource changes and triggers reconciliation events.

The Reconciler is a key component in Stage 5 of the controller startup sequence. It subscribes to resource change events, applies debouncing to batch rapid changes, and publishes reconciliation trigger events when the system reaches a quiet state.

Index

Constants

View Source
const (
	// DefaultDebounceInterval is the default time to wait after the last resource
	// change before triggering reconciliation.
	DefaultDebounceInterval = 500 * time.Millisecond

	// EventBufferSize is the size of the event subscription buffer.
	// Size 100: Medium-volume component that receives resource change events from
	// multiple watchers (Ingress, HTTPRoute, Service, Endpoints, Secrets, ConfigMaps).
	// Higher than deployer to handle bursts when many resources change simultaneously.
	EventBufferSize = 100
)
View Source
const ComponentName = "reconciler"

ComponentName is the unique identifier for this component.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DebounceInterval is the time to wait after the last resource change
	// before triggering reconciliation. If not set, DefaultDebounceInterval is used.
	DebounceInterval time.Duration
}

Config configures the Reconciler component.

type Reconciler

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

Reconciler implements the reconciliation debouncer component.

It subscribes to resource change events and index synchronization events, applies debouncing logic to prevent excessive reconciliations, and triggers reconciliation when appropriate.

Debouncing behavior:

  • Resource changes: Wait for quiet period (debounce interval) before triggering
  • Index synchronized: Trigger immediately (initial reconciliation after all resources synced)

The component publishes ReconciliationTriggeredEvent to signal the Executor to begin a reconciliation cycle.

func New

func New(eventBus *busevents.EventBus, logger *slog.Logger, config *Config) *Reconciler

New creates a new Reconciler component.

Parameters:

  • eventBus: The EventBus for subscribing to events and publishing triggers
  • logger: Structured logger for component logging
  • config: Optional configuration (nil for defaults)

Returns:

  • A new Reconciler instance ready to be started

func (*Reconciler) Name

func (r *Reconciler) Name() string

Name returns the unique identifier for this component. Implements the lifecycle.Component interface.

func (*Reconciler) Start

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

Start begins the reconciler's event loop.

This method blocks until the context is cancelled or an error occurs. The component is already subscribed to the EventBus (subscription happens in New()), so this method only processes events:

  • ResourceIndexUpdatedEvent: Starts/resets debounce timer
  • IndexSynchronizedEvent: Triggers initial reconciliation when all resources synced
  • Debounce timer expiration: Publishes ReconciliationTriggeredEvent

The component runs until the context is cancelled, at which point it performs cleanup and returns.

Parameters:

  • ctx: Context for cancellation and lifecycle management

Returns:

  • nil when context is cancelled (graceful shutdown)
  • Error only in exceptional circumstances

Jump to

Keyboard shortcuts

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