credentialsloader

package
v0.1.0-alpha.12 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

pkg/controller/credentialsloader

CredentialsLoader component - parses Secret data into credential structures.

Overview

Event-driven component that subscribes to SecretResourceChangedEvent, extracts credentials from Secret resources, and publishes CredentialsUpdatedEvent or CredentialsInvalidEvent.

Quick Start

import "haptic/pkg/controller/credentialsloader"

loader := credentialsloader.NewCredentialsLoaderComponent(bus, logger)
go loader.Start(ctx)

Expected Secret Format

apiVersion: v1
kind: Secret
metadata:
  name: haproxy-credentials
type: Opaque
stringData:
  dataplane_username: admin
  dataplane_password: password

Required fields:

  • dataplane_username: HAProxy Dataplane API username
  • dataplane_password: HAProxy Dataplane API password

Events

Subscribes To
  • SecretResourceChangedEvent: Secret updated
Publishes
  • CredentialsUpdatedEvent: Valid credentials loaded
  • CredentialsInvalidEvent: Invalid or missing credentials

License

See main repository for license information.

Documentation

Index

Constants

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

	// EventBufferSize is the size of the event subscription buffer.
	// Size 50: Low-volume component (~1 event per secret change).
	EventBufferSize = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CredentialsLoaderComponent

type CredentialsLoaderComponent struct {
	*resourceloader.BaseLoader
}

CredentialsLoaderComponent subscribes to SecretResourceChangedEvent and parses Secret data.

This component is responsible for: - Extracting credentials from Secret resources - Parsing Secret data into config.Credentials structures - Publishing CredentialsUpdatedEvent for successfully loaded credentials - Publishing CredentialsInvalidEvent for invalid credentials

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

func NewCredentialsLoaderComponent

func NewCredentialsLoaderComponent(eventBus *busevents.EventBus, logger *slog.Logger) *CredentialsLoaderComponent

NewCredentialsLoaderComponent creates a new CredentialsLoader component.

Parameters:

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

Returns:

  • *CredentialsLoaderComponent ready to start

func (*CredentialsLoaderComponent) ProcessEvent

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

ProcessEvent handles a single event from the EventBus.

type SecretWatcher

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

SecretWatcher watches a specific Secret and publishes SecretResourceChangedEvent.

This component bridges the Kubernetes informer pattern with the controller's event-driven architecture. It watches a single Secret (referenced by HAProxyTemplateConfig.CredentialsSecretRef) and publishes events whenever the Secret is added, updated, or deleted.

Architecture: - Uses core Kubernetes informers (not generated) - Publishes SecretResourceChangedEvent (consumed by CredentialsLoaderComponent) - Converts typed Secret to unstructured format for consistent handling.

func NewSecretWatcher

func NewSecretWatcher(
	client kubernetes.Interface,
	eventBus *busevents.EventBus,
	logger *slog.Logger,
	namespace string,
	name string,
) *SecretWatcher

NewSecretWatcher creates a new SecretWatcher.

Parameters:

  • client: Kubernetes client
  • eventBus: EventBus to publish SecretResourceChangedEvent
  • logger: Structured logger for diagnostics
  • namespace: Namespace containing the Secret
  • name: Name of the Secret to watch

Returns:

  • *SecretWatcher ready to start

func (*SecretWatcher) Start

func (w *SecretWatcher) Start(ctx context.Context) error

Start begins watching the Secret.

This method blocks until Stop() is called or the context is canceled. It should typically be run in a goroutine.

Example:

watcher := NewSecretWatcher(client, bus, logger, "default", "haproxy-credentials")
go watcher.Start(ctx)

func (*SecretWatcher) Stop

func (w *SecretWatcher) Stop()

Stop gracefully stops the watcher.

Jump to

Keyboard shortcuts

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