From f658b2c77005ab0e3482ac1746ab1f121d5e6870 Mon Sep 17 00:00:00 2001 From: maia Date: Tue, 24 Nov 2026 08:49:21 +0100 Subject: [PATCH] swarm-nats: order the host queue's callout-key unit after the prune A switch back deletes the queue's pod with --wait, so the pod is still ending while swarm-nats-k8s-prune runs. swarm-bao-nats-callout-xkey was ordered before the container but not after the prune, so on a slow apiserver its ensure-callout-keys ran beside the pod's responder and the switch test saw two responders. On a host with the cluster node the unit now starts after the prune. The prune names the unit nowhere, so there is no cycle, and without the node nothing changes. Closes #6831 --- nix/host-modules/swarm-nats.nix | 6 ++++++ nix/module-eval/k8s.nix | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/nix/host-modules/swarm-nats.nix b/nix/host-modules/swarm-nats.nix index 44d2abac8..e4507f2d2 100644 --- a/nix/host-modules/swarm-nats.nix +++ b/nix/host-modules/swarm-nats.nix @@ -1769,6 +1769,12 @@ in # (./glue-bao-readers-store-order.nix); elsewhere the timeout below # bounds the attempt. before = [ "container@${machine}.service" ]; + # On a host with the cluster node, also after the prune that deletes the + # queue's pod on a switch back. The prune waits for the pod to end, and + # `ensure-callout-keys` must not run beside a pod still terminating: its + # responder is a second one against the same store. The prune names + # this unit nowhere, so the order has no cycle. + after = lib.optional deployCfg.k8s.enable "${machine}-k8s-prune.service"; wantedBy = [ "multi-user.target" "container@${machine}.service" diff --git a/nix/module-eval/k8s.nix b/nix/module-eval/k8s.nix index d229b0e52..9ea54196e 100644 --- a/nix/module-eval/k8s.nix +++ b/nix/module-eval/k8s.nix @@ -1910,6 +1910,23 @@ let && (u onCluster).environment == (u withNode).environment && (u onCluster).serviceConfig.LoadCredential == (u withNode).serviceConfig.LoadCredential; } + { + # A switch back deletes the queue's pod with `--wait`, so the pod is + # still ending while the prune runs. The host copy's key step must wait + # for the prune, or it runs beside the pod's responder; and the prune must + # not name the key unit, which would be a cycle. Without the node there is + # no prune, so nothing orders the key unit after one. + name = "the host queue's callout-key unit starts after the prune that waits for the queue's pod, and the prune does not name it"; + ok = + let + xkey = withNode.systemd.services.swarm-bao-nats-callout-xkey; + prune = withNode.systemd.services.swarm-nats-k8s-prune; + names = u: u.after ++ u.before ++ u.requires ++ u.wants ++ u.requiredBy ++ u.wantedBy; + in + lib.elem "swarm-nats-k8s-prune.service" xkey.after + && !(lib.elem "swarm-bao-nats-callout-xkey.service" (names prune)) + && !(lib.elem "swarm-nats-k8s-prune.service" allLocal.systemd.services.swarm-bao-nats-callout-xkey.after); + } { # The host with the queue on it is the control for each absence: it has # the container, both delivery units and no rule in the raw table.