Watch
0
0
Fork
You've already forked hyperhive
0

k8s: deploy.notify-router.runtime moves the router between its container and the cluster

This commit is contained in:
atlas 2026-11-21 15:16:32 +01:00 • committed by maia
commit a1d44ed046
5 changed files with 671 additions and 187 deletions

View file

@ -249,8 +249,9 @@ The notification router, in a `swarm-notify-router` container on the host that
sets `deploy.notify-router.enable`. Run one: it handles each issue's events in
order. It turns forge events (assigning an issue or pull request, closing it, a
failed CI run on a pull request) into todos for the agents they concern, and an
agent that's down gets its todos when it's back. The flows and the delivery
path:
agent that's down gets its todos when it's back. Set
`deploy.notify-router.runtime = "k8s"` to run it as a pod in the host's cluster
instead of the container. The flows and the delivery path:
[`notify-router.md`](../../4-implementation/swarm/notify-router.md), and
[Host setup](../../4-implementation/swarm/notify-router.md#host-setup).

View file

@ -6,8 +6,8 @@ the systemd unit each service runs today. A host with
`services.hyperhive.k8s.enable` gets them as `system.build.k8sManifests`, a
directory with one YAML file per object, and the images their pods run as
`system.build.k8sImages`, which [the cluster node](node.md) loads. Rendering
changes no unit, and nothing in this module applies the manifests to a
cluster.
changes no unit. [The runtime switch](runtime.md) applies a service's manifests
to the cluster, when the service's `runtime` says `"k8s"`.
## Options
@ -77,9 +77,10 @@ A credential that holds a public CA file isn't a secret. `swarm-notify-router`'s
`notify-router-bao-server-ca` comes from the ConfigMap `hyperhive-ca-trust`,
key `bao-server-ca.pem`, and its trust bundles from the key `trust-bundle.pem`.
The manifests only name the ConfigMap, because the hive CA exists only at
runtime, and nothing here creates it. A service with both kinds of credential
gets one projected volume that merges the Secret's keys and the ConfigMap's into
the credential directory.
runtime. [The runtime switch](runtime.md#what-k8s-changes) publishes it from the
host's files. A service with both kinds of credential gets one
projected volume that merges the Secret's keys and the ConfigMap's into the
credential directory.
## Pods

View file

@ -38,7 +38,8 @@ The cluster starts with no hyperhive workload. Each service keeps running as
its systemd unit, and nothing applies the services' manifests: two copies of
`swarm-notify-router`, `swarm-ci-metrics` or `swarm-controller` would share one
queue consumer, one cursor or one swarm. A service's objects go into the
cluster when that service moves in (see [`swarmctl migrate`](migrate.md)).
cluster when its `runtime` is `"k8s"` ([the runtime switch](runtime.md), which
[`swarmctl migrate`](migrate.md) drives).
With the option off, the host's configuration is the one it has without the
module.

View file

@ -0,0 +1,88 @@
# Where a service runs: the runtime switch
A swarm service with a `runtime` option runs in one of two places: as its host
unit, or as a pod in the host's cluster. `services.hyperhive.deploy.<service>.runtime`
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.
`swarm-notify-router` has the option today, and the other services that run in
the cluster follow the same pattern.
## Options
- `services.hyperhive.deploy.notify-router.runtime` (default `"host"`).
`"k8s"` needs `services.hyperhive.deploy.k8s.enable` on the same host, and the
evaluation fails without it.
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
on `"host"`, the cluster holds no service objects.
## What `"k8s"` changes
- **The host unit goes.** The configuration has no `swarm-notify-router`
container, no credential hand-ins for it and no journal forwarder for it.
- **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
directory.
- **The pod reads the unit the container ran.** The unit comes from the
container's own configuration, evaluated on its own when the host has no
container, so the pod's environment is the unit's environment either way.
- **The host publishes the CA files.** `hyperhive-k8s-ca-trust.service` applies
the `hyperhive-ca-trust` ConfigMap from the host's files, with no manual step:
- `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`).
Both 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
trust bundle until it restarts, because the kubelet doesn't update `subPath`
mounts.
## One copy at a time
`switch-to-configuration` stops every unit the new configuration drops, and waits
for each stop, before it activates the new configuration. The activation links
the manifests. Switching to `"k8s"` therefore stops the container before the
cluster can apply the pod.
The cluster doesn't delete what a manifest created after the manifest goes away,
and it keeps the file's link in its manifests directory. Switching back to
`"host"` therefore needs a step of its own. `<service>-k8s-prune.service` belongs
to every configuration that has the node and the service on `"host"`, and the
service's host unit requires it and starts after it:
1. If the manifest's link exists, rename it to `<service>.yaml.pruning`, so the
cluster doesn't apply it again. The rename also records what remains to
delete. With no link, nothing went in, so the unit does nothing and needs no
cluster.
2. Wait for the cluster's API, then delete the service's Deployment, CronJob and
ServiceAccount (selected by `app.kubernetes.io/name`), and wait until its pods
have gone. A pod exits 0 within its termination grace period.
3. Delete the cluster's AddOn for the file, so that a later switch to `"k8s"`
applies the same manifest again. Then remove the renamed link.
A failed step fails the unit, and the host unit doesn't start: the service stays
down and never doubles. A rerun resumes from the renamed link. Persistent volume
claims stay; `swarmctl migrate finish` deletes them.
## State
`swarm-notify-router` keeps nothing on the host. Its durable consumer on the
forge events stream and its `notify-router-state` bucket live in the queue, so a
switch in either direction copies nothing, and the router continues from the
consumer's position.
## Validation
`module-eval-k8s` checks that the host render with `"host"` holds the container,
no cluster manifests and no CA objects. With `"k8s"` it checks that no container
remains, that the manifests sit in `services.k3s.manifests`, and that the
evaluation refuses `"k8s"` without the node. The VM test `k8s-runtime-switch`
runs a router against the real secret store and a queue. It switches from the
host to the cluster and back, checks each step for exactly one copy, and asserts
that the pod logs in, routes an event, and exits 0 when deleted.

View file

@ -441,6 +441,11 @@ that sets `deploy.notify-router.enable`. `allSwarmServices` defaults it on
wherever the host has the router's store identity, on the review classifier's
terms. Run one: it handles each issue's events in order.
With `deploy.notify-router.runtime = "k8s"` on a host that runs the cluster
(`deploy.k8s.enable`), the router runs as a pod and the host has no container.
The router keeps nothing on the host, so the switch copies nothing; see
[the runtime switch](../k8s/runtime.md).
swarm-controller keeps every `issues` and `pull_request` delivery, and every
failed or cancelled CI run, from its instance-wide hooks in the `SWARM_EVENTS`
stream. The router reads that