Watch
0
0
Fork
You've already forked hyperhive
0

pin queue and poller state to per-service node labels instead of the hostname

This commit is contained in:
atlas 2026-11-25 21:48:02 +01:00 • committed by maia
commit 354354859f

View file

@ -46,6 +46,7 @@ let
controllerOnCluster = controllerCfg.enable && controllerCfg.runtime == "k8s";
controllerTcp = hyperhiveCfg.swarm.controller.tcp;
natsCfg = deployCfg.nats;
labels = import ./labels.nix;
servicesRootPath = "${deployCfg.hive-controller.tls.stateDir}/${servicesRootKey}";
caSources = {
${trustBundleKey} = if caTrust.useSelfSigned then caTrust.caHostPath else null;
@ -275,6 +276,13 @@ let
healthEnv = null;
etcFiles = [ ];
publicCredentials."bao-ca.pem" = baoServerCaKey;
# A static local volume on the unit's own state directory, in place of the
# default class: it binds only on the node with the service's state label
# (./labels.nix).
localState = {
service = "ci-metrics";
hostDir = deployCfg.ci-metrics.hostStateDir;
};
otlp = "own";
# The timer and the service both: the prune unit holds back either, and a
# service started by hand cannot run beside the CronJob.
@ -551,6 +559,8 @@ 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;
localState = svc.localState or null;
stateClaim = if localState != null then "${name}-store" else "${name}-state";
# PATH holds only NixOS's default tools (checked below), which the image
# does not carry. `%d` is systemd's specifier for the credential
@ -732,9 +742,7 @@ let
{
name = "state";
}
// (
if ephemeral then { emptyDir = { }; } else { persistentVolumeClaim.claimName = "${name}-state"; }
)
// (if ephemeral then { emptyDir = { }; } else { persistentVolumeClaim.claimName = stateClaim; })
)
++ lib.optional (svc.etcFiles != [ ]) {
name = "etc";
@ -957,6 +965,9 @@ let
}
// lib.optionalAttrs baoLogin { serviceAccountName = name; }
// lib.optionalAttrs (svc ? hostUsers && !svc.hostUsers) { hostUsers = false; }
// lib.optionalAttrs (localState != null) {
nodeSelector = labels.stateSelector localState.service;
}
// lib.optionalAttrs (listener != { } || extra.initContainers != [ ]) {
initContainers = lib.optional (listener != { }) leafContainer ++ extra.initContainers;
}
@ -1048,10 +1059,30 @@ let
"${name}/persistentvolumeclaim" = {
apiVersion = "v1";
kind = "PersistentVolumeClaim";
metadata = metaFor "${name}-state";
metadata = metaFor stateClaim;
spec = {
accessModes = [ "ReadWriteOnce" ];
resources.requests.storage = "1Gi";
}
// lib.optionalAttrs (localState != null) {
storageClassName = stateClaim;
volumeName = stateClaim;
};
};
}
// lib.optionalAttrs (stateDir != null && !ephemeral && localState != null) {
"${name}/persistentvolume" = {
apiVersion = "v1";
kind = "PersistentVolume";
# Cluster-scoped: no namespace.
metadata = removeAttrs (metaFor stateClaim) [ "namespace" ];
spec = {
capacity.storage = "1Gi";
accessModes = [ "ReadWriteOnce" ];
persistentVolumeReclaimPolicy = "Retain";
storageClassName = stateClaim;
local.path = localState.hostDir;
nodeAffinity = labels.stateAffinity localState.service;
};
};
}