Watch
0
0
Fork
You've already forked hyperhive
0

k8s: stt and ci-metrics start without a state gate

This commit is contained in:
atlas 2026-11-23 02:46:31 +01:00 • committed by maia
commit 6ac4e9b87d

View file

@ -152,9 +152,11 @@ let
# the paths the unit names that hold one to theirs. `listener`, where a
# service has one, is the TCP port the pod publishes on the node
# (`hostAddress`) and the directory its init container writes the leaf to.
# `fresh` (`freshOf`) is set on every service whose pod gets a state volume:
# the volume's first init container, the state gate, refuses to start the pod
# on one that holds no migrated state unless the install is fresh.
# `fresh` (`freshOf`) is set on a service whose state is worth moving: the
# volume's first init container, the state gate, refuses to start the pod on
# one that holds no migrated state unless the install is fresh. A service
# without it starts on whatever volume it gets, and one with
# `ephemeralState` gets an `emptyDir` in place of a claim.
# `switch` is null for a service that always runs on the host, and for one
# with a `runtime` option names the option's value and the host unit or units
# that run the service when it is `"host"`. `otlp` is where the pod pushes
@ -238,7 +240,7 @@ let
etcFiles = [ ];
publicCredentials.stt-bao-server-ca = baoServerCaKey;
otlp = "hive";
fresh = freshOf "stt" deployCfg.stt;
ephemeralState = true;
switch = {
inherit (deployCfg.stt) runtime;
hostUnit = "container@swarm-stt.service";
@ -279,7 +281,6 @@ let
etcFiles = [ ];
publicCredentials."bao-ca.pem" = baoServerCaKey;
otlp = "own";
fresh = freshOf "ci-metrics" deployCfg.ci-metrics;
# The timer and the service both: the prune unit holds back either, and a
# service started by hand cannot run beside the CronJob.
switch = {
@ -445,6 +446,7 @@ let
runtimeDir = if sc ? RuntimeDirectory then "/run/${sc.RuntimeDirectory}" else null;
stateDir = if sc ? StateDirectory then "/var/lib/${sc.StateDirectory}" else null;
ephemeral = svc.ephemeralState or false;
# PATH holds only NixOS's default tools (checked below), which the image
# does not carry. `%d` is systemd's specifier for the credential
@ -622,10 +624,14 @@ let
name = "runtime";
emptyDir = { };
}
++ lib.optional (stateDir != null) {
name = "state";
persistentVolumeClaim.claimName = "${name}-state";
}
++ lib.optional (stateDir != null) (
{
name = "state";
}
// (
if ephemeral then { emptyDir = { }; } else { persistentVolumeClaim.claimName = "${name}-state"; }
)
)
++ lib.optional (svc.etcFiles != [ ]) {
name = "etc";
configMap.name = "${name}-etc";
@ -772,18 +778,22 @@ let
package = leafImagePackage;
bin = leafIssueBin;
};
# The volume that holds the service's state, and where it is mounted. A
# pod that makes its own volume names it in `state`.
# The volume the state gate checks, and where it is mounted: that of a
# service with a `fresh` option, none for the rest. A pod that makes its
# own volume names it in `state`.
stateVolume =
extra.state or (
if stateDir != null then
{
volume = "state";
path = stateDir;
}
else
null
);
if !(svc ? fresh) then
null
else
extra.state or (
if stateDir != null then
{
volume = "state";
path = stateDir;
}
else
null
);
stateGate = lib.optionalAttrs (stateVolume != null) {
name = "state-gate";
@ -974,7 +984,7 @@ let
automountServiceAccountToken = false;
};
}
// lib.optionalAttrs (stateDir != null) {
// lib.optionalAttrs (stateDir != null && !ephemeral) {
"${name}/persistentvolumeclaim" = {
apiVersion = "v1";
kind = "PersistentVolumeClaim";
@ -1000,8 +1010,6 @@ let
fail name "the unit names no OTLP endpoint of its own, which the pod would push to"
else if svc.healthEnv != null && unitEnv ? ${svc.healthEnv} then
fail name "the unit already sets ${svc.healthEnv}"
else if stateVolume != null && !(svc ? fresh) then
fail name "the pod has a state volume and the service names no `fresh` option for its state gate"
else if lib.head execWords != entrypoint then
fail name "ExecStart is not ${entrypoint} with plain arguments"
else if lib.any (w: lib.hasInfix "\"" w) execWords then