From 89308e8ba57b7f633f69f7bc990ed0743ee3c308 Mon Sep 17 00:00:00 2001 From: atlas Date: Wed, 25 Nov 2026 21:48:02 +0100 Subject: [PATCH] pin queue and poller state to per-service node labels instead of the hostname --- docs/4-implementation/k8s/manifests.md | 2 +- docs/4-implementation/k8s/node.md | 38 ++++++++++ docs/4-implementation/k8s/runtime.md | 30 +++++--- docs/4-implementation/swarm/ci-metrics.md | 7 +- nix/host-modules/k8s/labels.nix | 36 ++++++++++ nix/host-modules/k8s/node.nix | 41 +++++++++++ nix/host-modules/k8s/render.nix | 39 ++++++++-- nix/host-modules/swarm-ci-metrics.nix | 32 +++++++-- nix/host-modules/swarm-nats.nix | 24 +++---- nix/module-eval/k8s.nix | 87 +++++++++++++++++++++-- nix/vm-tests/k8s-nats-switch.nix | 52 ++++++++++++++ 11 files changed, 348 insertions(+), 40 deletions(-) create mode 100644 nix/host-modules/k8s/labels.nix diff --git a/docs/4-implementation/k8s/manifests.md b/docs/4-implementation/k8s/manifests.md index 634f23a10..70f4c0f09 100644 --- a/docs/4-implementation/k8s/manifests.md +++ b/docs/4-implementation/k8s/manifests.md @@ -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)). diff --git a/docs/4-implementation/k8s/node.md b/docs/4-implementation/k8s/node.md index 74844ab8b..88b3fb98d 100644 --- a/docs/4-implementation/k8s/node.md +++ b/docs/4-implementation/k8s/node.md @@ -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-=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