haproxy

package
v0.1.0-alpha.41 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

Package haproxy implements proxy.Driver with HAProxy running as an Armada-managed system container. Structural changes are rendered to a config file, validated with `haproxy -c`, and applied with a graceful reload; server changes go through the Runtime API without a reload.

Index

Constants

View Source
const Image = "haproxy:3.2-alpine@sha256:5893840576071e6217cd52ebdcc14f454c6f7a631056fa6f4e0f40d3cac4215b"

Image is the HAProxy image, pinned by digest (3.2 LTS, Alpine). Update it through a reviewed PR; never use a mutable tag.

View Source
const MetricsPort = 8404

MetricsPort is the HAProxy stats/metrics port on the node's private IP.

View Source
const WakeSocketFile = "wake.sock"

WakeSocketFile is the agent's wake socket in the proxy's run directory, the only place HAProxy and the agent share.

Variables

This section is empty.

Functions

func WakeSocket

func WakeSocket(dir string) string

WakeSocket returns the host path of the wake socket for a proxy directory.

Types

type API

type API interface {
	Command(ctx context.Context, cmd string) (string, error)
	// Payload sends a command followed by a multi-line payload.
	Payload(ctx context.Context, cmd, payload string) (string, error)
}

API is the subset of the HAProxy Runtime API the driver uses.

type Config

type Config struct {
	// Dir is the host directory holding etc/ (config, certs) and run/
	// (Runtime API socket). It is created with mode 0700.
	Dir       string
	PrivateIP string
	// InternalIP is the container bridge gateway for the internal frontend;
	// empty disables internal ingress on this node.
	InternalIP string
	// Subnet is the node's container subnet in the cluster network, where
	// its replicas have their own addresses (ADR 0025); empty otherwise.
	Subnet string
	Engine Engine
	// API defaults to the Runtime API socket under Dir.
	API API
	// Listeners returns the TCP sockets listening on the node; it defaults
	// to reading /proc/net (ADR 0039).
	Listeners func() ([]netip.AddrPort, error)
	Logger    *slog.Logger
}

Config configures a Driver.

type ContainerEngine

type ContainerEngine struct {
	Runtime runtime.Driver
	System  runtime.SystemRunner
	// Dir is the same host directory given to the Driver.
	Dir   string
	Image string
	// StartWait is how long Start waits to confirm HAProxy stays up.
	StartWait time.Duration
}

ContainerEngine runs HAProxy as a host-network system container.

func (*ContainerEngine) Reload

func (e *ContainerEngine) Reload(ctx context.Context) error

Reload sends SIGUSR2 to the HAProxy master process.

func (*ContainerEngine) Running

func (e *ContainerEngine) Running(ctx context.Context) (bool, error)

Running reports whether the HAProxy container is up with the pinned image and this engine's directory.

func (*ContainerEngine) Start

func (e *ContainerEngine) Start(ctx context.Context) error

Start replaces any existing HAProxy container with a fresh one.

func (*ContainerEngine) Validate

func (e *ContainerEngine) Validate(ctx context.Context, file string) error

Validate runs `haproxy -c -f file` inside the running container.

type Driver

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

Driver is the HAProxy proxy.Driver.

func New

func New(cfg Config) (*Driver, error)

New prepares the directories and default certificate.

func (*Driver) Apply

func (d *Driver) Apply(ctx context.Context, cfg proxy.Config) error

Apply implements proxy.Driver.

func (*Driver) Health

func (d *Driver) Health(ctx context.Context) error

Health implements proxy.Driver.

func (*Driver) Load

func (d *Driver) Load(ctx context.Context) (map[string]proxy.ServerLoad, error)

Load implements proxy.LoadReader from the Runtime API's "show stat": each slot's current sessions plus its queue, and its total sessions, mapped back to the replica in that slot. Totals keep growing across reloads.

func (*Driver) SetClients

func (d *Driver) SetClients(ctx context.Context, clients map[netip.Addr]string) error

SetClients implements proxy.ClientSetter: it maps the addresses of this node's containers to their apps for the internal frontend's checks (ADR 0026). The map file is replaced for the next start or reload, and a running HAProxy gets the new map at once, atomically, through the Runtime API.

type Engine

type Engine interface {
	Running(ctx context.Context) (bool, error)
	// Start (re)creates the HAProxy container from the current config file.
	Start(ctx context.Context) error
	// Validate runs `haproxy -c` against a config file (container path).
	Validate(ctx context.Context, file string) error
	// Reload gracefully reloads the configuration (master-worker SIGUSR2).
	Reload(ctx context.Context) error
}

Engine controls the HAProxy process.

type Layout

type Layout map[string][]string

Layout assigns replicas to fixed server slots per HAProxy backend. Slots let the Runtime API change servers without a reload; an empty string marks a free slot.

type Socket

type Socket struct {
	Path    string
	Timeout time.Duration
}

Socket talks to the Runtime API over its Unix socket, one command per connection (non-interactive mode).

func (Socket) Command

func (s Socket) Command(ctx context.Context, cmd string) (string, error)

Command runs one Runtime API command.

func (Socket) Payload

func (s Socket) Payload(ctx context.Context, cmd, payload string) (string, error)

Payload runs a command that takes a payload (e.g. "set ssl cert").

Jump to

Keyboard shortcuts

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