remove swarmctl migrate, migrate.json and the migrate docs
This commit is contained in:
parent
58e59be65e
commit
f89d289a9f
9 changed files with 25 additions and 1398 deletions
|
|
@ -40,8 +40,6 @@ This document contains the help content for the `swarmctl` command-line program.
|
||||||
* [`swarmctl bao`↴](#swarmctl-bao)
|
* [`swarmctl bao`↴](#swarmctl-bao)
|
||||||
* [`swarmctl bao init`↴](#swarmctl-bao-init)
|
* [`swarmctl bao init`↴](#swarmctl-bao-init)
|
||||||
* [`swarmctl bao grant-bootstrap`↴](#swarmctl-bao-grant-bootstrap)
|
* [`swarmctl bao grant-bootstrap`↴](#swarmctl-bao-grant-bootstrap)
|
||||||
* [`swarmctl migrate`↴](#swarmctl-migrate)
|
|
||||||
* [`swarmctl migrate status`↴](#swarmctl-migrate-status)
|
|
||||||
* [`swarmctl login`↴](#swarmctl-login)
|
* [`swarmctl login`↴](#swarmctl-login)
|
||||||
* [`swarmctl completions`↴](#swarmctl-completions)
|
* [`swarmctl completions`↴](#swarmctl-completions)
|
||||||
|
|
||||||
|
|
@ -59,7 +57,6 @@ swarm-level operator CLI
|
||||||
* `forge` — Manage human accounts on the swarm's forge
|
* `forge` — Manage human accounts on the swarm's forge
|
||||||
* `setup` — Walk through the first-run setup, interactively
|
* `setup` — Walk through the first-run setup, interactively
|
||||||
* `bao` — Initialise the swarm's secret store and bootstrap its granter
|
* `bao` — Initialise the swarm's secret store and bootstrap its granter
|
||||||
* `migrate` — Move the swarm's services from this host onto its k3s cluster
|
|
||||||
* `login` — Log in to the swarm named by `--swarm` as your own SSO account
|
* `login` — Log in to the swarm named by `--swarm` as your own SSO account
|
||||||
* `completions` — Generate a shell completion script for `swarmctl` and print it to stdout
|
* `completions` — Generate a shell completion script for `swarmctl` and print it to stdout
|
||||||
|
|
||||||
|
|
@ -739,37 +736,6 @@ Reads the root token from a hidden prompt, or from stdin when stdin isn't a term
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## `swarmctl migrate`
|
|
||||||
|
|
||||||
Move the swarm's services from this host onto its k3s cluster.
|
|
||||||
|
|
||||||
`docs/4-implementation/k8s/migrate.md` describes the move. Only `status` exists yet, and it moves nothing and creates no pod.
|
|
||||||
|
|
||||||
**Usage:** `swarmctl migrate
|
|
||||||
migrate <COMMAND>`
|
|
||||||
|
|
||||||
###### **Subcommands:**
|
|
||||||
|
|
||||||
* `status` — Report where each service stands: its runtime, its host units and its pod, and which step comes next
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## `swarmctl migrate status`
|
|
||||||
|
|
||||||
Report where each service stands: its runtime, its host units and its pod, and which step comes next.
|
|
||||||
|
|
||||||
Read-only: it creates no pod and changes nothing. Run it as root; it reads `/etc/hyperhive/migrate.json`, asks systemd about the host units and lists the pods in the swarm's namespace with the k3s admin kubeconfig.
|
|
||||||
|
|
||||||
Exits 0 when every check ran, whatever the answers, and 1 when a check failed to run. A script reads the report from `--json`.
|
|
||||||
|
|
||||||
**Usage:** `swarmctl migrate status [OPTIONS]`
|
|
||||||
|
|
||||||
###### **Options:**
|
|
||||||
|
|
||||||
* `--json` — Print the report as JSON: the services as the module renders them, one entry per step with its status, and the next step
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## `swarmctl login`
|
## `swarmctl login`
|
||||||
|
|
||||||
Log in to the swarm named by `--swarm` as your own SSO account.
|
Log in to the swarm named by `--swarm` as your own SSO account.
|
||||||
|
|
|
||||||
|
|
@ -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
|
its systemd unit, and nothing applies the services' manifests: two copies of
|
||||||
`swarm-notify-router`, `swarm-ci-metrics` or `swarm-controller` would share one
|
`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
|
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
|
cluster when its `runtime` is `"k8s"` ([the runtime switch](runtime.md)).
|
||||||
[`swarmctl migrate status`](migrate.md) reports).
|
|
||||||
|
|
||||||
With the option off, the host's configuration is the one it has without the
|
With the option off, the host's configuration is the one it has without the
|
||||||
module.
|
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
|
(`swarm-nats`) have the option today, and the other services that run in the
|
||||||
cluster follow the same pattern.
|
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
|
## Options
|
||||||
|
|
||||||
- `services.hyperhive.deploy.notify-router.runtime` (default `"host"`).
|
- `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
|
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
|
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 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
|
The volume is `local`, pinned to the node, with a storage class of its own
|
||||||
and its volume stay after a switch back, as every claim does, with the
|
and the `Retain` policy, and the claim binds it by name.
|
||||||
directory.
|
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
|
- **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
|
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
|
`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
|
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
|
15-second grace period, so every client's connection drops at once and the
|
||||||
clients reconnect when the next pod is up.
|
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
|
- **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
|
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.
|
sets. The VM test checks the runtime's is at least that.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
# Kubernetes manifests for the swarm services this host deploys, rendered by
|
# Kubernetes manifests for the swarm services this host deploys, rendered by
|
||||||
# ./render.nix from their systemd units, and the per-service switch that moves
|
# ./render.nix from their systemd units, and the per-service switch that moves
|
||||||
# a service between its host unit and the cluster (./runtime.nix), and what
|
# a service between its host unit and the cluster (./runtime.nix). Rendering
|
||||||
# `swarmctl migrate` reads of both (./migrate.nix). Rendering
|
|
||||||
# alone changes no unit and applies nothing. docs/4-implementation/k8s/manifests.md
|
# alone changes no unit and applies nothing. docs/4-implementation/k8s/manifests.md
|
||||||
# and runtime.md have the design.
|
# and runtime.md have the design.
|
||||||
{
|
{
|
||||||
|
|
@ -25,7 +24,6 @@ in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./host-services.nix
|
./host-services.nix
|
||||||
./migrate.nix
|
|
||||||
./node.nix
|
./node.nix
|
||||||
./pod-logs.nix
|
./pod-logs.nix
|
||||||
./runtime.nix
|
./runtime.nix
|
||||||
|
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
# What `swarmctl migrate` reads of this host: `/etc/hyperhive/migrate.json`, and
|
|
||||||
# the environment that tells `swarmctl` which `kubectl` and kubeconfig to use.
|
|
||||||
# Imported by ./default.nix. docs/4-implementation/k8s/migrate.md has the design.
|
|
||||||
#
|
|
||||||
# The file has one entry per service that has a `runtime` option: the
|
|
||||||
# option's path, the runtime the configuration wants, the host units that run
|
|
||||||
# the service when it is on the host. The file and the wrapper exist only on a
|
|
||||||
# host with the node (./node.nix): without a cluster there is nothing to read.
|
|
||||||
{
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
config,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
let
|
|
||||||
cfg = config.services.hyperhive.k8s;
|
|
||||||
deployCfg = config.services.hyperhive.deploy;
|
|
||||||
node = deployCfg.k8s;
|
|
||||||
controllerCfg = deployCfg.swarm-controller;
|
|
||||||
|
|
||||||
# Each service's name under `services.hyperhive.deploy`.
|
|
||||||
optionOf = {
|
|
||||||
swarm-controller = "swarm-controller";
|
|
||||||
swarm-nats = "nats";
|
|
||||||
swarm-notify-router = "notify-router";
|
|
||||||
swarm-stt = "stt";
|
|
||||||
swarm-review-classifier = "review-classifier";
|
|
||||||
swarm-claude-login = "claude-login";
|
|
||||||
swarm-ci-metrics = "ci-metrics";
|
|
||||||
};
|
|
||||||
|
|
||||||
entry = name: switch: {
|
|
||||||
option = "services.hyperhive.deploy.${optionOf.${name}}.runtime";
|
|
||||||
inherit (switch) runtime;
|
|
||||||
hostUnits = lib.toList switch.hostUnit;
|
|
||||||
};
|
|
||||||
|
|
||||||
migrateJson = {
|
|
||||||
inherit (cfg) namespace;
|
|
||||||
services = lib.mapAttrs entry cfg.rendered.switches;
|
|
||||||
};
|
|
||||||
|
|
||||||
# The `swarmctl` wrapper's variables. The same `kubectl` that ./runtime.nix
|
|
||||||
# runs, with the cluster's admin kubeconfig.
|
|
||||||
kubeEnv = {
|
|
||||||
SWARMCTL_KUBECTL = "${pkgs.kubectl}/bin/kubectl";
|
|
||||||
SWARMCTL_KUBECONFIG = "/etc/rancher/k3s/k3s.yaml";
|
|
||||||
};
|
|
||||||
|
|
||||||
# `swarmctl` where the controller's module does not install one.
|
|
||||||
swarmctlKube = pkgs.symlinkJoin {
|
|
||||||
name = "swarmctl-kube";
|
|
||||||
paths = [ deployCfg.swarm-controller.swarmctlPackage ];
|
|
||||||
nativeBuildInputs = [ pkgs.makeWrapper ];
|
|
||||||
postBuild = ''
|
|
||||||
wrapProgram $out/bin/swarmctl ${
|
|
||||||
lib.concatStringsSep " " (
|
|
||||||
lib.mapAttrsToList (name: value: "--set ${name} ${lib.escapeShellArg value}") kubeEnv
|
|
||||||
)
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
|
||||||
config = lib.mkIf (node.enable && cfg.enable) {
|
|
||||||
environment.etc."hyperhive/migrate.json".text = builtins.toJSON migrateJson;
|
|
||||||
|
|
||||||
# The controller module's wrapper carries these where the controller is
|
|
||||||
# enabled, which it stays at `runtime = "k8s"`.
|
|
||||||
services.hyperhive.deploy.swarm-controller.swarmctlEnvironment = kubeEnv;
|
|
||||||
environment.systemPackages = lib.mkIf (!controllerCfg.enable) [ swarmctlKube ];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -247,7 +247,6 @@ let
|
||||||
&& usesSecret { projected.sources = [ { secret.name = "x"; } ]; }
|
&& usesSecret { projected.sources = [ { secret.name = "x"; } ]; }
|
||||||
&& !(usesSecret { projected.sources = [ { configMap.name = "x"; } ]; });
|
&& !(usesSecret { projected.sources = [ { configMap.name = "x"; } ]; });
|
||||||
|
|
||||||
migrateOf = c: builtins.fromJSON c.environment.etc."hyperhive/migrate.json".text;
|
|
||||||
routerUnit = c: c.services.hyperhive.deploy.notify-router.unit;
|
routerUnit = c: c.services.hyperhive.deploy.notify-router.unit;
|
||||||
manifestNames = c: lib.sort lib.lessThan (lib.attrNames c.services.k3s.manifests);
|
manifestNames = c: lib.sort lib.lessThan (lib.attrNames c.services.k3s.manifests);
|
||||||
routerPrune = withNode.systemd.services.swarm-notify-router-k8s-prune;
|
routerPrune = withNode.systemd.services.swarm-notify-router-k8s-prune;
|
||||||
|
|
@ -2182,63 +2181,6 @@ let
|
||||||
&& problems withCaps != [ ]
|
&& problems withCaps != [ ]
|
||||||
&& problems withoutSeccomp != [ ];
|
&& problems withoutSeccomp != [ ];
|
||||||
}
|
}
|
||||||
{
|
|
||||||
# The file names the runtime and the host units of every service and no
|
|
||||||
# state: nothing is copied. The units of the poller (timer and service)
|
|
||||||
# are the control for a list of more than one.
|
|
||||||
name = "migrate.json names every service with its option, host units and the runtime the configuration wants, and no state";
|
|
||||||
ok =
|
|
||||||
let
|
|
||||||
host = (migrateOf withNode).services;
|
|
||||||
cluster = (migrateOf onCluster).services;
|
|
||||||
in
|
|
||||||
(migrateOf withNode).namespace == "hyperhive"
|
|
||||||
&&
|
|
||||||
lib.sort lib.lessThan (lib.attrNames host) == [
|
|
||||||
"swarm-ci-metrics"
|
|
||||||
"swarm-claude-login"
|
|
||||||
"swarm-controller"
|
|
||||||
"swarm-nats"
|
|
||||||
"swarm-notify-router"
|
|
||||||
"swarm-review-classifier"
|
|
||||||
"swarm-stt"
|
|
||||||
]
|
|
||||||
&& lib.all (s: !(s ? state)) (lib.attrValues host)
|
|
||||||
&& lib.all (n: lib.hasPrefix "services.hyperhive.deploy." host.${n}.option) (lib.attrNames host)
|
|
||||||
&&
|
|
||||||
host.swarm-ci-metrics.hostUnits == [
|
|
||||||
"swarm-ci-metrics.timer"
|
|
||||||
"swarm-ci-metrics.service"
|
|
||||||
]
|
|
||||||
&& host.swarm-nats.hostUnits == [ "container@swarm-nats.service" ]
|
|
||||||
&& host.swarm-ci-metrics.option == "services.hyperhive.deploy.ci-metrics.runtime"
|
|
||||||
&& lib.all (s: s.runtime == "host") (lib.attrValues host)
|
|
||||||
# The runtime follows the option: the cluster fixture has every one on k8s.
|
|
||||||
&& lib.all (s: s.runtime == "k8s") (lib.attrValues cluster);
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "swarmctl is wrapped with kubectl and the cluster's kubeconfig, by one wrapper per host";
|
|
||||||
ok =
|
|
||||||
let
|
|
||||||
env = c: c.services.hyperhive.deploy.swarm-controller.swarmctlEnvironment;
|
|
||||||
wrappers =
|
|
||||||
c:
|
|
||||||
map lib.getName (
|
|
||||||
lib.filter (p: lib.hasPrefix "swarmctl-" (lib.getName p)) c.environment.systemPackages
|
|
||||||
);
|
|
||||||
in
|
|
||||||
(env withNode).SWARMCTL_KUBECTL == "${pkgs.kubectl}/bin/kubectl"
|
|
||||||
&& (env withNode).SWARMCTL_KUBECONFIG == "/etc/rancher/k3s/k3s.yaml"
|
|
||||||
# The controller's own wrapper carries them where the controller is
|
|
||||||
# enabled; elsewhere the k8s module installs one.
|
|
||||||
&& wrappers withNode == [ "swarmctl-configured" ]
|
|
||||||
&& wrappers nodeNoBridge == [ "swarmctl-kube" ]
|
|
||||||
# Without the node there is no cluster to name, though the manifests render.
|
|
||||||
&& allLocal.services.hyperhive.k8s.enable
|
|
||||||
&& !(env allLocal ? SWARMCTL_KUBECTL)
|
|
||||||
&& !(allLocal.environment.etc ? "hyperhive/migrate.json")
|
|
||||||
&& wrappers allLocal == [ "swarmctl-configured" ];
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
runGroup "k8s" cases
|
runGroup "k8s" cases
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ mod forge;
|
||||||
mod inference;
|
mod inference;
|
||||||
mod interactive;
|
mod interactive;
|
||||||
mod login;
|
mod login;
|
||||||
mod migrate;
|
|
||||||
mod permissions;
|
mod permissions;
|
||||||
mod remote;
|
mod remote;
|
||||||
mod schedule;
|
mod schedule;
|
||||||
|
|
@ -257,11 +256,6 @@ enum Verb {
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: BaoVerb,
|
command: BaoVerb,
|
||||||
},
|
},
|
||||||
/// Move the swarm's services from this host onto its k3s cluster.
|
|
||||||
///
|
|
||||||
/// `docs/4-implementation/k8s/migrate.md` describes the move. Only
|
|
||||||
/// `status` exists yet, and it moves nothing and creates no pod.
|
|
||||||
Migrate(migrate::MigrateArgs),
|
|
||||||
/// Log in to the swarm named by `--swarm` as your own SSO account.
|
/// Log in to the swarm named by `--swarm` as your own SSO account.
|
||||||
///
|
///
|
||||||
/// With no `--swarm` or `SWARMCTL_SWARM`, logs in to
|
/// With no `--swarm` or `SWARMCTL_SWARM`, logs in to
|
||||||
|
|
@ -890,7 +884,6 @@ fn main() -> Result<()> {
|
||||||
command: BaoVerb::GrantBootstrap(args),
|
command: BaoVerb::GrantBootstrap(args),
|
||||||
} => bao::grant_bootstrap(args),
|
} => bao::grant_bootstrap(args),
|
||||||
// Needs none of the `SWARMCTL_AUTHELIA_*` values: it reads the cluster and systemd.
|
// Needs none of the `SWARMCTL_AUTHELIA_*` values: it reads the cluster and systemd.
|
||||||
Verb::Migrate(args) => migrate::run(args),
|
|
||||||
// Same socket-resolution reasoning as `Create` above.
|
// Same socket-resolution reasoning as `Create` above.
|
||||||
Verb::Schedule { command } => schedule(&remote, command),
|
Verb::Schedule { command } => schedule(&remote, command),
|
||||||
Verb::Setup(args) => setup_verb(paths, &remote, args),
|
Verb::Setup(args) => setup_verb(paths, &remote, args),
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue