Watch
0
0
Fork
You've already forked hyperhive
0

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.
This commit is contained in:
maia 2026-11-26 21:17:30 +01:00
commit 02e0aab3b6
2 changed files with 46 additions and 2 deletions

View file

@ -320,6 +320,23 @@ let
fail = name: msg: throw "services.hyperhive.k8s: ${name}: ${msg}"; 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 # A unit's `ExecStart` as argv, split as systemd splits it: on spaces, with
# single quotes grouping a word (`lib.escapeShellArg` writes them) and `$$` # single quotes grouping a word (`lib.escapeShellArg` writes them) and `$$`
# standing for `$`. A pod's arguments are not expanded by a shell. # standing for `$`. A pod's arguments are not expanded by a shell.
@ -1125,7 +1142,9 @@ let
}; };
}; };
in 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" 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 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" 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 lib.filterAttrs (_: svc: svc.enable && svc ? hostUsers && !svc.hostUsers) services
); );
services = lib.mapAttrs (_: w: { inherit (w) objects; }) enabled; services = lib.mapAttrs (_: w: { inherit (w) objects; }) enabled;
inherit caConfigMap caSources; inherit caConfigMap caSources legacyPrefixed;
} }

View file

@ -2330,6 +2330,31 @@ let
&& !(hasInfix "\"imagePullPolicy\":\"Never\"" clusterText) && !(hasInfix "\"imagePullPolicy\":\"Never\"" clusterText)
&& !(hasInfix "docker.io" 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 in
runGroup "k8s" cases runGroup "k8s" cases