Watch
0
0
Fork
You've already forked hyperhive
0

k8s: deploy.stt.runtime moves the speech-to-text service between its container and the cluster

This commit is contained in:
atlas 2026-11-21 23:12:09 +01:00 • committed by maia
commit 4b4df16e52

View file

@ -49,15 +49,22 @@ let
};
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`.
# 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`.
onCluster = hiveWithController (
lib.recursiveUpdate nodeSettings { deploy.notify-router.runtime = "k8s"; }
lib.recursiveUpdate nodeSettings {
deploy.notify-router.runtime = "k8s";
deploy.stt.runtime = "k8s";
}
);
# A host that asks for the cluster with no node.
runtimeRefused = hive { deploy.notify-router.runtime = "k8s"; };
runtimeRefused = hive {
deploy.notify-router.runtime = "k8s";
deploy.stt.runtime = "k8s";
};
runtimeRefusals = lib.filter (a: !a.assertion) runtimeRefused.assertions;
# A node every assertion refuses: no rendering, a pod range containing the
@ -86,6 +93,7 @@ let
swarm-controller = allLocal.systemd.services.swarm-controller;
swarm-notify-router =
allLocal.containers.swarm-notify-router.config.systemd.services.swarm-notify-router;
swarm-stt = allLocal.containers.swarm-stt.config.systemd.services.swarm-stt;
swarm-ci-metrics = allLocal.systemd.services.swarm-ci-metrics;
};
@ -137,6 +145,11 @@ let
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_NOTIFY_ROUTER_HEALTH_ADDR = "0.0.0.0:8080";
};
swarm-stt = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_STT_HEALTH_ADDR = "0.0.0.0:8080";
STATE_DIRECTORY = "/var/lib/swarm-stt";
};
swarm-ci-metrics = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_CI_METRICS_OTLP_ENDPOINT = collectorEndpoint;
@ -159,7 +172,9 @@ let
units.swarm-controller.serviceConfig.LoadCredential
++ units.swarm-ci-metrics.serviceConfig.LoadCredential
)
++ map (f: lib.last (lib.splitString ":" f)) allLocal.containers.swarm-notify-router.extraFlags;
++ map (f: lib.last (lib.splitString ":" f)) (
allLocal.containers.swarm-notify-router.extraFlags ++ allLocal.containers.swarm-stt.extraFlags
);
credentialIds = lib.concatMap (
u: map (e: lib.head (lib.splitString ":" e)) u.serviceConfig.LoadCredential
) (lib.attrValues units);
@ -172,6 +187,8 @@ let
"bao-client-key.pem"
"notify-router-bao-cert"
"notify-router-bao-key"
"stt-bao-cert"
"stt-bao-key"
];
ciTimer = allLocal.systemd.timers.swarm-ci-metrics.timerConfig;
@ -188,6 +205,7 @@ let
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;
sttPrune = withNode.systemd.services.swarm-stt-k8s-prune;
clusterRouterSpec = (render onCluster)."swarm-notify-router/deployment".spec.template.spec;
cases = [
{
@ -276,17 +294,17 @@ let
}
{
# The images are the ones the manifests run, one per rendered service:
# the three workloads are the control that the list is not empty.
# the four workloads are the control that the list is not empty.
name = "the node loads the image of every service the manifests run, and k3s's own";
ok =
let
loaded = map toString withNode.services.k3s.images;
rendered = map toString withNode.system.build.k8sImages;
in
lib.length rendered == 3
lib.length rendered == 4
&& lib.all (i: lib.elem i loaded) rendered
&& lib.elem (toString withNode.services.k3s.package.airgap-images) loaded
&& lib.length loaded == 4;
&& lib.length loaded == 5;
}
{
# Nothing the host already runs differs but the store's side of the pods'
@ -296,7 +314,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 router's prune unit 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 and the speech-to-text service to the all-local host, and changes no container, timer or manifest";
ok =
let
names = a: lib.attrNames a;
@ -307,10 +325,15 @@ let
&& 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" || n == "swarm-notify-router-k8s-prune"
n:
lib.hasPrefix "k3s" n
|| n == "swarm-bao-k8s-jwt-policy"
|| n == "swarm-notify-router-k8s-prune"
|| n == "swarm-stt-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.all
(
@ -525,6 +548,7 @@ let
script = s.swarm-bao-k8s-jwt-policy.script;
certScript = {
swarm-notify-router = s.swarm-bao-notify-router-policy.script;
swarm-stt = s.swarm-bao-stt-policy.script;
swarm-ci-metrics = s.swarm-bao-ci-metrics-policy.script;
swarm-controller = s.swarm-bao-controller-policy.script;
};
@ -540,7 +564,7 @@ let
${ttl}
'';
in
lib.length roles == 3
lib.length roles == 4
&& lib.sort lib.lessThan roles == lib.sort lib.lessThan (lib.attrNames units)
&&
lib.sort lib.lessThan withNode.services.hyperhive.deploy.bao.k8sPrincipals
@ -677,16 +701,20 @@ let
&& !(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";
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";
ok =
!(onCluster.containers ? swarm-notify-router)
&& !(onCluster.systemd.services ? "container@swarm-notify-router")
&& !(onCluster.systemd.services ? swarm-notify-router-k8s-prune)
&& !(onCluster.containers ? swarm-stt)
&& !(onCluster.systemd.services ? "container@swarm-stt")
&& !(onCluster.systemd.services ? swarm-stt-k8s-prune)
&&
manifestNames onCluster == [
"coredns-custom"
"hyperhive-namespace"
"swarm-notify-router"
"swarm-stt"
]
&& onCluster.services.k3s.manifests.hyperhive-namespace.content.kind == "Namespace"
&&
@ -694,6 +722,12 @@ let
== [
"Deployment"
"ServiceAccount"
]
&&
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-stt.content) == [
"Deployment"
"PersistentVolumeClaim"
"ServiceAccount"
];
}
{
@ -749,9 +783,163 @@ let
&& !(withNode.systemd.paths ? hyperhive-k8s-ca-trust);
}
{
name = "the router's runtime \"k8s\" needs the node";
# The container's whole unit is compared, sandbox included, so the
# stand-alone evaluation cannot drift from what the host runs.
name = "the speech-to-text service's unit, and so its manifests, are the same whether the container or the stand-alone evaluation supplies it";
ok =
lib.any (a: lib.hasInfix "runtime = \"k8s\" needs the" a.message) runtimeRefusals
let
unitOf = c: c.services.hyperhive.deploy.stt.unit;
in
(unitOf withNode).serviceConfig.SystemCallFilter == [
"@system-service"
"~@privileged"
"~@resources"
]
&& (unitOf onCluster).serviceConfig == (unitOf withNode).serviceConfig
&& (unitOf onCluster).environment == (unitOf withNode).environment
&& render onCluster == render withNode;
}
{
# The host-mode container is pinned by value: the module moved into a
# let binding, and nothing about the container it defines may change.
name = "with the speech-to-text service on the host, its container, credential flags and sandbox are as the module defines them";
ok =
let
c = withNode.containers.swarm-stt;
sc = (unitOf withNode).serviceConfig;
unitOf = x: x.services.hyperhive.deploy.stt.unit;
flags = c.extraFlags;
in
c.autoStart
&& !c.ephemeral
&& c.privateNetwork
&& c.hostBridge == withNode.services.hyperhive.network.bridgeName
&& lib.all (f: lib.hasPrefix "--load-credential=stt-bao-" f) flags
&& lib.any (lib.hasPrefix "--load-credential=stt-bao-cert:") flags
&& lib.any (lib.hasPrefix "--load-credential=stt-bao-key:") flags
&& sc.User == "swarm-stt"
&& sc.StateDirectory == "swarm-stt"
&& sc.NoNewPrivileges
&& sc.MemoryDenyWriteExecute
&& sc.PrivateUsers
&& sc.CapabilityBoundingSet == ""
&& sc.MemoryMax == "3G"
&& sc.CPUQuota == "400%"
&& sc.TasksMax == 256
&& withNode.systemd.services ? "container@swarm-stt"
&& sttPrune.before == [ "container@swarm-stt.service" ]
&& sttPrune.requiredBy == [ "container@swarm-stt.service" ]
&& lib.hasInfix "swarm-stt.yaml" sttPrune.script;
}
{
# The unit's ceilings are the pod's limits, and the limits the pod has
# no field for are not rendered. The controller's pod, whose unit sets
# none, is the control that nothing is added to a pod without them.
name = "the speech-to-text pod carries its unit's memory and CPU ceilings as limits and no requests, and a pod whose unit sets none carries none";
ok =
let
unit = units.swarm-stt.serviceConfig;
limits = (container "swarm-stt").resources.limits;
in
unit.MemoryMax == "3G"
&& unit.CPUQuota == "400%"
&& unit.TasksMax == 256
&&
limits == {
memory = "3Gi";
cpu = "4000m";
}
&& !((container "swarm-stt").resources ? requests)
&& !(lib.hasInfix "TasksMax" rendered)
&& !(lib.hasInfix "SystemCallFilter" rendered)
&& lib.all (name: !((container name) ? resources)) [
"swarm-controller"
"swarm-notify-router"
"swarm-ci-metrics"
];
}
{
# Other spellings of a ceiling: bytes, megabytes, a fractional core, no
# memory limit. A setting render cannot read fails the evaluation, the
# unchanged host being the control that the render itself succeeds.
name = "the unit's limits translate by systemd's units, and one render cannot read fails the evaluation";
ok =
let
withLimits =
sc: lib.recursiveUpdate allLocal { services.hyperhive.deploy.stt.unit.serviceConfig = sc; };
containersOf = sc: ((render (withLimits sc))."swarm-stt/deployment".spec.template.spec.containers);
first = sc: lib.head (containersOf sc);
in
renders allLocal
&&
(first {
MemoryMax = "512M";
CPUQuota = "150%";
}).resources.limits == {
memory = "512Mi";
cpu = "1500m";
}
&&
(first { MemoryMax = "1048576"; }).resources.limits == {
memory = "1048576";
cpu = "4000m";
}
&&
(first { MemoryMax = "infinity"; }).resources.limits == {
cpu = "4000m";
}
&& !(renders (withLimits {
MemoryMax = "50%";
}))
&& !(renders (withLimits {
MemoryMax = "3 G";
}))
&& !(renders (withLimits {
CPUQuota = "4";
}));
}
{
name = "the speech-to-text pod has probes on its health listener, keeps its cache in a volume, mounts no Secret, and runs as every pod does";
ok =
let
c = container "swarm-stt";
spec = podSpec "swarm-stt";
pvc = objects."swarm-stt/persistentvolumeclaim";
cred = lib.findFirst (v: v.name == "credentials") null spec.volumes;
in
(lib.head c.ports).containerPort == 8080
&& c.readinessProbe.httpGet.path == "/readyz"
&& c.livenessProbe.httpGet.path == "/healthz"
&& pvc.metadata.name == "swarm-stt-state"
&& pvc.spec.resources.requests.storage == "1Gi"
&& lib.any (m: m.name == "state" && m.mountPath == "/var/lib/swarm-stt") c.volumeMounts
&&
(lib.findFirst (v: v.name == "state") null spec.volumes).persistentVolumeClaim.claimName
== "swarm-stt-state"
# The one credential the pod holds is the store's public CA, from the
# ConfigMap. The controller's pod is the control for the lookup.
&& cred != null
&& !(cred ? secret)
&&
map (s: s.configMap.items) cred.projected.sources == [
[
{
key = "bao-server-ca.pem";
path = "stt-bao-server-ca";
}
]
]
&& lib.any (v: v ? secret) (podSpec "swarm-controller").volumes
&& c.securityContext.readOnlyRootFilesystem
&& c.securityContext.runAsNonRoot
&& c.securityContext.capabilities.drop == [ "ALL" ]
&& spec.securityContext.seccompProfile.type == "RuntimeDefault";
}
{
name = "the router's and the speech-to-text service'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.all (a: a.assertion) onCluster.assertions;
}
];