From 02e0aab3b65a15ed535e7e5b7beac3fd42b72841 Mon Sep 17 00:00:00 2001 From: maia Date: Thu, 26 Nov 2026 21:17:30 +0100 Subject: [PATCH] k8s: refuse a workload name that starts with the legacy hive- prefix The forge and matrix services carry a hive- prefix from their per-hive container days. Neither runs in the cluster on k8s/v1 yet, so nothing is renamed here: the renderer now fails the evaluation of any in-cluster workload that carries a name starting with hive- (an object key, an object's name, or its app label), so the move cannot bring the prefix along. A module-eval case pins the lookup on literals and holds the rendered hosts to it. --- nix/host-modules/k8s/render.nix | 23 +++++++++++++++++++++-- nix/module-eval/k8s.nix | 25 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/nix/host-modules/k8s/render.nix b/nix/host-modules/k8s/render.nix index 0a0e6ecbc..35c0c662e 100644 --- a/nix/host-modules/k8s/render.nix +++ b/nix/host-modules/k8s/render.nix @@ -320,6 +320,23 @@ let fail = name: msg: throw "services.hyperhive.k8s: ${name}: ${msg}"; + # The names an object set carries that start with `hive-`, the prefix the + # forge and matrix services had as per-hive containers. Their workloads, and + # so their pods, must not bring it into the cluster. Read from the object + # keys, each object's name and its app label. + legacyPrefixed = + objs: + lib.filter (lib.hasPrefix "hive-") ( + lib.attrNames objs + ++ lib.concatMap ( + o: + [ o.metadata.name ] + ++ lib.optional ( + o.metadata.labels."app.kubernetes.io/name" or null != null + ) o.metadata.labels."app.kubernetes.io/name" + ) (lib.attrValues objs) + ); + # A unit's `ExecStart` as argv, split as systemd splits it: on spaces, with # single quotes grouping a word (`lib.escapeShellArg` writes them) and `$$` # standing for `$`. A pod's arguments are not expanded by a shell. @@ -1125,7 +1142,9 @@ let }; }; in - if !(lib.all (p: lib.elem (lib.getName p) nixosDefaultPath) unit.path) then + if legacyPrefixed objects != [ ] then + fail name "names ${lib.concatStringsSep ", " (lib.unique (legacyPrefixed objects))}, which start with the legacy `hive-` prefix" + else if !(lib.all (p: lib.elem (lib.getName p) nixosDefaultPath) unit.path) then fail name "the unit puts packages on PATH, which the image does not carry" else if svc.otlp == "own" && !(lib.any (n: unitEnv ? ${n}) otlpEndpointVars) then fail name "the unit names no OTLP endpoint of its own, which the pod would push to" @@ -1187,5 +1206,5 @@ in lib.filterAttrs (_: svc: svc.enable && svc ? hostUsers && !svc.hostUsers) services ); services = lib.mapAttrs (_: w: { inherit (w) objects; }) enabled; - inherit caConfigMap caSources; + inherit caConfigMap caSources legacyPrefixed; } diff --git a/nix/module-eval/k8s.nix b/nix/module-eval/k8s.nix index 2fd5d5bda..e73263836 100644 --- a/nix/module-eval/k8s.nix +++ b/nix/module-eval/k8s.nix @@ -2330,6 +2330,31 @@ let && !(hasInfix "\"imagePullPolicy\":\"Never\"" clusterText) && !(hasInfix "docker.io" clusterText); } + { + # The literals are the controls that the lookup sees each place a name is + # written (an object key, a name, the app label) and lets `swarm-` and an + # inner `hive-` through. The hosts hold many objects, so the empty result + # is not an empty input. + name = "no workload, Service, volume claim or label in the cluster starts with the legacy hive- prefix"; + ok = + let + legacy = + (import ../host-modules/k8s/render.nix { + inherit lib pkgs; + config = onCluster; + }).legacyPrefixed; + obj = name: labels: { metadata = { inherit name labels; }; }; + named = n: l: legacy { x = obj n l; }; + in + legacy { "hive-forge/deployment" = obj "x" { }; } == [ "hive-forge/deployment" ] + && named "hive-matrix" { } == [ "hive-matrix" ] + && named "x" { "app.kubernetes.io/name" = "hive-forge"; } == [ "hive-forge" ] + && named "swarm-hive-forge" { "app.kubernetes.io/name" = "swarm-x"; } == [ ] + && lib.length (lib.attrNames objects) >= 15 + && lib.length (lib.attrNames (render onCluster)) >= 30 + && legacy objects == [ ] + && legacy (render onCluster) == [ ]; + } ]; in runGroup "k8s" cases