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 mara
commit 79c06cdcb0

View file

@ -364,6 +364,11 @@ pkgs.testers.runNixOSTest {
NODE = "${nodeIp}"
BRIDGE = "${bridgeIp}"
CONTROL = ${toString controlPort}
STATE_LABEL = "hyperhive.darkest.space/state-nats"
ENTRY_LABELS = {
"hyperhive.darkest.space/entry": "true",
"svccontroller.k3s.cattle.io/enablelb": "true",
}
MANIFESTS = "/var/lib/rancher/k3s/server/manifests"
SERVICES_ROOT = "${tlsDir}/swarm-services-root.pem"
TOKEN = "${routerToken}"
@ -447,6 +452,10 @@ pkgs.testers.runNixOSTest {
return name
def node_labels() -> dict:
return json.loads(kube(machine, "get node -o json"))["items"][0]["metadata"]["labels"]
def switch(target: str) -> str:
"""Switches to `target`. Units of this host that fail for reasons of
their own make the exit status 4; the units the switch is about must
@ -609,6 +618,14 @@ pkgs.testers.runNixOSTest {
assert int(machine.succeed(f"find {HOST_STORE} -type f | wc -l")) > 0
assert machine.succeed(f"find {HOST_STORE} ! -uid {HOST_UID} | wc -l").strip() == "0"
# The node registers with the entry labels only. The switch is the upgrade of
# a node that registered before the queue was in the cluster: it gets the
# state label at the restart of k3s, and the volume and the pod select on it.
with subtest("the node registered with the entry labels and no state label while the queue runs in its container"):
labels = node_labels()
assert all(labels.get(k) == v for k, v in ENTRY_LABELS.items()), labels
assert STATE_LABEL not in labels, labels
with subtest("the switch to the cluster stops the container before it applies the pod"):
out = switch("/run/booted-system/specialisation/k8s")
assert HOST_UNIT in out and "stopping the following units" in out, out
@ -654,6 +671,38 @@ pkgs.testers.runNixOSTest {
print(limits)
assert int(limits.split()[3]) >= 800000, limits
with subtest("the switch gave the registered node the state label, and the volume and the pod select on it"):
labels = node_labels()
assert labels.get(STATE_LABEL) == "true", labels
assert all(labels.get(k) == v for k, v in ENTRY_LABELS.items()), labels
volume = json.loads(kube(machine, f"get pv {SERVICE}-store -o json"))
assert volume["status"]["phase"] == "Bound", volume["status"]
assert volume["spec"]["claimRef"]["name"] == f"{SERVICE}-store", volume["spec"]
assert volume["spec"]["nodeAffinity"]["required"]["nodeSelectorTerms"] == [
{"matchExpressions": [{"key": STATE_LABEL, "operator": "In", "values": ["true"]}]}
], volume["spec"]
assert pod(machine, pod_name)["spec"]["nodeSelector"] == {STATE_LABEL: "true"}, pod(machine, pod_name)["spec"]
assert "kubernetes.io/hostname" not in json.dumps(volume["spec"]), volume["spec"]
with subtest("a node without the state label cannot run the pod, and the pod starts when the label returns"):
node = machine.succeed("kubectl get node -o name").strip()
old_uid = pod(machine, pod_name)["metadata"]["uid"]
kube(machine, f"label {node} {STATE_LABEL}-")
assert STATE_LABEL not in node_labels()
kube(machine, f"delete pod {pod_name} --wait=true --timeout=120s", 150)
unscheduled = (
f"kubectl -n {NS} get pods --selector app.kubernetes.io/name={SERVICE} -o json "
"| jq -r '.items[].status.conditions[]? | select(.type == \"PodScheduled\" and .status == \"False\") | .message'"
)
machine.wait_until_succeeds(f"{unscheduled} | grep -q .", timeout=120)
message = machine.succeed(unscheduled)
assert "node affinity" in message, message
assert pods() != [] and counts()[0] == 0, (pods(), counts())
kube(machine, f"label {node} {STATE_LABEL}=true")
pod_name = wait_pod_ready(old_uid)
assert node_labels().get(STATE_LABEL) == "true"
assert counts() == (1, 1), counts()
with subtest("the exporter is a ClusterIP Service, and the pod's policy admits the client port from any source and nothing else"):
svc = json.loads(kube(machine, f"get service {METRICS_SERVICE} -o json"))
assert svc["spec"]["type"] == "ClusterIP", svc["spec"]
@ -801,6 +850,9 @@ pkgs.testers.runNixOSTest {
assert 0 < pruned <= started, (pruned, started)
requires = machine.succeed(f"systemctl show -p Requires --value {HOST_UNIT}")
assert f"{PRUNE}.service" in requires, requires
# k3s adds labels and never takes one off: the label stays and does
# nothing while the container runs.
assert node_labels().get(STATE_LABEL) == "true", node_labels()
# The volume is kept for the next switch.
assert json.loads(kube(machine, f"get pvc {SERVICE}-store -o json"))["metadata"]["uid"] == STATE_VOLUME
settle(QUEUE_UP, 600, [HOST_UNIT])