mesh

package
v1.3.2 Latest Latest
Warning

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

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

Documentation

Overview

Package mesh implements the mesh controller: the reconcile.Controller that keeps the WireGuard mesh and the internal DNS zone converged on whatever the store currently says the fleet and its placements look like.

Like internal/reconcile/ingress, and unlike the per-resource application and database controllers, this reconciles the whole fleet in one pass. That is not a convenience: a mesh is a property of the set of nodes, not of any one node, and every node's peer list changes when any node's key or address changes. There is no coherent "reconcile one node's mesh" operation to build.

Each pass:

  1. Reads every node and every placement from the store. Nothing about the fleet is cached between passes, the same level-triggered reconciler contract every controller in this codebase follows.
  2. Distributes mesh configuration through internal/network.Coordinator, which allocates any missing addresses, plans a full mesh, and sends each node its own config.
  3. Persists whatever the nodes reported back (their public keys) plus any newly allocated address, so the next pass plans from it.
  4. Rebuilds the internal DNS record set from the same node data and the current placements, and swaps it into the resolver.

Ordering matters between 3 and 4 and only in one direction: DNS records are built from the same in-memory inventory the distribution pass just updated, not from a re-read of the store, so a node whose address was allocated this very pass resolves immediately rather than one pass later.

What this controller does not do, and why:

  • It does not create or own the Mesh device. That belongs to whoever builds the process (the control plane's own node) or to the agent (a remote node), because a Mesh is a live handle on a kernel interface with a lifetime tied to the process, not to a reconcile pass.
  • It does not point containers at the DNS server. See internal/network's dns_server.go for exactly what that needs and why it is a separate change.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller reconciles the mesh and the internal DNS zone.

func New

func New(selfID string, st Store, distributor Distributor, resolver *network.Resolver, opts ...Option) *Controller

New builds the mesh controller. resolver is swapped wholesale on every pass and may be shared with a running network.DNSServer: that is the intended wiring, since network.Resolver.SetRecords is safe for concurrent use precisely so a reconcile pass can update it while queries are in flight.

func (*Controller) Name

func (c *Controller) Name() string

Name identifies this controller in logs and status lookups.

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context) (reconcile.Result, error)

Reconcile runs one full pass. See the package doc comment for the order and why.

Returns conditions even when it also returns an error, per reconcile.Controller's contract. Three conditions, not one, because three genuinely different things can be wrong and collapsing them would make the UI say "mesh degraded" without saying which half:

  • MeshPlanned: the inventory was coherent enough to plan from. False here means a duplicate key or an exhausted address range, and nothing was distributed at all.
  • MeshDistributed: every node accepted its config. False means at least one node is unreachable, which is expected and transient while the rest of the fleet still converged.
  • DNSResolvable: every placement resolved to a real mesh address. False means some service name will answer NXDOMAIN, which is a broken connection string, not a cosmetic gap.

type Distributor

type Distributor interface {
	Distribute(ctx context.Context, nodes []network.NodeInfo) ([]network.NodeInfo, network.DistributeResult, error)
}

Distributor is the narrow surface this controller needs from internal/network.Coordinator, so tests can drive the controller without building a coordinator and a sink. *network.Coordinator satisfies it.

type Option

type Option func(*Controller)

Option configures New.

func WithHiddenApps

func WithHiddenApps(f func(ctx context.Context) (map[string]bool, error)) Option

WithHiddenApps omits every service of the returned app IDs from mesh DNS, the cross-node half of private network default-deny.

func WithInternalNames

func WithInternalNames(enabled func(ctx context.Context) bool) Option

WithInternalNames serves each app's extra internal names while enabled reports true.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets the structured logger.

type Store

type Store interface {
	ListNodes(ctx context.Context) ([]store.Node, error)
	ListDesiredServices(ctx context.Context) ([]store.DesiredService, error)
	ListDesiredDatabases(ctx context.Context) ([]store.DesiredDatabase, error)
	UpdateNodeMesh(ctx context.Context, id, publicKey, address string) error
}

Store is the narrow surface this controller needs from internal/store, so tests can fake it without a real database. *store.DB satisfies it.

type Waker

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

Waker turns node membership changes into a debounced request for one reconcile pass. It only asks for a pass: the pass still reads the fleet from the store.

func NewWaker

func NewWaker(target func(), window func() time.Duration) *Waker

NewWaker builds a Waker that calls target once per window after the first Wake in it. window is read on every burst, so a settings change applies live.

func (*Waker) Wake

func (w *Waker) Wake()

Wake requests a pass. It never blocks, so it is safe on an agent session goroutine.

Jump to

Keyboard shortcuts

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