configloader

package
v0.2.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

pkg/controller/configloader

Stage-1 event adapter that turns HAProxyTemplateConfig CRD changes into internal config. Subscribes to ConfigResourceChangedEvent, runs conversion.ParseCRD on the unstructured resource, and publishes a ConfigParsedEvent with the resulting *config.Config plus the typed CRD wrapper.

This is a thin event-loop on top of pkg/controller/resourceloader.BaseLoader — same scaffold used by credentialsloader. The actual parsing lives in pkg/controller/conversion; this package just wires the event flow.

Minimal Usage

import (
    "context"

    "gitlab.com/haproxy-haptic/haptic/pkg/controller/configloader"
    "gitlab.com/haproxy-haptic/haptic/pkg/events"
)

bus := events.NewEventBus(100)
loader := configloader.NewConfigLoaderComponent(bus, logger)

bus.Start()              // release buffered events to subscribers
go loader.Start(ctx)     // then run the event loop

// Upstream: a SingleWatcher for the HAProxyTemplateConfig CRD emits
// ConfigResourceChangedEvent{Resource: *unstructured.Unstructured}.
// Downstream: pkg/controller/configchange.ConfigChangeHandler consumes
// ConfigParsedEvent, runs the scatter-gather validation, and publishes
// ConfigValidatedEvent / ConfigInvalidEvent.

Subscription happens in NewConfigLoaderComponent, before bus.Start(), so any buffered ConfigResourceChangedEvent from the watcher's initial sync is delivered once the bus is released.

Event Contract

In

type ConfigResourceChangedEvent struct {
    Resource any  // *unstructured.Unstructured pointing at the HAProxyTemplateConfig CRD
}

The resourceVersion is read off the unstructured resource by the loader itself; there's no Version field on the event.

Out — on successful parse

type ConfigParsedEvent struct {
    Config         any    // *config.Config — internal struct (any to avoid circular deps)
    TemplateConfig any    // typed CRD (metadata + spec) — used by ConfigPublisher for k8s metadata
    Version        string // CRD resourceVersion
    SecretVersion  string // always empty; ConfigChangeHandler passes it through unchanged
}

Out — on failure: nothing is published. Errors are logged with the CRD's namespace/name. A stale config stays active; the controller doesn't start a failed reinitialisation.

What It Validates

ParseCRD rejects resources that aren't haproxy-haptic.org/v1alpha1.HAProxyTemplateConfig before conversion. Everything after that (port ranges, required fields, enum values) is done by the scatter-gather validators in pkg/controller/validator, not here. configloader is intentionally small — it converts, it doesn't judge.

See Also

License

Apache-2.0 — see root LICENSE.

Documentation

Index

Constants

View Source
const (
	// ComponentName is the unique identifier for this component.
	ComponentName = "configloader"

	// EventBufferSize is the size of the event subscription buffer.
	// Low-volume component (~1 event per config change).
	EventBufferSize = busevents.StandardSubscriberBuffer
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigLoaderComponent

type ConfigLoaderComponent struct {
	*resourceloader.BaseLoader
}

ConfigLoaderComponent subscribes to ConfigResourceChangedEvent and parses config data.

This component is responsible for: - Converting HAProxyTemplateConfig CRD Spec to config.Config - Publishing ConfigParsedEvent for successfully parsed configs - Logging errors for conversion failures

Architecture: This is a pure event-driven component with no knowledge of watchers or Kubernetes. It simply reacts to ConfigResourceChangedEvent and produces ConfigParsedEvent.

func NewConfigLoaderComponent

func NewConfigLoaderComponent(eventBus *busevents.EventBus, logger *slog.Logger) *ConfigLoaderComponent

NewConfigLoaderComponent creates a new ConfigLoader component.

Parameters:

  • eventBus: The EventBus to subscribe to and publish on
  • logger: Structured logger for diagnostics

Returns:

  • *ConfigLoaderComponent ready to start

func (*ConfigLoaderComponent) ProcessEvent

func (c *ConfigLoaderComponent) ProcessEvent(event busevents.Event)

ProcessEvent handles a single event from the EventBus.

Jump to

Keyboard shortcuts

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