Documentation
¶
Overview ¶
Package discovery provides the Discovery event adapter component.
This package wraps the pure Discovery component (pkg/dataplane/discovery) with event-driven coordination. It subscribes to configuration, credentials, and pod change events, and publishes discovered HAProxy endpoints.
Package discovery provides HAProxy pod discovery functionality.
This package implements pure business logic for discovering HAProxy pod endpoints based on pod resources from the Kubernetes API. It extracts pod IPs and constructs Dataplane API endpoints with credentials.
This is a pure component with no event bus dependency - event coordination is handled by the adapter in pkg/controller/discovery.
Index ¶
- Constants
- type Component
- type Discovery
- func (d *Discovery) DiscoverEndpoints(podStore types.Store, credentials coreconfig.Credentials) ([]dataplane.Endpoint, error)
- func (d *Discovery) DiscoverEndpointsWithLogger(podStore types.Store, credentials coreconfig.Credentials, logger *slog.Logger) ([]dataplane.Endpoint, error)
- func (d *Discovery) LocalVersion() *dataplane.Version
Constants ¶
const ( // ComponentName is the unique identifier for this component. ComponentName = "discovery" // EventBufferSize is the buffer size for event subscriptions. EventBufferSize = 100 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component is the Discovery event adapter.
This component:
- Subscribes to ConfigValidatedEvent, CredentialsUpdatedEvent, ResourceIndexUpdatedEvent, and BecameLeaderEvent
- Maintains current state (dataplanePort, credentials, podStore)
- Calls Discovery.DiscoverEndpoints() when relevant events occur
- Publishes HAProxyPodsDiscoveredEvent with discovered endpoints
- Publishes HAProxyPodTerminatedEvent when pods are removed
Event Flow:
- ConfigValidatedEvent → Update dataplanePort → Trigger discovery
- CredentialsUpdatedEvent → Update credentials → Trigger discovery
- ResourceIndexUpdatedEvent (haproxy-pods) → Trigger discovery
- BecameLeaderEvent → Re-trigger discovery for new leader's DeploymentScheduler
- Discovery completes → Compare with previous endpoints → Publish HAProxyPodTerminatedEvent for removed pods → Publish HAProxyPodsDiscoveredEvent
func New ¶
New creates a new Discovery event adapter component.
Parameters:
- eventBus: The event bus for subscribing to and publishing events
- logger: Structured logger for observability
Returns a configured Component ready to be started, or an error if local HAProxy version detection fails (which is fatal - the controller cannot start without knowing its local version for compatibility checking).
Note: The Discovery pure component is created lazily when the dataplane port is configured via ConfigValidatedEvent. This constructor only detects the local HAProxy version for future compatibility checking.
func (*Component) Name ¶
Name returns the unique identifier for this component. Implements the lifecycle.Component interface.
func (*Component) SetPodStore ¶
SetPodStore sets the pod store reference.
This is called by the controller after creating the haproxy-pods resource watcher. It allows the Discovery component to access pod resources for endpoint discovery.
Thread-safe.
func (*Component) Start ¶
Start begins the Discovery component's event processing loop.
This method:
- Maintains state from config and credential updates
- Triggers discovery when HAProxy pods change (via ResourceSyncCompleteEvent)
- Publishes discovered endpoints
- Runs until context is cancelled
Returns an error if the event loop fails.
Note: Event subscription occurs in the constructor (New()) to ensure proper startup synchronization. ResourceSyncCompleteEvent is buffered until EventBus.Start() is called, so no events are missed.
type Discovery ¶
type Discovery struct {
// contains filtered or unexported fields
}
Discovery discovers HAProxy pod endpoints from Kubernetes resources.
This is a pure component that takes a pod store and credentials and returns a list of Dataplane API endpoints. It has no knowledge of events or the event bus - that coordination is handled by the event adapter.
The Discovery also holds the local HAProxy version, detected at startup, which is used by the event adapter for version compatibility checking.
func (*Discovery) DiscoverEndpoints ¶
func (d *Discovery) DiscoverEndpoints( podStore types.Store, credentials coreconfig.Credentials, ) ([]dataplane.Endpoint, error)
DiscoverEndpoints discovers HAProxy Dataplane API endpoints from pod resources.
This method:
- Lists all pods from the provided store
- Extracts pod IPs from pod.status.podIP
- Checks that the dataplane container is ready
- Constructs Dataplane API URLs (http://{IP}:{port})
- Creates Endpoint structs with credentials
Parameters:
- podStore: Store containing HAProxy pod resources
- credentials: Dataplane API credentials to use for all endpoints
Returns:
- A slice of discovered Endpoint structs
- An error if discovery fails
Example:
endpoints, err := discovery.DiscoverEndpoints(podStore, credentials)
if err != nil {
return fmt.Errorf("discovery failed: %w", err)
}
// Use endpoints for HAProxy synchronization
func (*Discovery) DiscoverEndpointsWithLogger ¶
func (d *Discovery) DiscoverEndpointsWithLogger( podStore types.Store, credentials coreconfig.Credentials, logger *slog.Logger, ) ([]dataplane.Endpoint, error)
DiscoverEndpointsWithLogger is like DiscoverEndpoints but accepts an optional logger for debugging.
func (*Discovery) LocalVersion ¶
LocalVersion returns the detected local HAProxy version. This is used by the event adapter for version compatibility checking.