remove swarmctl migrate, migrate.json and the migrate docs
This commit is contained in:
parent
210c60cde0
commit
077f6f707d
3 changed files with 25 additions and 1398 deletions
|
|
@ -1,163 +0,0 @@
|
|||
# Moving an all-local swarm onto k8s: `swarmctl migrate`
|
||||
|
||||
A running all-local swarm (`services.hyperhive.deploy.singleHostSwarm`) moves
|
||||
onto the k3s cluster on the same host one service at a time. The operator sets
|
||||
`deploy.<svc>.runtime = "k8s"` and rebuilds; `swarmctl migrate status` reports
|
||||
where each service stands. Nothing copies a service's state: each one's pod
|
||||
re-derives what it keeps, keeps it in the service's own store, or uses the host
|
||||
unit's directory in place.
|
||||
|
||||
## Scope and guarantees
|
||||
|
||||
The swarm's own daemons and the queue move into the cluster:
|
||||
`swarm-notify-router`, `swarm-review-classifier`, `swarm-claude-login`,
|
||||
`swarm-stt`, `swarm-ci-metrics`, NATS with `swarm-nats-auth`, and
|
||||
`swarm-controller`. bao, the forge, authelia, the gateway, `swarm-builder`,
|
||||
`swarm-matrix-ctl` and every hive keep running on the host.
|
||||
|
||||
- **The hive contract stays the same.** Hives and agents keep the NATS URL,
|
||||
its port, its certificate name and its auth callout. No hive needs a
|
||||
rebuild for any move.
|
||||
- **One nix option decides where a service runs.** `deploy.<svc>.runtime` is
|
||||
`"host"` (the default) or `"k8s"`. The cut-over is an operator rebuild,
|
||||
never a runtime toggle that `swarmctl` flips on its own.
|
||||
- **A move leaves the host's data alone.** The host unit's directories stay
|
||||
where they're, so going back is `runtime = "host"` and a rebuild.
|
||||
|
||||
### Names
|
||||
|
||||
| name | what it names |
|
||||
| ----------------------------------------- | --------------------------------------------------------------- |
|
||||
| `services.hyperhive.deploy.k8s.enable` | brings up single-node k3s on the swarm host |
|
||||
| `services.hyperhive.deploy.<svc>.runtime` | `"host"` or `"k8s"`, per service |
|
||||
| `/etc/hyperhive/migrate.json` | the module's render of each service's runtime and host units |
|
||||
| `SWARMCTL_KUBECTL`, `SWARMCTL_KUBECONFIG` | the `swarmctl` wrapper's `kubectl` and the k3s admin kubeconfig |
|
||||
| `swarmctl migrate status` | the one verb: a read-only report |
|
||||
|
||||
## `swarmctl migrate status`
|
||||
|
||||
It reads `/etc/hyperhive/migrate.json`, asks systemd whether each service's
|
||||
host units run, and lists the pods of the swarm's namespace with one
|
||||
`kubectl get`. It creates and changes nothing. For each service it reports:
|
||||
|
||||
- **runtime**: whether the host units have stopped when the configuration says
|
||||
`k8s`, and whether the cluster still holds a pod of a service the
|
||||
configuration puts on the host;
|
||||
- **order**: whether the service moved before one that comes earlier in the
|
||||
[order of moves](#order-of-moves);
|
||||
- **ready**: whether the newest pod's readiness probe passes (a `CronJob`'s pod
|
||||
finishes when its Job completed).
|
||||
|
||||
It names the next step that isn't done, exits 0 when every check ran, and
|
||||
exits 1 when a check failed to run. `--json` prints the services as the module
|
||||
renders them, every step with its status, and the next step.
|
||||
|
||||
## Services
|
||||
|
||||
"Ready" means the pod's readiness probe passes. The probes read the `/readyz`
|
||||
endpoints the [services page](../../2-handbook/swarm/services.md) lists; the
|
||||
[readiness page](../swarm/readiness.md) has their mechanics.
|
||||
|
||||
| service | state | what the pod starts with | readiness signal | cut-over and rollback |
|
||||
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `swarm-notify-router` | in the queue: a state bucket and a durable consumer on the forge events stream | the queue's | `/readyz`: queue connected | `runtime = "k8s"`, rebuild; back with `runtime = "host"` |
|
||||
| `swarm-review-classifier` | none on disk; its runs and settings live in buckets the controller owns | the queue's | `/readyz`: queue connected | same |
|
||||
| `swarm-claude-login` | none; credentials it writes go to the store | nothing; a login in progress ends | `/readyz`: queue connected | same |
|
||||
| `swarm-stt` | the transcript cache, entries live 24 h; the pod keeps it in an `emptyDir` | an empty cache | `/readyz`: queue connected | same |
|
||||
| `swarm-ci-metrics` | `cursor.json` in the state directory; losing it re-pushes every run | an empty claim: the first pass re-pushes every run as the same points | the CronJob's next Job completes | `runtime = "k8s"`, rebuild; the timer goes, the CronJob runs; back with `runtime = "host"` |
|
||||
| NATS + `swarm-nats-auth` | JetStream's `store_dir`: the swarm's desired state, operator profiles, schedules and run records. `swarm-nats-auth` keeps nothing | the host unit's own `store_dir`, in place | nats-server's `/healthz?js-enabled-only=true` and `swarm-nats-auth`'s `/readyz`; Ready when both pass | `runtime = "k8s"`, rebuild; the pod takes the same host port, so hives keep their URL. Rollback is `runtime = "host"` and a rebuild: the same files |
|
||||
| `swarm-controller` | its state directory holds the legacy `webhook-secret` (the store has it too), the forge avatar markers and, once, a legacy operator-admin file; the grant record is in the queue's key-value store | an `emptyDir` | `/readyz` on the controller's plain health listener | `runtime = "k8s"`, rebuild; the same rebuild points the gateway's `/api/` and `/webhook/forge/` upstreams at the controller's TCP listener. Back with `runtime = "host"` and a rebuild |
|
||||
|
||||
Two facts the table rests on:
|
||||
|
||||
- **The queue's store is state that must survive.** Losing it empties the
|
||||
hive-status view, and it also loses the buckets that hold desired state.
|
||||
It never leaves its directory on the host: the pod and the container use
|
||||
the same files, so a switch in either direction copies nothing, and the
|
||||
streams, consumers and acknowledgements are the ones the other side left.
|
||||
See [the queue's store](#the-queues-store).
|
||||
- **The controller keeps no state of its own that a move could lose.** The
|
||||
record of the Matrix admin grants is in the queue's key-value store, the
|
||||
webhook secret is in the secret store, and the controller sets the avatar
|
||||
markers again at start. The first start of the controller on the host after
|
||||
an upgrade imports a legacy grant file into the store, so run the host
|
||||
controller once before the switch.
|
||||
|
||||
## The queue's store
|
||||
|
||||
The queue's pod uses the directory its container's `nats` unit already uses:
|
||||
`/var/lib/nixos-containers/swarm-nats/var/lib/nats` on the host, `/var/lib/nats`
|
||||
in both. The module renders a static `local` PersistentVolume on that path,
|
||||
pinned to the node, with a storage class of its own and the `Retain` policy.
|
||||
The claim `swarm-nats-store` binds it by name, so nothing else binds either.
|
||||
|
||||
- **One server at a time.** The prune unit stops a pod before the container
|
||||
starts, and the Deployment replaces its pod rather than running two. Nothing
|
||||
reads the directory while the other side writes.
|
||||
- **Pod to host.** nats-server creates its files with mode `0600`, owned by the
|
||||
uid it runs as. The pod runs as uid 65532, so the container's `nats` unit
|
||||
runs `chown -R nats:nats` on the directory before the server starts, as root
|
||||
and at every start.
|
||||
- **Host to pod.** The pod's `fsGroup` makes the kubelet set the directory's
|
||||
group to the pod's and add group read and write on every file at each pod
|
||||
start, so the pod's uid can use files the host's `nats` user wrote.
|
||||
- **No lock or identity file.** nats-server keeps none in the store, so
|
||||
nothing there ties the directory to the side that wrote it.
|
||||
- **A host that never ran the container.** The module makes the directory,
|
||||
because the volume needs it before the pod starts.
|
||||
- **An older claim.** A `swarm-nats-state` claim from an earlier shape isn't
|
||||
the queue's any more: the pod mounts `swarm-nats-store`, so the old claim
|
||||
stays unused and needs no step.
|
||||
|
||||
## Order of moves
|
||||
|
||||
`swarmctl migrate status` reports the services in this order, and flags a
|
||||
service that moved ahead of an earlier one:
|
||||
|
||||
1. **`swarm-notify-router` alone.** The first cut-over proves the runtime
|
||||
switch, the image, the store identity and reaching the host-run NATS by
|
||||
name.
|
||||
2. **`swarm-review-classifier`, `swarm-claude-login`, `swarm-stt`,
|
||||
`swarm-ci-metrics`**, in one rebuild or one at a time, the same pattern as
|
||||
step 1.
|
||||
3. **NATS with `swarm-nats-auth`.** The riskiest move: every hive and agent
|
||||
disconnects, and the data is the swarm's desired state. Nothing copies it.
|
||||
`swarm-nats-auth` moves in the same pod, because it answers the auth
|
||||
callout on every connect and dials the server by name, which the pod's
|
||||
host aliases map to its loopback.
|
||||
4. **`swarm-controller` last.**
|
||||
- It's the operator's view of the swarm. Kept on the host through step 3,
|
||||
it reports from an unchanged place whether the hives reconnected after
|
||||
the NATS move, and `swarmctl` keeps its local socket for the checks.
|
||||
- Its cut-over also changes the gateway's upstream and ends the local
|
||||
socket for `swarmctl`, the widest change to the operator's tools.
|
||||
|
||||
Each step needs the previous one Ready. `swarmctl migrate status` says which
|
||||
service comes next.
|
||||
|
||||
## Downtime and what hives see
|
||||
|
||||
The budget is the time from the cut-over rebuild stopping the host unit to the
|
||||
pod being Ready.
|
||||
|
||||
| service | budget | what hives, agents and the operator see |
|
||||
| ------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `swarm-notify-router` | 2 min | Forge events wait in the stream behind the durable consumer and arrive late |
|
||||
| `swarm-review-classifier` | 2 min | A try-out request in the gap gets no answer, and its caller reports a failure |
|
||||
| `swarm-claude-login` | 2 min | A login in progress fails; the operator starts it again |
|
||||
| `swarm-stt` | 2 min | Transcription requests fail during the gap; the cache starts empty |
|
||||
| `swarm-ci-metrics` | one 5-minute period | One pass runs late; the first pass on the pod's empty cursor pushes every run again |
|
||||
| NATS + `swarm-nats-auth` | 10 min | below |
|
||||
| `swarm-controller` | 5 min | The swarm UI and API answer with gateway errors. Forge webhook deliveries in the gap fail at the forge. After the cut-over, `swarmctl` on the host needs `--swarm` |
|
||||
|
||||
During the NATS gap:
|
||||
|
||||
- Every hive, agent and swarm daemon loses its connection. The queue client
|
||||
retries at once, then backs off from 500 ms up to one minute. Clients
|
||||
therefore return within a minute of the pod passing readiness.
|
||||
- The desired-state buckets aren't readable. Hives apply no change, and
|
||||
running agents keep running as they are.
|
||||
- Operator input to agents and agent status in the UI stall, and the UI shows
|
||||
status as stale.
|
||||
- Core NATS messages published in the gap get lost. JetStream publishes fail
|
||||
at the publisher.
|
||||
|
|
@ -42,8 +42,7 @@ 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 its `runtime` is `"k8s"` ([the runtime switch](runtime.md), which
|
||||
[`swarmctl migrate status`](migrate.md) reports).
|
||||
cluster when its `runtime` is `"k8s"` ([the runtime switch](runtime.md)).
|
||||
|
||||
With the option off, the host's configuration is the one it has without the
|
||||
module.
|
||||
|
|
|
|||
|
|
@ -11,6 +11,16 @@ or two cursors that push every CI run twice. `swarm-notify-router`,
|
|||
(`swarm-nats`) have the option today, and the other services that run in the
|
||||
cluster follow the same pattern.
|
||||
|
||||
## Moving a service
|
||||
|
||||
To move a service into the cluster, set its `runtime` to `"k8s"` and rebuild.
|
||||
To move it back, set `runtime` back to `"host"` and rebuild.
|
||||
No command copies data, and a move loses nothing a service holds.
|
||||
The queue keeps its host store: the pod mounts the directory the container's unit uses, so a switch moves the process and not the bytes.
|
||||
The controller and the other services hold nothing a move loses; [State](#state) lists what each one keeps.
|
||||
Hives and agents keep the queue's URL, port, certificate name and auth callout, so no hive needs a rebuild.
|
||||
The secret store, the forge, authelia, the gateway, `swarm-builder`, `swarm-matrix-ctl` and every hive stay on the host.
|
||||
|
||||
## Options
|
||||
|
||||
- `services.hyperhive.deploy.notify-router.runtime` (default `"host"`).
|
||||
|
|
@ -281,9 +291,17 @@ holds the container back until the pod has gone.
|
|||
so a switch moves the process and not the bytes, and the pod has no state
|
||||
gate. The container's unit runs `chown -R nats:nats` on the directory before
|
||||
the server starts, and the pod's `fsGroup` gives its group read and write.
|
||||
[The queue's store](migrate.md#the-queues-store) has the details. The claim
|
||||
and its volume stay after a switch back, as every claim does, with the
|
||||
directory.
|
||||
The volume is `local`, pinned to the node, with a storage class of its own
|
||||
and the `Retain` policy, and the claim binds it by name.
|
||||
The prune unit stops a pod before the container starts, and the Deployment
|
||||
replaces its pod rather than running two, so one server reads the directory
|
||||
at a time.
|
||||
nats-server keeps no lock or identity file in the store, so nothing there ties
|
||||
the directory to the side that wrote it.
|
||||
The module makes the directory on a host that never ran the container,
|
||||
because the volume needs it before the pod starts.
|
||||
The claim and its volume stay after a switch back, as every claim does, with
|
||||
the directory.
|
||||
- **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
|
||||
|
|
@ -293,6 +311,8 @@ holds the container back until the pod has gone.
|
|||
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.
|
||||
Core NATS messages published while no server is up never arrive, and JetStream
|
||||
publishes fail at the publisher.
|
||||
- **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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue