Watch
0
0
Fork
You've already forked hyperhive
0

pin queue and poller state to per-service node labels instead of the hostname

This commit is contained in:
atlas 2026-11-25 21:48:02 +01:00 • committed by maia
commit ff2bdea78d
4 changed files with 348 additions and 40 deletions

View file

@ -27,7 +27,7 @@ A service gets manifests on the host whose configuration deploys it:
| `swarm-stt` | Deployment | ServiceAccount, NetworkPolicy `swarm-stt` |
| `swarm-review-classifier` | Deployment | ServiceAccount |
| `swarm-claude-login` | Deployment | ServiceAccount |
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolumeClaim `swarm-ci-metrics-state` |
| `swarm-ci-metrics` | CronJob | ServiceAccount, PersistentVolume and Claim |
`namespace.yaml` holds the Namespace ([Pod Security](#pod-security)).

View file

@ -47,6 +47,44 @@ 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.
## Node labels
A service whose data sits on one node's disk runs on that node, and the node
says so with a label. The module sets the labels
(`services.hyperhive.deploy.k8s.nodeLabels`, passed to `services.k3s.nodeLabel`):
- `hyperhive.darkest.space/state-<service>=true`, one per service whose data
the cluster keeps. Today that's `nats`, when `deploy.nats.runtime` is
`"k8s"`, and `ci-metrics`, when `deploy.ci-metrics.runtime` is `"k8s"`. The
service's static local volume has a `nodeAffinity` on the label, and its pod a
`nodeSelector` on it, so a node without the label can't run the pod and shows
as no match instead of a volume that can't bind. One label per service, so
moving one service's data moves one label.
- `hyperhive.darkest.space/entry=true`, on the node the hosts' DNS points at.
Nothing selects on it yet. The pods that hosts dial will, as they move in.
- `svccontroller.k3s.cattle.io/enablelb=true`. With this label on any node, k3s's
service load balancer binds a published port on the labelled nodes only
(k3s documents it under "Controlling servicelb node selection"). Without it, a
node that joins would also bind the queue's port 4222.
On the single node, every label is on the node and the pods are the ones the
node ran without them, plus a `nodeSelector`. **A node that joins carries
none of the labels**, so it can't run a pod that keeps data on a disk, and
the load balancer doesn't bind the queue's port on it. A stateless pod can run
there.
k3s applies `--node-label` to the node's object at every start, whether the
node registered before or not, so a node that registered before a label existed
has the label after the restart a switch causes. A pod that selects on a label
the node doesn't have yet waits as Pending and starts when the label arrives.
k3s only adds labels. A label the module no longer sets, such as `state-nats`
after the queue moves back to `"host"`, stays on the node and does nothing,
because no pod selects on it. `kubectl label node <name> <label>-` removes it.
Moving a service's data to another node is manual: copy the directory, put the
label on the new node, take it off the old one. Moving it with a command
belongs to a later version.
## Reaching host-run services
A pod reaches a service that runs on the host by the service's swarm name. The

View file

@ -136,13 +136,22 @@ transcribes a memo that only the other side cached. The whisper model isn't
state: the pod's image holds it, from the same store path the container reads.
`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.
already pushed. On the host it sits in the service's state directory,
`/var/lib/private/swarm-ci-metrics`. In the cluster it sits in the
PersistentVolumeClaim `swarm-ci-metrics-store`, mounted at the same path, which
binds a static local volume on that host directory. A switch moves the process
and not the cursor. The volume's `nodeAffinity` and the pod's `nodeSelector`
both name the node label `hyperhive.darkest.space/state-ci-metrics`
([node labels](node.md#node-labels)). The module makes the directory on a host
that never ran the service, because the volume needs it before the first Job.
The claim and its volume stay after a switch back, with the directory.
A host that ran the poller in the cluster before the volume was static has the
claim `swarm-ci-metrics-state` on the cluster's default class. A bound claim's
class can't change, so the poller uses a new claim and the old one stays,
unused, until the operator deletes it. The first Job after the upgrade finds
the host directory's cursor, or none, and pushes every run again as the same
points.
## The controller
@ -291,8 +300,11 @@ 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 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 volume is `local`, with a storage class of its own and the `Retain`
policy, and the claim binds it by name. Its `nodeAffinity` and the pod's
`nodeSelector` both name the node label
`hyperhive.darkest.space/state-nats`, so the pod and the directory stay on the
node that carries it ([node labels](node.md#node-labels)).
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.

View file

@ -42,9 +42,10 @@ three places:
- Its one credential file is the store's CA, from the `hyperhive-ca-trust`
ConfigMap.
The cursor is in a volume of the cluster, `swarm-ci-metrics-state`. A switch
copies no cursor, so the first pass on a side that has none pushes every run
again, which changes no panel, as after a crash.
The cursor is in a volume of the cluster, `swarm-ci-metrics-store`, on the
host directory the service's own unit keeps it in. A switch moves the process
and not the cursor. [The runtime page](../k8s/runtime.md#state) has the volume
and the label that pins the Job to its node.
## What it reads, and as whom