Watch
0
0
Fork
You've already forked hyperhive
0

docs: the controller's runtime, hostPort hop, listener leaf, state and rev rollout

This commit is contained in:
atlas 2026-11-22 12:42:49 +01:00 • committed by maia
commit 74dcb9b369
3 changed files with 114 additions and 16 deletions

View file

@ -115,8 +115,17 @@ credential directory.
stay on the host: the pod has the security shape above and no other.
- **Probes:** a service with an opt-in health listener gets its variable set to
`0.0.0.0:8080`, with liveness on `/healthz` and readiness on `/readyz`
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` serves
`/readyz` on its unix socket only, so it has no probes yet.
(see [Readiness checks](../swarm/readiness.md)). `swarm-controller` is one of
them, with `SWARM_CONTROLLER_HEALTH_ADDR`.
- **Listener and init container:** a service with a TCP `listener`
(`swarm-controller`, with `swarm.controller.tcp.enable`) publishes its port on
the node's address with a `hostPort`, and gets an init container and a
renewal container that issue its leaf into an `emptyDir`
([runtime](runtime.md#the-controller)). The image of those containers is part
of `system.build.k8sImages`.
- **Config checksum:** a Deployment whose service has a ConfigMap (`etcFiles`)
carries `checksum/etc` on its pod template, the hash of that ConfigMap's
content, so a changed file rolls the pod.
- **Shutdown:** `terminationGracePeriodSeconds` is 15, the 10-second drain a
daemon allows itself after SIGTERM (`DRAIN` in
`swarm-secret-client/src/shutdown.rs`) plus headroom.
@ -154,7 +163,7 @@ store's side.
provider) by the same names as the units do. The node's CoreDNS answers those
names with the hive bridge's address.
- `swarm-controller`'s socket lives in an `emptyDir`, so only the pod can
reach it.
reach it. The gateway dials the TCP listener instead.
## Validation

View file

@ -6,9 +6,9 @@ is `"host"` (the default) or `"k8s"`. The service runs once per swarm, so the
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` and
`swarm-claude-login` have the option today, and the other services that run in
the cluster follow the same pattern.
`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.
## Options
@ -20,6 +20,12 @@ the cluster follow the same pattern.
`services.hyperhive.deploy.review-classifier.runtime` and
`services.hyperhive.deploy.claude-login.runtime` (default `"host"`), with the
same rule.
- `services.hyperhive.deploy.swarm-controller.runtime` (default `"host"`), with
the same rule. It also needs
`services.hyperhive.swarm.controller.tcp.enable`, and
`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.
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
@ -31,7 +37,10 @@ on `"host"`, the cluster holds no service objects.
(`swarm-notify-router`, `swarm-stt`, `swarm-review-classifier`,
`swarm-claude-login`), no credential hand-ins for it and no journal forwarder
for it. `swarm-ci-metrics` has no container: its service, its timer and the
CA bundle unit of its service go.
CA bundle unit of its service go. `swarm-controller` has no container
either: the host turns `swarm-controller.service` off, so nothing can start
it, and defines no `swarm-controller-tls.service` or timer. The evaluated
unit stays the source of the Deployment.
- **The service's objects go in.** The [rendered manifests](manifests.md) reach
the cluster through `services.k3s.manifests`, one file per service plus the
namespace. The cluster applies a file when its link appears in the manifests
@ -46,9 +55,13 @@ on `"host"`, the cluster holds no service objects.
- `trust-bundle.pem`: the hive's trust bundle, where the gateway is
self-signed;
- `bao-server-ca.pem`: the secret store's server CA
(`deploy.bao.serverCaFile`).
(`deploy.bao.serverCaFile`);
- `hive-client-ca.pem` and `swarm-services-root.pem`, with the controller in
the cluster: the authority the controller writes into each hive's store role
(`deploy.swarm-controller.hiveClientCaFile`), and the store's services root
that its listener trusts the gateway's client leaf by.
Both are public certificates. The unit waits for the cluster and for the
All are public certificates. The unit waits for the cluster and for the
files, and a pod that mounts the ConfigMap waits in `ContainerCreating` until
the unit has run. A path unit watches both files and runs the unit again when
either changes, with no manual step. A running pod doesn't see a changed
@ -109,6 +122,63 @@ with none pushes every run again, as the same points. A second Job on the same
side finds the cursor and pushes nothing. The claim stays after a switch back,
and so does the host's directory.
## The controller
`swarm-controller` runs once per swarm, and nothing in the daemon guards that: a
second copy would send the operator admin grants and revokes again, split the
review requests the queue holds, and write the same keys. The runtime switch is
the whole guard on one node: the Deployment has one replica and the `Recreate`
strategy, and the prune unit holds the host unit back until the pod has gone. No
leader lock exists, so a cluster of more than one node needs one before the
controller may move there.
- **The gateway's hop.** The host can't reach a unix socket inside a pod, so
the pod serves the TCP listener, and publishes it with a `hostPort` on
`deploy.swarm-controller.tcp.hostAddress`. That address is the hive bridge's
by default, the one the pods already reach the host's services on. The
listener binds `0.0.0.0` inside the pod (`tcp.listenAddress`, which the
evaluation holds there). The gateway's `/api/` and `/webhook/forge/`
locations dial the node's address and port, and verify the listener's
certificate as `swarm.controller.tcp.domain` (`proxy_ssl_name`,
`proxy_ssl_verify`). With the controller on the host the locations dial the
name. A `hostPort` reaches one node: a cluster of more than one node needs a
Service instead.
- **The listener's leaf.** The pod issues its own, from the store's
`swarm-controller-tls` role, with the same script as
`swarm-controller-tls.service`. An init container logs in with the pod's
ServiceAccount token (the `swarm-controller` role of the `jwt-k8s` mount,
whose policy holds the one issue path) and writes the leaf and its key into
an `emptyDir` before the daemon starts. The `emptyDir` is in memory
(`medium: Memory`), so the key never reaches a Secret or the node's disk. A
second container, `tls-renew`, runs the script again every day, and again
after ten minutes when the store refused. The script leaves a leaf alone
while it's in the first half of its lifetime, as the host's daily timer
does, and the daemon reads the new files with no restart. A sidecar renews
because nothing rolls the pod before the leaf expires. Both containers run
an image of their own, `swarm-controller-tls`, which holds the store client
and the script's tools.
- **`swarmctl`.** The controller's socket lives inside the pod, so the host's
`swarmctl` reaches the controller only through the gateway: run
`swarmctl login` once, then use `--swarm <url>` or a wrapper that defaults
to it. A socket path on the host serves nothing under `runtime = "k8s"`.
- **Probes.** The pod binds `SWARM_CONTROLLER_HEALTH_ADDR`, with liveness on
`/healthz` and readiness on `/readyz`. Readiness needs the queue connection
and a fresh store login, so a store role that refuses the pod's token leaves
it NotReady.
- **State.** `/var/lib/swarm-controller` is the PersistentVolumeClaim
`swarm-controller-state`. It starts empty, and nothing here copies the host's
directory into it ([migrate](migrate.md) does). An empty claim holds no
`operator-matrix-admins.json`, which reads as an empty set: the controller
revokes nobody, and an account removed from the operator group before the
copy keeps its homeserver admin. The webhook secret is in the store, so it
survives.
- **The rev.** The unit's rev file, `/etc/hyperhive/swarm-controller.json`, is a
`subPath` mount of the `swarm-controller-etc` ConfigMap, which a running pod
never sees change. The Deployment's pod template carries `checksum/etc`, a
hash of the ConfigMap's content, so a new rev rolls the pod. The host unit
re-reads the file with no restart, so this restart, which drops the job graph,
is new.
## Resources and sandbox
The pod takes the unit's `MemoryMax` and `CPUQuota` as its container's limits
@ -193,3 +263,14 @@ pod's root takes no writes, so a write outside the `/tmp` volume fails, and
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-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
Secret, that its listener's leaf is the one its init container issued, valid as
the listener's name against the hive's root, that the volume holding its key is
a tmpfs, and that the listener refuses a client with no leaf. It runs the
gateway's own controller location, from the module's text for each runtime,
against the host unit and the pod: both answer an unsigned webhook 401. A
changed rev rolls the Deployment onto a new pod and keeps the state volume, and
the switch back deletes the pod and its AddOn before the unit starts.

View file

@ -19,10 +19,13 @@ unit's value.
The collector stamps the hive's `hive` label on what it forwards, as it does for
agents. The pods run on that hive's node.
A swarm-tier producer keeps its own route. `swarm-ci-metrics` is one: its poller
reads `SWARM_CI_METRICS_OTLP_ENDPOINT`, which names its route of the swarm
collector, `https://<swarm.otel.domain>/swarm-ci-metrics`, and it mints the
bearer that route checks itself on each pass. The renderer sets nothing for such
A swarm-tier producer keeps its own route. `swarm-ci-metrics` and
`swarm-controller` are two. The controller's unit sets
`OTEL_EXPORTER_OTLP_ENDPOINT` to its route of the swarm collector and mints its
own bearer, so its pod keeps that value. The poller reads
`SWARM_CI_METRICS_OTLP_ENDPOINT`, which names its route of the swarm collector,
`https://<swarm.otel.domain>/swarm-ci-metrics`, and it mints the bearer that
route checks itself on each pass. The renderer sets nothing for such
a service (`otlp = "own"` in its entry of `render.nix`), because a series that
went through the hive collector would carry the `hive` label, and a swarm-level
series must not. The render refuses a service marked `"own"` whose unit names