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
- 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) ([]interface{}, error)
- func (sc *StateCache) GetValidatedConfig() (*debug.ValidatedConfigInfo, error)
- func (sc *StateCache) Start(ctx context.Context) error
- type WebhookCertificates
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 = 1000 )
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(ctx context.Context, k8sClient *client.Client, crdName, secretName, webhookCertSecretName 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
- webhookCertSecretName: Name of the Secret containing webhook TLS certificates
- 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)
Types ¶
type StateCache ¶
type StateCache struct {
// contains filtered or unexported fields
}
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
- ValidationStartedEvent/CompletedEvent/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) ([]interface{}, error)
GetResourcesByType implements debug.StateProvider.
func (*StateCache) GetValidatedConfig ¶
func (sc *StateCache) GetValidatedConfig() (*debug.ValidatedConfigInfo, error)
GetValidatedConfig implements debug.StateProvider.
func (*StateCache) Start ¶
func (sc *StateCache) Start(ctx context.Context) error
Start begins processing events from the EventBus.
The component is already subscribed to the EventBus (subscription happens in NewStateCache()), so this method only processes events. This method blocks until the context is cancelled.
type WebhookCertificates ¶
fetchAndValidateInitialConfig fetches, parses, and validates the initial ConfigMap and Secret.
Returns the validated configuration and credentials, or an error if any step fails. WebhookCertificates holds the TLS certificate and private key for the webhook server.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package commentator provides the Event Commentator pattern for domain-aware logging.
|
Package commentator provides the Event Commentator pattern for domain-aware logging. |
|
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 component that performs dry-run reconciliation for webhook validation.
|
Package dryrunvalidator implements the DryRunValidator component 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 executor implements the Executor component that orchestrates reconciliation cycles by coordinating pure components.
|
Package executor implements the Executor component that orchestrates reconciliation cycles by coordinating pure components. |
|
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 reconciler implements the Reconciler component that debounces resource changes and triggers reconciliation events.
|
Package reconciler implements the Reconciler component that debounces resource changes and triggers reconciliation events. |
|
Package rendercontext provides a centralized builder for template rendering contexts.
|
Package rendercontext provides a centralized builder for template rendering contexts. |
|
Package renderer implements the Renderer component that renders HAProxy configuration and auxiliary files from templates.
|
Package renderer implements the Renderer component that renders HAProxy configuration and auxiliary files from templates. |
|
Package resourcestore provides centralized management of resource stores with memory-efficient overlay support for dry-run validation.
|
Package resourcestore provides centralized management of resource stores with memory-efficient overlay support for dry-run validation. |
|
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 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 validator implements validation components for HAProxy configuration.
|
Package validator implements validation components 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. |