11 KiB
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,
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.
Options
services.hyperhive.deploy.notify-router.runtime(default"host")."k8s"needsservices.hyperhive.deploy.k8s.enableon the same host, and the evaluation fails without it.services.hyperhive.deploy.stt.runtime,services.hyperhive.deploy.ci-metrics.runtime,services.hyperhive.deploy.review-classifier.runtimeandservices.hyperhive.deploy.claude-login.runtime(default"host"), with the same rule.
With "host", a host without the cluster node 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 container for the service (
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-metricshas no container: its service, its timer and the CA bundle unit of its service go. -
The service's objects go in. The rendered manifests 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 poller has no container: the renderer evaluates its service and timer on their own when the host doesn't run them, and the CronJob follows that timer.
-
The host publishes the CA files.
hyperhive-k8s-ca-trust.serviceapplies thehyperhive-ca-trustConfigMap 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
ContainerCreatinguntil 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 updatesubPathmounts.
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 each
of the service's host units requires it and starts after it. The poller has
two, its timer and its service, so a pass started by hand can't run beside a
Job:
- 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. - 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. - 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.
swarm-stt keeps a transcript cache, which lives 24 hours. On the host the
cache sits in the container's /var/lib/swarm-stt. In the cluster it sits in
the PersistentVolumeClaim swarm-stt-state, mounted at the same path. A switch
copies neither: each side starts with the cache it last had, empty the first
time, and transcribes a memo that only the other side cached. The claim stays
after a switch back, as every claim does, and the container's directory stays
too. The whisper model isn't state: the pod's image holds it, from the same
store path the container reads, and the volume doesn't.
swarm-ci-metrics keeps a cursor, cursor.json, which holds the run numbers
already pushed. On the host it sits in the service's state directory. In the
cluster it sits in the PersistentVolumeClaim swarm-ci-metrics-state, mounted
at the same path, and the claim binds with the first Job. A switch copies
neither, so each side keeps the cursor it last had, and the first pass on a side
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.
Resources and sandbox
The pod takes the unit's MemoryMax and CPUQuota as its container's limits
(manifests), so swarm-stt keeps its 3 GiB and four-core
ceilings. The pod requests nothing (memory 0, cpu 0, as the unit sets no
MemoryMin or MemoryLow), so the node reserves nothing for it and the pod is
Burstable. TasksMax has no pod counterpart, so the renderer drops it. The systemd sandbox
(MemoryDenyWriteExecute, SystemCallFilter, PrivateUsers, the read-only
ProtectSystem and the rest) stays on the host. The pod is a non-root user with
a read-only root filesystem, every capability dropped, the runtime's default
seccomp profile and no API token, which is its whole sandbox. Neither side
restricts the network.
Telemetry and credentials of the poller
The pod of swarm-ci-metrics keeps pushing to its route of the swarm
collector, https://<swarm.otel.domain>/swarm-ci-metrics, with the bearer it
mints for itself each pass. The renderer sets no hive collector endpoint for it
(telemetry). The pod holds no client certificate, so it
doesn't push the bao.client_cert.* gauges of the host unit. Its one credential
file is the store's CA, bao-ca.pem, which comes from the hyperhive-ca-trust
ConfigMap. The pod has no Secret volume, and no swarm-ci-metrics-credentials
Secret exists, because nothing creates it.
The claude daemons
swarm-review-classifier and swarm-claude-login keep no state, so a switch
moves nothing and the renderer adds no volume. Their units set no limits, so their
pods have none. Both run claude, which the daemon starts with HOME set to a
scratch directory under the system's temporary directory (the classifier also
starts opencode that way). The pod's root filesystem takes no writes, and its
/tmp is an emptyDir volume, so each scratch directory, and the config
claude writes under it, land in that volume and go with the pod. The
claude login minter writes the credentials it gets to the secret store, not to
disk. The image holds claude-code (and opencode for the classifier) from the
store paths the unit's environment names, the same ones the container uses. The
unit's own configuration allows the unfree claude-code, so the host needs no
global allowance.
Both log in to the store with their ServiceAccount token through a jwt role
that has the policy of their certificate role. The minter's role writes the
agents' claude-credentials leaves, as its certificate does.
Neither side restricts the network. The review classifier runs a model-driven
agent over untrusted PR text, and its ACP runtime takes its base_url from the
run, so the hosts it reaches aren't fixed. In a pod it has the security shape
every pod has (above) in place of its unit's DynamicUser and PrivateTmp. A
tighter sandbox and an egress policy belong to the network policy work.
Both pods push their telemetry to the hive collector, as the router and
swarm-stt do, because the loopback forwarder their units name has no
counterpart in a pod. The hive collector stamps the hive label on what it
forwards.
Validation
module-eval-k8s checks that the host render with "host" holds the container,
no cluster manifests and no CA objects, and that swarm-stt's container and
unit are as the module defines them, and likewise for the review classifier and the claude
login minter. 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, and that the poller's pod keeps
the swarm route its unit names, where every other pod gets the hive collector,
and mounts no Secret. The VM test k8s-runtime-switch runs a router, the
speech-to-text service, the CI run poller, the review classifier and the claude
login minter against the real secret store and a queue. It switches all five
from the host to the cluster and back, checks each step for exactly one copy of
each, and asserts that the router's pod logs in, routes an event, and exits 0
when deleted. For swarm-stt it asserts that the pod is Ready, logged in to
the store with its ServiceAccount token, carries the unit's limits, requests
nothing and is Burstable, and has its cache volume bound. For
swarm-ci-metrics it asserts that the host has no timer or service on the
cluster side, and that the cluster has no CronJob, Job or pod on the host side
before the timer starts. A Job completes against a forge stub that lists one run
and pushes it to the poller's own route with a bearer the identity provider
stub minted. The pod holds no Secret and binds its cursor volume, and a second
Job, and a Job after a round trip through the host, push nothing. The host's
own pass against the same stubs is the control. For the two claude daemons it
asserts that each pod is Ready and logged in with its token, that the minter's
token writes an agent's credentials and the classifier's token can't, that the
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.