Documentation
¶
Overview ¶
Package controller provides the main controller orchestration for the HAProxy template ingress controller.
The controller follows an event-driven architecture with a reinitialization loop: 1. Fetch and validate initial configuration 2. Create EventBus and components 3. Start components and watchers 4. Wait for configuration changes 5. Reinitialize on valid config changes
Index ¶
- Constants
- func Run(ctx context.Context, k8sClient *client.Client, ...) error
- func SetBuildInfo(version, haproxyVersion string)
- type InitialConfigBundle
- type StateCache
- func (sc *StateCache) GetAuxiliaryFiles() (*dataplane.AuxiliaryFiles, time.Time, error)
- func (sc *StateCache) GetConfig() (*coreconfig.Config, string, error)
- func (sc *StateCache) GetCredentials() (*coreconfig.Credentials, string, error)
- func (sc *StateCache) GetErrors() (*debug.ErrorSummary, error)
- func (sc *StateCache) GetPipelineStatus() (*debug.PipelineStatus, error)
- func (sc *StateCache) GetRenderedConfig() (string, time.Time, error)
- func (sc *StateCache) GetResourceCounts() (map[string]int, error)
- func (sc *StateCache) GetResourcesByType(resourceType string) ([]any, error)
- func (sc *StateCache) GetValidatedConfig() (*debug.ValidatedConfigInfo, error)
- func (sc *StateCache) HandleEvent(event busevents.Event)
Constants ¶
const ( // RetryDelay is the duration to wait before retrying after an iteration failure. RetryDelay = 5 * time.Second // ConfigPollInterval is the interval for polling HAProxyTemplateConfig availability. ConfigPollInterval = 5 * time.Second // DebugEventBufferSize is the size of the event buffer for debug/introspection. DebugEventBufferSize = busevents.DebugSubscriberBuffer // ShutdownTimeout is the maximum time to wait for goroutines to finish during shutdown. // Set to 25s to allow clean exit before Kubernetes' default 30s terminationGracePeriodSeconds. ShutdownTimeout = 25 * time.Second // ShutdownProgressInterval is how often to log progress during shutdown. ShutdownProgressInterval = 5 * time.Second )
const ReinitGraceWindow = 90 * time.Second
ReinitGraceWindow is how long after a voluntary iteration restart /healthz keeps reporting healthy while components re-initialize. Sized to cover a slow reinit (embedded validationTests + watcher re-sync + leader re-acquisition) while staying well below the fresh-pod startup budget the liveness restart would fall back to.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, k8sClient *client.Client, crdName, secretName, webhookCertDir string, debugPort int) error
Run is the main entry point for the controller.
It performs initial configuration fetching and validation, then enters a reinitialization loop where it responds to configuration changes by restarting with the new configuration.
The controller uses an event-driven architecture:
- EventBus coordinates all components
- SingleWatcher monitors HAProxyTemplateConfig CRD and Secret
- Components react to events and publish results
- ConfigChangeHandler detects validated config changes and signals reinitialization
Parameters:
- ctx: Context for cancellation (SIGTERM, SIGINT, etc.)
- k8sClient: Kubernetes client for API access
- crdName: Name of the HAProxyTemplateConfig CRD
- secretName: Name of the Secret containing HAProxy Dataplane API credentials
- webhookCertDir: Directory holding the webhook TLS cert (tls.crt/tls.key); empty disables the webhook
- debugPort: Port for debug HTTP server (0 to disable)
Returns:
- Error if the controller cannot start or encounters a fatal error
- nil if the context is cancelled (graceful shutdown)
func SetBuildInfo ¶
func SetBuildInfo(version, haproxyVersion string)
SetBuildInfo configures version information exposed via the haptic_build_info Prometheus metric. Must be called before Run() to take effect.
Parameters:
- version: Controller version (e.g., "0.1.0-alpha.10")
- haproxyVersion: HAProxy version the controller was built for (e.g., "3.2")
Types ¶
type InitialConfigBundle ¶
type InitialConfigBundle struct {
Config *coreconfig.Config
CRD *v1alpha1.HAProxyTemplateConfig
Credentials *coreconfig.Credentials
CredentialsVersion string
}
fetchAndValidateInitialConfig fetches, parses, and validates the initial HAProxyTemplateConfig CRD and credentials Secret.
Returns the validated configuration and credentials, or an error if any step fails. InitialConfigBundle holds the parsed initial CRD / Secret values plus the resource versions of the underlying Secrets, so the iteration startup can wire bootstrap-version filtering for ConfigChangeHandler.
type StateCache ¶
StateCache caches controller state by subscribing to events.
This component implements the debug.StateProvider interface and provides thread-safe access to the controller's internal state for debug purposes.
It subscribes to key events and updates its cached state accordingly:
- ConfigValidatedEvent → updates config cache
- CredentialsUpdatedEvent → updates credentials cache
- TemplateRenderedEvent → updates rendered config cache
- ReconciliationTriggeredEvent → updates pipeline trigger state
- ValidationCompletedEvent/FailedEvent → updates validation state
- DeploymentStartedEvent/CompletedEvent → updates deployment state
- InstanceDeploymentFailedEvent → tracks failed endpoints
func NewStateCache ¶
func NewStateCache(eventBus *busevents.EventBus, resourceWatcher *resourcewatcher.ResourceWatcherComponent, logger *slog.Logger) *StateCache
NewStateCache creates a new state cache component.
The StateCache subscribes to the EventBus in the constructor (before EventBus.Start()) to ensure proper startup synchronization and receive all buffered startup events.
Usage:
stateCache := NewStateCache(eventBus, resourceWatcher, logger) go stateCache.Start(ctx) // Process events in background eventBus.Start() // Release buffered events
func (*StateCache) GetAuxiliaryFiles ¶
func (sc *StateCache) GetAuxiliaryFiles() (*dataplane.AuxiliaryFiles, time.Time, error)
GetAuxiliaryFiles implements debug.StateProvider.
func (*StateCache) GetConfig ¶
func (sc *StateCache) GetConfig() (*coreconfig.Config, string, error)
GetConfig implements debug.StateProvider.
func (*StateCache) GetCredentials ¶
func (sc *StateCache) GetCredentials() (*coreconfig.Credentials, string, error)
GetCredentials implements debug.StateProvider.
func (*StateCache) GetErrors ¶
func (sc *StateCache) GetErrors() (*debug.ErrorSummary, error)
GetErrors implements debug.StateProvider.
func (*StateCache) GetPipelineStatus ¶
func (sc *StateCache) GetPipelineStatus() (*debug.PipelineStatus, error)
GetPipelineStatus implements debug.StateProvider.
func (*StateCache) GetRenderedConfig ¶
func (sc *StateCache) GetRenderedConfig() (string, time.Time, error)
GetRenderedConfig implements debug.StateProvider.
func (*StateCache) GetResourceCounts ¶
func (sc *StateCache) GetResourceCounts() (map[string]int, error)
GetResourceCounts implements debug.StateProvider.
func (*StateCache) GetResourcesByType ¶
func (sc *StateCache) GetResourcesByType(resourceType string) ([]any, error)
GetResourcesByType implements debug.StateProvider.
For `store: on-demand` types the result is the warm-cache subset only, not the full tracked set (see the partial-result contract on the interface declaration and listResources below). GetResourceCounts() remains the authoritative total.
func (*StateCache) GetValidatedConfig ¶
func (sc *StateCache) GetValidatedConfig() (*debug.ValidatedConfigInfo, error)
GetValidatedConfig implements debug.StateProvider.
func (*StateCache) HandleEvent ¶
func (sc *StateCache) HandleEvent(event busevents.Event)
HandleEvent implements component.EventHandler: it processes events and updates cached state.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package buffers provides fixed buffer sizes for event subscriptions.
|
Package buffers provides fixed buffer sizes for event subscriptions. |
|
Package coalesce provides utilities for event coalescing in controller components.
|
Package coalesce provides utilities for event coalescing in controller components. |
|
Package commentator provides the Event Commentator pattern for domain-aware logging.
|
Package commentator provides the Event Commentator pattern for domain-aware logging. |
|
Package component provides a shared event-loop scaffold for controller components that subscribe on construction and dispatch one event at a time.
|
Package component provides a shared event-loop scaffold for controller components that subscribe on construction and dispatch one event at a time. |
|
Package configtest runs a HAProxyTemplateConfig's embedded validationTests against an already-built engine, bounded by a timeout.
|
Package configtest runs a HAProxyTemplateConfig's embedded validationTests against an already-built engine, bounded by a timeout. |
|
Package crdwatch reinitializes the controller when the CustomResourceDefinitions backing watched resources change.
|
Package crdwatch reinitializes the controller when the CustomResourceDefinitions backing watched resources change. |
|
Package currentconfigstore provides a utility component for caching the parsed current HAProxy configuration from the HAProxyCfg CRD.
|
Package currentconfigstore provides a utility component for caching the parsed current HAProxy configuration from the HAProxyCfg CRD. |
|
Package debug provides controller-specific debug variable implementations.
|
Package debug provides controller-specific debug variable implementations. |
|
Package deployer implements the Deployer component that deploys validated HAProxy configurations to discovered HAProxy pod endpoints.
|
Package deployer implements the Deployer component that deploys validated HAProxy configurations to discovered HAProxy pod endpoints. |
|
Package discovery provides the Discovery event adapter component.
|
Package discovery provides the Discovery event adapter component. |
|
Package dryrunvalidator implements the DryRunValidator that performs dry-run reconciliation for webhook validation.
|
Package dryrunvalidator implements the DryRunValidator that performs dry-run reconciliation for webhook validation. |
|
Package events contains all domain event type definitions for the HAPTIC controller.
|
Package events contains all domain event type definitions for the HAPTIC controller. |
|
Package helpers provides shared utility functions for the controller layer.
|
Package helpers provides shared utility functions for the controller layer. |
|
Package httpstore provides the event adapter for HTTP resource fetching.
|
Package httpstore provides the event adapter for HTTP resource fetching. |
|
Package indextracker provides the IndexSynchronizationTracker that monitors resource watcher synchronization and publishes an event when all are synced.
|
Package indextracker provides the IndexSynchronizationTracker that monitors resource watcher synchronization and publishes an event when all are synced. |
|
Package leadership provides utilities for handling leadership transitions in event-driven components.
|
Package leadership provides utilities for handling leadership transitions in event-driven components. |
|
Package names provides well-known string constants used across the controller layer.
|
Package names provides well-known string constants used across the controller layer. |
|
Package pipeline provides the render-validate pipeline for HAProxy configuration.
|
Package pipeline provides the render-validate pipeline for HAProxy configuration. |
|
Package pluggablevalidator implements the controller-side client for the pluggable-validator-sidecar wire protocol.
|
Package pluggablevalidator implements the controller-side client for the pluggable-validator-sidecar wire protocol. |
|
testutil
Package testutil provides a fixture unix-socket server for exercising the pluggablevalidator client without spinning up a real haproxy-spoa-hub sidecar.
|
Package testutil provides a fixture unix-socket server for exercising the pluggablevalidator client without spinning up a real haproxy-spoa-hub sidecar. |
|
Package proposalvalidator provides validation of hypothetical configuration changes.
|
Package proposalvalidator provides validation of hypothetical configuration changes. |
|
Package reconciler implements the Reconciler component that triggers reconciliation events on resource changes.
|
Package reconciler implements the Reconciler component that triggers reconciliation events on resource changes. |
|
Package rendercontext provides a centralized builder for template rendering contexts.
|
Package rendercontext provides a centralized builder for template rendering contexts. |
|
Package resourceapplier reconciles template-declared Kubernetes resources via Server-Side Apply (SSA).
|
Package resourceapplier reconciles template-declared Kubernetes resources via Server-Side Apply (SSA). |
|
Package resourceloader provides shared event loop infrastructure for loader components that watch a single resource type and parse/transform its data.
|
Package resourceloader provides shared event loop infrastructure for loader components that watch a single resource type and parse/transform its data. |
|
Package resourcewatcher provides the ResourceWatcherComponent that creates and manages watchers for all Kubernetes resources defined in the controller configuration.
|
Package resourcewatcher provides the ResourceWatcherComponent that creates and manages watchers for all Kubernetes resources defined in the controller configuration. |
|
Package statusapplier applies template-driven status patches to Kubernetes resources.
|
Package statusapplier applies template-driven status patches to Kubernetes resources. |
|
Package testrunner implements validation test execution for HAProxyTemplateConfig.
|
Package testrunner implements validation test execution for HAProxyTemplateConfig. |
|
Package testutil provides shared test helpers for controller package tests.
|
Package testutil provides shared test helpers for controller package tests. |
|
Package throttle provides leading-edge refractory throttle helpers used by controller components that bound their write rate to slow downstream systems (e.g.
|
Package throttle provides leading-edge refractory throttle helpers used by controller components that bound their write rate to slow downstream systems (e.g. |
|
Package timeouts provides shared timeout constants used across controller sub-packages.
|
Package timeouts provides shared timeout constants used across controller sub-packages. |
|
Package timers provides safe timer management for event-driven controller components.
|
Package timers provides safe timer management for event-driven controller components. |
|
Package typebootstrap orchestrates the typed-watched-resources pipeline at controller startup.
|
Package typebootstrap orchestrates the typed-watched-resources pipeline at controller startup. |
|
Package validation provides pure validation services for HAProxy configuration.
|
Package validation provides pure validation services for HAProxy configuration. |
|
Package webhook provides the webhook adapter component that bridges the pure webhook library to the event-driven controller architecture.
|
Package webhook provides the webhook adapter component that bridges the pure webhook library to the event-driven controller architecture. |