Watch
0
0
Fork
You've already forked hyperhive
0

k8s: deploy.notify-router.runtime moves the router between its container and the cluster

This commit is contained in:
atlas 2026-11-21 15:16:32 +01:00 • committed by mara
commit 50dc13d61b

View file

@ -39,7 +39,7 @@ let
# The all-local host with the node on. It does not set
# `services.hyperhive.k8s.enable`: the node turns the rendering on.
withNode = hiveWithController {
nodeSettings = {
deploy.singleHostSwarm = true;
deploy.k8s.enable = true;
deploy.victorialogs.authPackage = marker "logs";
@ -47,6 +47,18 @@ let
deploy.victoriametrics.authPackage = marker "metrics";
deploy.victoriametrics.agentAuthPackage = marker "metrics-agent";
};
withNode = hiveWithController nodeSettings;
# The same host with the router in the cluster, so it has no container. A
# second full host, because the claim is about what the configuration
# drops; the other cases of this group read `withNode`.
onCluster = hiveWithController (
lib.recursiveUpdate nodeSettings { deploy.notify-router.runtime = "k8s"; }
);
# A host that asks for the cluster with no node.
runtimeRefused = hive { deploy.notify-router.runtime = "k8s"; };
runtimeRefusals = lib.filter (a: !a.assertion) runtimeRefused.assertions;
# A node every assertion refuses: no rendering, a pod range containing the
# hive bridge's subnet, and a service range inside the pod range.
@ -173,6 +185,10 @@ let
renders =
config: (builtins.tryEval (builtins.deepSeq (builtins.toJSON (render config)) true)).success;
routerUnit = c: c.services.hyperhive.deploy.notify-router.unit;
manifestNames = c: lib.sort lib.lessThan (lib.attrNames c.services.k3s.manifests);
routerPrune = withNode.systemd.services.swarm-notify-router-k8s-prune;
clusterRouterSpec = (render onCluster)."swarm-notify-router/deployment".spec.template.spec;
cases = [
{
# Each service's own credential path is the control: the comparison
@ -205,32 +221,6 @@ let
&&
(lib.head (podSpec "swarm-controller").volumes).secret.secretName == "swarm-controller-credentials";
}
{
# The controller's pod is the control for the Secret lookup: its
# credentials still come from one.
name = "the router's CA file comes from the CA ConfigMap and its pod mounts no Secret";
ok =
let
volumes = (podSpec "swarm-notify-router").volumes;
credentials = lib.findFirst (v: v.name == "credentials") null volumes;
sources = credentials.projected.sources;
in
credentials != null
&& lib.length sources == 1
&& (lib.head sources).configMap.name == "hyperhive-ca-trust"
&&
map (i: [
i.key
i.path
]) (lib.head sources).configMap.items == [
[
"bao-server-ca.pem"
"notify-router-bao-server-ca"
]
]
&& !(lib.any (v: v ? secret) volumes)
&& lib.any (v: v ? secret) (podSpec "swarm-controller").volumes;
}
{
name = "the poller's CronJob runs on its timer's interval and deadline, never overlapping";
ok =
@ -306,7 +296,7 @@ let
# granter's role unit (which enables the login's auth mount) starts the
# same command, and the manifests are the same derivation as without the
# node.
name = "the node changes no unit, container, timer or manifest of the all-local host";
name = "the node adds only k3s, the jwt unit and the router's prune unit to the all-local host, and changes no container, timer or manifest";
ok =
let
names = a: lib.attrNames a;
@ -316,8 +306,11 @@ let
&& names allLocal.containers == names withNode.containers
&& lib.subtractLists (names withNode.systemd.services) (names allLocal.systemd.services) == [ ]
&& lib.elem "k3s" added
&& lib.all (n: lib.hasPrefix "k3s" n || n == "swarm-bao-k8s-jwt-policy") added
&& lib.all (
n: lib.hasPrefix "k3s" n || n == "swarm-bao-k8s-jwt-policy" || n == "swarm-notify-router-k8s-prune"
) added
&& lib.elem "swarm-bao-k8s-jwt-policy" added
&& lib.elem "swarm-notify-router-k8s-prune" added
&&
lib.all
(
@ -666,6 +659,101 @@ let
&& !(lib.elem 8208 fw.allowedTCPPorts)
&& !(lib.elem 8208 withNode.services.hyperhive.network.exposeHostPorts);
}
{
# The host with the router on it is the control for every absence below:
# it holds the container, the prune unit and the pieces the cluster
# case lacks.
name = "a router on the host keeps its container, the node adds no manifest and no CA unit, and its prune unit runs before the container";
ok =
withNode.containers ? swarm-notify-router
&& withNode.systemd.services ? "container@swarm-notify-router"
&& manifestNames withNode == [ "coredns-custom" ]
&& !(withNode.systemd.services ? hyperhive-k8s-ca-trust)
&& routerPrune.before == [ "container@swarm-notify-router.service" ]
&& routerPrune.requiredBy == [ "container@swarm-notify-router.service" ]
&& lib.hasInfix "swarm-notify-router.yaml" routerPrune.script
&& allLocal.services.k3s.manifests == { }
&& !(allLocal.systemd.services ? swarm-notify-router-k8s-prune)
&& !(allLocal.systemd.services ? hyperhive-k8s-ca-trust);
}
{
name = "a router in the cluster leaves the host no container and no prune unit, and applies the namespace and its objects";
ok =
!(onCluster.containers ? swarm-notify-router)
&& !(onCluster.systemd.services ? "container@swarm-notify-router")
&& !(onCluster.systemd.services ? swarm-notify-router-k8s-prune)
&&
manifestNames onCluster == [
"coredns-custom"
"hyperhive-namespace"
"swarm-notify-router"
]
&& onCluster.services.k3s.manifests.hyperhive-namespace.content.kind == "Namespace"
&&
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-notify-router.content)
== [
"Deployment"
"ServiceAccount"
];
}
{
name = "the router's manifests and its unit are the same whether the container or the stand-alone evaluation supplies the unit";
ok =
(routerUnit withNode).environment ? SWARM_NOTIFY_ROUTER_NATS_URL
&& (routerUnit onCluster).environment == (routerUnit withNode).environment
&& (routerUnit onCluster).serviceConfig.ExecStart == (routerUnit withNode).serviceConfig.ExecStart
&&
(routerUnit onCluster).serviceConfig.LoadCredential == (routerUnit withNode)
.serviceConfig.LoadCredential
&& render onCluster == render withNode;
}
{
# The controller's pod is the control for the Secret lookup: its
# credentials still come from one.
name = "the router's CA file comes from the ConfigMap the host publishes, and the pod mounts no Secret";
ok =
let
volumes = clusterRouterSpec.volumes;
credentials = lib.findFirst (v: v.name == "credentials") null volumes;
sources = credentials.projected.sources;
caUnit = onCluster.systemd.services.hyperhive-k8s-ca-trust;
serverCa = onCluster.services.hyperhive.deploy.bao.serverCaFile;
in
credentials != null
&& lib.length sources == 1
&& (lib.head sources).configMap.name == "hyperhive-ca-trust"
&&
map (i: [
i.key
i.path
]) (lib.head sources).configMap.items == [
[
"bao-server-ca.pem"
"notify-router-bao-server-ca"
]
]
&& !(lib.any (v: v ? secret) volumes)
&& lib.any (v: v ? secret) (podSpec "swarm-controller").volumes
&& lib.hasInfix "--from-file=bao-server-ca.pem=${serverCa}" caUnit.script
&& lib.hasInfix "--from-file=trust-bundle.pem=" caUnit.script
&& lib.elem "multi-user.target" caUnit.wantedBy
# A change to either file publishes again with no manual step, and the
# host with the router on its container has no path unit.
&&
lib.sort lib.lessThan onCluster.systemd.paths.hyperhive-k8s-ca-trust.pathConfig.PathChanged
== lib.sort lib.lessThan [
serverCa
"${onCluster.services.hyperhive.deploy.hive-controller.tls.stateDir}/trust-bundle.pem"
]
&& !(caUnit.serviceConfig ? RemainAfterExit)
&& !(withNode.systemd.paths ? hyperhive-k8s-ca-trust);
}
{
name = "the router's runtime \"k8s\" needs the node";
ok =
lib.any (a: lib.hasInfix "runtime = \"k8s\" needs the" a.message) runtimeRefusals
&& lib.all (a: a.assertion) onCluster.assertions;
}
];
in
runGroup "k8s" cases