# 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..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`, `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 - `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. - `services.hyperhive.deploy.stt.runtime`, `services.hyperhive.deploy.ci-metrics.runtime`, `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. - `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). [The queue](#the-queue) has its own section. - `services.hyperhive.deploy..k8s.freshState` (default `false`) for the service whose pod keeps state worth moving in a volume: `swarm-controller`. It says whether the pod may start on an empty volume ([State](#state)). 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 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-metrics` has no container: its service, its timer and the 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 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.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`); - `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. 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 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. `-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: 1. If the manifest's link exists, rename it to `.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 A pod with a state volume that holds state worth moving (`swarm-controller`) starts only on migrated state. Its first init container, `state-gate`, mounts the volume and exits 0 when the volume holds `.hyperhive-migrated`. A volume with no entries besides `lost+found` gets the marker (`{"fresh": true, "at":