Documentation
¶
Overview ¶
Package discovery provides the Discovery event adapter component.
It tracks the set of HAProxy pods reported by the resource watcher (via the auto-injected haproxy-pods watcher), admits the ones whose agent answers /v1/state — carrying the HAProxy version it reports — and publishes HAProxyPodsDiscoveredEvent / HAProxyPodTerminatedEvent so the deployer and other consumers know which endpoints to talk to.
Package discovery provides HAProxy pod discovery functionality.
This package implements pure business logic for discovering HAProxy pod endpoints from pod resources: it extracts pod IPs, checks that the agent container is running, and constructs agent endpoints with credentials. Whether the agent answers is the event adapter's half of the rule.
This is a pure component with no event bus dependency - event coordination is handled by the adapter in pkg/controller/discovery.
Index ¶
Constants ¶
const ( // ComponentName is the unique identifier for this component. ComponentName = "discovery" // EventBufferSize is the buffer size for event subscriptions. // High-volume to absorb pod churn bursts during scaling and rolling updates. EventBufferSize = busevents.HighVolumeSubscriberBuffer )
const ( RejectionAgentNotRunning = "agent_container_not_running" RejectionAgentUnreachable = "agent_unreachable" )
Rejection reasons, reported as haptic_haproxy_pods_rejected_total{reason}.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Candidate ¶
type Candidate struct {
Endpoint dataplane.Endpoint
Reason string // empty when the pod is a candidate
}
Candidate is one pod's verdict: an endpoint the adapter should probe, or the reason the pod is not one.
type Component ¶
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.
Note: The Discovery pure component is created lazily when the dataplane port is configured via ConfigValidatedEvent.
func (*Component) HandleEvent ¶
HandleEvent implements component.EventHandler: it processes incoming events and triggers discovery as needed.
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 runs the embedded component.Base event loop until the context is cancelled.
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 the pods worth probing. It has no knowledge of events or the event bus - that coordination is handled by the event adapter.
func (*Discovery) DiscoverEndpoints ¶
func (d *Discovery) DiscoverEndpoints( podStore types.Store, credentials coreconfig.Credentials, ) ([]Candidate, error)
DiscoverEndpoints returns the candidate endpoints from pod resources.
It lists every pod in the store, keeps the ones with an IP whose agent container is running, and builds the agent endpoint from the pod IP, the configured port and the credentials. Whether the agent answers is decided by the caller, which owns the HTTP client.
func (*Discovery) DiscoverEndpointsWithLogger ¶
func (d *Discovery) DiscoverEndpointsWithLogger( podStore types.Store, credentials coreconfig.Credentials, logger *slog.Logger, ) ([]Candidate, error)
DiscoverEndpointsWithLogger is like DiscoverEndpoints but accepts an optional logger for debugging.