Watch
0
0
Fork
You've already forked hyperhive
0

docs: the queue in the cluster

This commit is contained in:
atlas 2026-11-22 17:31:52 +01:00 • committed by maia
commit 7ff98d3c70

View file

@ -7,8 +7,9 @@ option moves it and never copies it: the host unit and the pod never run
together, because they would share one queue consumer and one set of buckets,
or two cursors that push every CI run twice. `swarm-notify-router`,
`swarm-stt`, `swarm-ci-metrics`, `swarm-review-classifier`,
`swarm-claude-login` and `swarm-controller` have the option today, and the
other services that run in the cluster follow the same pattern.
`swarm-claude-login`, `swarm-controller` and the queue with its auth callout
(`swarm-nats`) have the option today, and the other services that run in the
cluster follow the same pattern.
## Options
@ -26,6 +27,11 @@ other services that run in the cluster follow the same pattern.
`deploy.swarm-controller.tcp.listenAddress` at its default `0.0.0.0`: the
evaluation fails without either. [The controller](#the-controller) has its
own section.
- `services.hyperhive.deploy.nats.runtime` (default `"host"`), with the same
rule. One switch covers the queue's server and its auth callout. It needs
the iptables firewall (`networking.nftables.enable` off), and
`deploy.nats.k8s.freshStore` says whether a fresh store may start the
server. [The queue](#the-queue) has its own section.
With `"host"`, a host without [the cluster node](node.md) renders the same
configuration as before the option existed. With the node on and every service
@ -179,6 +185,80 @@ controller may move there.
re-reads the file with no restart, so this restart, which drops the job graph,
is new.
## The queue
`swarm-nats` is the swarm's message queue: the NATS server and the
auth-callout responder that admits its clients. Both belong to one pod,
because a server whose responder is down refuses every connect. A switch
moves the two together, and two servers or two responders never run: the
Deployment has one replica and the `Recreate` strategy, and the prune unit
holds the container back until the pod has gone.
- **Containers.** The responder is the pod's main container, `swarm-nats`,
rendered from the unit the container runs, as the other daemons are. Beside
it run `nats`, the server, `tls-renew` and `exporter`, the Prometheus
exporter. Three init containers run in order before them. `store-guard`
checks the JetStream volume. `tls-issue` issues the server's leaf.
`callout-config` creates the callout's keys if the store holds none, fetches
their public halves and writes the server's configuration. The server's
settings are the ones the container's `services.nats.settings` render, so a
change to them reaches both. Only the path of the server's key differs,
because the pod has no credential directory.
- **Names.** The pod's `hostAliases` map the queue's name to the pod's own
loopback, so the responder dials the server by the name its leaf carries and
verifies it, with no traffic leaving the pod. Every other client reaches the
queue by the same name as before: the node's CoreDNS and the bridge's
resolver answer it with the bridge's address, and the published port forwards
it to the pod.
- **The client port.** The server's port is a `hostPort` on `0.0.0.0`, the
addresses the container's server listens on, so hives on other hosts keep
their URL. A `hostPort` is a DNAT rule, and the firewall's INPUT rules, the
ones `deploy.nats.openFirewall` and the bridge's port list write, never see
what it rewrites. The module therefore adds rules to the raw table, which is
read before the DNAT: a packet for the node's address and the client port is
dropped unless it arrives on the host's loopback, the hive bridge or a pod
interface, or unless `deploy.nats.openFirewall` is on. The container's port
has that reach. The exporter's port is a `hostPort` on the bridge's address,
for the gateway's `/metrics` location on the host. The rules drop it on every
interface but the host's loopback: the exporter answers with the name of
every client, and only the host's own processes may read it.
- **The leaf.** `tls-issue` logs in to the store with the pod's token as the
role `swarm-nats` and issues the server's leaf from the same script as the
host's `swarm-bao-nats-tls`. The key lands in a volume in memory. The
callout's keys and the responder's own reads go through the role
`swarm-nats-auth`. A pod has one ServiceAccount, `swarm-nats`, so both roles
bind it. A fourth container, `tls-renew`, runs the same script every five
minutes beside the server. It leaves a leaf in the first half of its 30 days
alone, and issues a new one after that. Then it sends `SIGHUP` to the server,
which reloads its TLS files for new connections, so the pod shares its
processes among its containers. A connection already open keeps the old leaf.
- **The host's units.** `swarm-nats-auth-secrets` and
`swarm-bao-nats-callout-xkey` deliver into the container, so the configuration
turns them off. `swarm-bao-nats-tls` stays: it issues the host's own copy of
the leaf for the gateway's `/metrics` vhost, and with no container it has
nothing to restart. The gateway's location dials the exporter on the bridge's
address where it dialled loopback.
- **State.** The server's store directory, `/var/lib/nats`, is the
PersistentVolumeClaim `swarm-nats-state`. The claim starts empty, and a switch
copies nothing from the container's store: it holds the swarm's declared
desired state, which nothing regenerates. `store-guard` therefore stops the
pod, with a message naming `swarmctl migrate`, when the volume holds no
JetStream data, unless `deploy.nats.k8s.freshStore` is on. Turn it on for a
fresh install only. The claim stays after a switch back, as every claim
does, and the container's store stays too.
- **Readiness.** The pod is Ready when the responder's `/readyz`, on the pod's
port 8080, passes and the server's exec probe does. The probe runs
`wget` against `/healthz?js-enabled-only=true` on the server's monitor, which
stays on the pod's loopback; the server's image holds `wget` and nothing else
of busybox.
- **Stopping.** The container's unit drains the server's clients, giving them
up to 150 seconds to move. The pod's server gets `SIGTERM` and the pod's
15-second grace period, so every client's connection drops at once and the
clients reconnect when the next pod is up.
- **Limits.** None, as on the host. The pod has no memory or CPU limit, and its
descriptors are the container runtime's, not the 800000 the container's unit
sets. The VM test checks the runtime's is at least that.
## Resources and sandbox
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
@ -264,6 +344,19 @@ that `claude` with `HOME` in the volume writes its config there, as the
minter's real login step does, while `claude` with `HOME` on the root leaves
nothing there.
The VM test `k8s-nats-switch` moves the queue against the real secret store. A
sampler counts servers and responders every 200 ms and sees at most one of each,
and the container and the pod never together. The pod is Ready by its exec probe
and has the init containers, the `hostPort`s and the volumes the module renders,
and its leaf's volume is a tmpfs. A client on the bridge reaches the queue by
name, and a second node outside the node reaches the control port and not the
queue's, as with the container; with `openFirewall` it dials the pod by name and
verifies the name, and the responder in the pod admits it. A stream written
before a pod delete survives it: the replacement pod reads it from the same
volume. The store guard's image refuses an empty volume, passes a fresh one and
a volume with data. The exporter answers the host's own processes through the
published port, and the switch back removes the pod before the container starts.
The VM test `k8s-controller-switch` moves the controller. It asserts one copy at
each step by the switch's own timestamps and by a sampler, that the pod is Ready
on `/readyz` with the `hostPort` and the volumes the module renders and no