Watch
0
0
Fork
You've already forked hyperhive
0

k8s: deploy.ci-metrics.runtime moves the CI run poller between its timer and the cluster

This commit is contained in:
atlas 2026-11-22 02:52:20 +01:00 • committed by maia
commit cd1fe02b1f

View file

@ -49,14 +49,15 @@ let
};
withNode = hiveWithController nodeSettings;
# The same host with the router and the speech-to-text service in the
# cluster, so it has neither container. A second full host, because the claim
# is about what the configuration drops; the other cases of this group read
# `withNode`.
# The same host with the router, the speech-to-text service and the CI run
# poller in the cluster, so it has neither container nor poller unit. 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";
deploy.stt.runtime = "k8s";
deploy.ci-metrics.runtime = "k8s";
}
);
@ -64,6 +65,7 @@ let
runtimeRefused = hive {
deploy.notify-router.runtime = "k8s";
deploy.stt.runtime = "k8s";
deploy.ci-metrics.runtime = "k8s";
};
runtimeRefusals = lib.filter (a: !a.assertion) runtimeRefused.assertions;
@ -150,9 +152,8 @@ let
SWARM_STT_HEALTH_ADDR = "0.0.0.0:8080";
STATE_DIRECTORY = "/var/lib/swarm-stt";
};
# No endpoint: the poller keeps the route its unit names.
swarm-ci-metrics = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_CI_METRICS_OTLP_ENDPOINT = collectorEndpoint;
STATE_DIRECTORY = "/var/lib/swarm-ci-metrics";
};
};
@ -197,7 +198,12 @@ let
# The same host with one more variable on the poller's unit, naming a path
# the pod does not mount.
withStrayPath = lib.recursiveUpdate allLocal {
systemd.services.swarm-ci-metrics.environment.SWARM_CI_METRICS_STRAY = "/etc/stray.json";
services.hyperhive.deploy.ci-metrics.unit.environment.SWARM_CI_METRICS_STRAY = "/etc/stray.json";
};
# The same host with the poller's unit naming no endpoint of its own.
withoutOwnEndpoint = lib.recursiveUpdate allLocal {
services.hyperhive.deploy.ci-metrics.unit.environment.SWARM_CI_METRICS_OTLP_ENDPOINT = null;
};
renders =
config: (builtins.tryEval (builtins.deepSeq (builtins.toJSON (render config)) true)).success;
@ -206,6 +212,7 @@ let
manifestNames = c: lib.sort lib.lessThan (lib.attrNames c.services.k3s.manifests);
routerPrune = withNode.systemd.services.swarm-notify-router-k8s-prune;
sttPrune = withNode.systemd.services.swarm-stt-k8s-prune;
ciPrune = withNode.systemd.services.swarm-ci-metrics-k8s-prune;
clusterRouterSpec = (render onCluster)."swarm-notify-router/deployment".spec.template.spec;
cases = [
{
@ -314,7 +321,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 adds only k3s, the jwt unit and the prune units of the router and the speech-to-text service to the all-local host, and changes no container, timer or manifest";
name = "the node adds only k3s, the jwt unit and the prune units of the router, the speech-to-text service and the CI run poller to the all-local host, and changes no container, timer or manifest";
ok =
let
names = a: lib.attrNames a;
@ -330,10 +337,12 @@ let
|| n == "swarm-bao-k8s-jwt-policy"
|| n == "swarm-notify-router-k8s-prune"
|| n == "swarm-stt-k8s-prune"
|| n == "swarm-ci-metrics-k8s-prune"
) added
&& lib.elem "swarm-bao-k8s-jwt-policy" added
&& lib.elem "swarm-notify-router-k8s-prune" added
&& lib.elem "swarm-stt-k8s-prune" added
&& lib.elem "swarm-ci-metrics-k8s-prune" added
&&
lib.all
(
@ -410,21 +419,35 @@ let
{
# The units' own endpoints are the control: each differs from the
# collector's, so the override replaces something. The host's units keep
# theirs.
name = "every pod pushes telemetry to the hive collector, and the host units keep their endpoints";
# theirs. The poller is a swarm-tier producer: its pod keeps the swarm
# collector's route of its own, spelled out here, and names no hive
# collector in any variable.
name = "every hive-tier pod pushes telemetry to the hive collector, the poller's pod keeps its swarm route, and the host units keep their endpoints";
ok =
lib.all (
let
hiveTier = lib.filter (n: n != "swarm-ci-metrics") (lib.attrNames units);
ownRoute = "https://${allLocal.services.hyperhive.swarm.otel.domain}/swarm-ci-metrics";
in
lib.length hiveTier == 3
&& lib.all (
name:
(envOf name).OTEL_EXPORTER_OTLP_ENDPOINT == collectorEndpoint
&& (units.${name}.environment.OTEL_EXPORTER_OTLP_ENDPOINT or null) != collectorEndpoint
) (lib.attrNames units)
&& units.swarm-ci-metrics.environment.SWARM_CI_METRICS_OTLP_ENDPOINT != collectorEndpoint
&& (envOf "swarm-ci-metrics").SWARM_CI_METRICS_OTLP_ENDPOINT == collectorEndpoint
) hiveTier
&& units.swarm-ci-metrics.environment.SWARM_CI_METRICS_OTLP_ENDPOINT == ownRoute
&& (envOf "swarm-ci-metrics").SWARM_CI_METRICS_OTLP_ENDPOINT == ownRoute
&& !((envOf "swarm-ci-metrics") ? OTEL_EXPORTER_OTLP_ENDPOINT)
&& !(lib.any (e: lib.hasInfix "hive-collector" (e.value or "")) (container "swarm-ci-metrics").env)
&& !(envOf "swarm-notify-router" ? SWARM_CI_METRICS_OTLP_ENDPOINT)
&&
allLocal.systemd.services.swarm-controller.environment.OTEL_EXPORTER_OTLP_ENDPOINT
== "https://${allLocal.services.hyperhive.swarm.otel.domain}/${allLocal.services.hyperhive.swarm.otel.producerName}";
}
{
# The unchanged host is the control that the render itself succeeds.
name = "a poller whose unit names no endpoint of its own fails the render, as the pod would have nowhere to push";
ok = renders allLocal && !(renders withoutOwnEndpoint);
}
{
# Off, the collector's configuration holds nothing of the pod logs, and
# on, taking that out leaves the configuration it has off. The host with
@ -701,7 +724,7 @@ let
&& !(allLocal.systemd.services ? hyperhive-k8s-ca-trust);
}
{
name = "a router or a speech-to-text service in the cluster leaves the host no container and no prune unit, and applies the namespace and its objects";
name = "a router, a speech-to-text service or a poller in the cluster leaves the host no container, service, timer or prune unit, and applies the namespace and its objects";
ok =
!(onCluster.containers ? swarm-notify-router)
&& !(onCluster.systemd.services ? "container@swarm-notify-router")
@ -709,10 +732,15 @@ let
&& !(onCluster.containers ? swarm-stt)
&& !(onCluster.systemd.services ? "container@swarm-stt")
&& !(onCluster.systemd.services ? swarm-stt-k8s-prune)
&& !(onCluster.systemd.services ? swarm-ci-metrics)
&& !(onCluster.systemd.timers ? swarm-ci-metrics)
&& !(onCluster.systemd.services ? swarm-ci-metrics-k8s-prune)
&& !(onCluster.systemd.services ? swarm-ci-metrics-ca-bundle)
&&
manifestNames onCluster == [
"coredns-custom"
"hyperhive-namespace"
"swarm-ci-metrics"
"swarm-notify-router"
"swarm-stt"
]
@ -728,6 +756,13 @@ let
"Deployment"
"PersistentVolumeClaim"
"ServiceAccount"
]
&&
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-ci-metrics.content)
== [
"CronJob"
"PersistentVolumeClaim"
"ServiceAccount"
];
}
{
@ -975,12 +1010,97 @@ let
&& spec.securityContext.seccompProfile.type == "RuntimeDefault";
}
{
name = "the router's and the speech-to-text service's runtime \"k8s\" needs the node";
name = "the router's, the speech-to-text service's and the poller's runtime \"k8s\" needs the node";
ok =
lib.any (a: lib.hasInfix "notify-router.runtime = \"k8s\" needs the" a.message) runtimeRefusals
&& lib.any (a: lib.hasInfix "stt.runtime = \"k8s\" needs the" a.message) runtimeRefusals
&& lib.any (a: lib.hasInfix "ci-metrics.runtime = \"k8s\" needs the" a.message) runtimeRefusals
&& lib.all (a: a.assertion) onCluster.assertions;
}
{
# The host with the poller on it is the control for the stand-alone
# evaluation: the unit and timer read there are what the host runs.
name = "the poller's unit and timer, and so its CronJob, are the same whether the host or the stand-alone evaluation supplies them";
ok =
let
unitOf = c: c.services.hyperhive.deploy.ci-metrics.unit;
timerOf = c: c.services.hyperhive.deploy.ci-metrics.timer;
in
(unitOf withNode).serviceConfig.Type == "oneshot"
&& (unitOf withNode).environment ? SWARM_CI_METRICS_OTLP_ENDPOINT
&& (unitOf onCluster).serviceConfig == (unitOf withNode).serviceConfig
&& (unitOf onCluster).environment == (unitOf withNode).environment
&& (timerOf withNode).timerConfig.OnUnitInactiveSec == "5min"
&& (timerOf onCluster).timerConfig == (timerOf withNode).timerConfig
&& (render onCluster)."swarm-ci-metrics/cronjob" == (render withNode)."swarm-ci-metrics/cronjob";
}
{
# The host's own unit and timer are pinned by value, and both are held
# back by the prune unit. The host with the poller in the cluster is the
# control that the lookups find what is there.
name = "with the poller on the host, its service, timer and CA bundle are as the module defines them, and its prune unit runs before both";
ok =
let
sc = withNode.systemd.services.swarm-ci-metrics.serviceConfig;
timer = withNode.systemd.timers.swarm-ci-metrics;
in
sc.Type == "oneshot"
&& sc.DynamicUser
&& sc.StateDirectory == "swarm-ci-metrics"
&& sc.TimeoutStartSec == "30min"
&& lib.any (e: lib.hasPrefix "bao-client.pem:" e) sc.LoadCredential
&& timer.timerConfig.OnUnitInactiveSec == "5min"
&& lib.elem "timers.target" timer.wantedBy
&& withNode.systemd.services.swarm-ci-metrics.environment ? SSL_CERT_FILE
&& withNode.systemd.services ? swarm-ci-metrics-ca-bundle
&&
ciPrune.before == [
"swarm-ci-metrics.timer"
"swarm-ci-metrics.service"
]
&&
ciPrune.requiredBy == [
"swarm-ci-metrics.timer"
"swarm-ci-metrics.service"
]
&& lib.hasInfix "swarm-ci-metrics.yaml" ciPrune.script
&& lib.hasInfix "delete deployment,cronjob,serviceaccount" ciPrune.script
&& !(allLocal.systemd.services ? swarm-ci-metrics-k8s-prune);
}
{
# The poller's one credential in the pod is the store's public CA, from
# the ConfigMap the host publishes, and no volume of it names a Secret,
# which nothing creates. The controller's pod is the control that the
# lookup finds a Secret where there is one.
name = "the poller's pod gets the store's CA from the ConfigMap, drops its client certificate and key, and mounts no Secret";
ok =
let
spec = (render onCluster)."swarm-ci-metrics/cronjob".spec.jobTemplate.spec.template.spec;
volumesOf = s: s.volumes;
usesSecret = v: v ? secret || lib.any (src: src ? secret) (v.projected.sources or [ ]);
cred = lib.findFirst (v: v.name == "credentials") null spec.volumes;
serverCa = onCluster.services.hyperhive.deploy.bao.serverCaFile;
in
serverCa != null
&& cred != null
&&
map (s: s.configMap.items) cred.projected.sources == [
[
{
key = "bao-server-ca.pem";
path = "bao-ca.pem";
}
]
]
&& !(lib.any usesSecret (volumesOf spec))
&& lib.any usesSecret (volumesOf (podSpec "swarm-controller"))
&& (lib.head spec.containers).env != [ ]
&& lib.any (
e: e.name == "BAO_CACERT" && e.value == "/run/credentials/swarm-ci-metrics.service/bao-ca.pem"
) (lib.head spec.containers).env
&& lib.all (v: lib.all (e: e.name != v) (lib.head spec.containers).env) clientVars
&& !(lib.hasInfix "swarm-ci-metrics-credentials" rendered);
}
];
in
runGroup "k8s" cases