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 ff2bdea78d

View file

@ -885,6 +885,7 @@ let
lib.sort lib.lessThan (map (o: o.kind) onCluster.services.k3s.manifests.swarm-ci-metrics.content)
== [
"CronJob"
"PersistentVolume"
"PersistentVolumeClaim"
"ServiceAccount"
];
@ -1845,27 +1846,28 @@ let
&& (volume "nats-data").persistentVolumeClaim.claimName == pvc.metadata.name
&& pvc.spec.accessModes == [ "ReadWriteOnce" ]
# The claim binds by name the static local volume on the container's
# store directory, on this node, and only that: its class is its own.
# The poller's claim is the control that a claim does not.
# store directory, and only that: its class is its own.
&& pvc.spec.volumeName == pv.metadata.name
&& pvc.spec.storageClassName == pv.spec.storageClassName
&& pv.spec.storageClassName != ""
&& !(objects."swarm-ci-metrics/persistentvolumeclaim".spec ? volumeName)
&& pv.spec.local.path == hostStore
&& pv.spec.persistentVolumeReclaimPolicy == "Retain"
&& !(pv.metadata ? namespace)
# It binds on the node with the queue's state label, and the pod runs
# only there.
&&
pv.spec.nodeAffinity.required.nodeSelectorTerms == [
{
matchExpressions = [
{
key = "kubernetes.io/hostname";
key = "hyperhive.darkest.space/state-nats";
operator = "In";
values = [ (lib.toLower allLocal.networking.hostName) ];
values = [ "true" ];
}
];
}
]
&& spec.nodeSelector == { "hyperhive.darkest.space/state-nats" = "true"; }
# A pod on a host that never ran the container gets the directory made;
# a host with the container needs no rule.
&& lib.any (lib.hasPrefix "d ${hostStore} ") onCluster.systemd.tmpfiles.rules
@ -1912,7 +1914,7 @@ let
}
&& !(objects ? "swarm-controller/persistentvolumeclaim")
&& !(objects ? "swarm-stt/persistentvolumeclaim")
&& (stateVolume "swarm-ci-metrics").persistentVolumeClaim.claimName == "swarm-ci-metrics-state"
&& (stateVolume "swarm-ci-metrics").persistentVolumeClaim.claimName == "swarm-ci-metrics-store"
&& objects ? "swarm-ci-metrics/persistentvolumeclaim"
&& !(lib.any (n: lib.hasInfix "state-gate" n) (map toString withNode.system.build.k8sImages))
&& objects ? "swarm-nats/persistentvolumeclaim";
@ -2220,6 +2222,79 @@ let
&& problems withCaps != [ ]
&& problems withoutSeccomp != [ ];
}
{
# Each fixture is the control for the other: the host with the services
# on the host has the entry labels only, the one with them in the
# cluster has those and a state label each. The host without the node
# labels nothing.
name = "the node labels itself as the entry node, and with a state label for each service whose data the cluster keeps";
ok =
let
entry = [
"hyperhive.darkest.space/entry=true"
"svccontroller.k3s.cattle.io/enablelb=true"
];
sorted = lib.sort lib.lessThan;
in
sorted onCluster.services.k3s.nodeLabel == sorted (
entry
++ [
"hyperhive.darkest.space/state-nats=true"
"hyperhive.darkest.space/state-ci-metrics=true"
]
)
&& sorted withNode.services.k3s.nodeLabel == sorted entry
&&
onCluster.services.hyperhive.deploy.k8s.nodeLabels == {
"hyperhive.darkest.space/entry" = "true";
"svccontroller.k3s.cattle.io/enablelb" = "true";
"hyperhive.darkest.space/state-nats" = "true";
"hyperhive.darkest.space/state-ci-metrics" = "true";
}
&& allLocal.services.k3s.nodeLabel == [ ];
}
{
# The queue's pod is the control for the poller's lookups, and the
# stateless pods for the absence of a selector. `nodeAffinity` is in the
# text the hostname is searched in.
name = "the poller's claim is a static local volume on the service's directory, and the volumes and pods of the queue and the poller name their state label, with no hostname in any object";
ok =
let
pv = objects."swarm-ci-metrics/persistentvolume";
pvc = objects."swarm-ci-metrics/persistentvolumeclaim";
spec = podSpec "swarm-ci-metrics";
state = lib.findFirst (v: v.name == "state") null spec.volumes;
text = builtins.toJSON objects + builtins.toJSON onCluster.services.hyperhive.k8s.rendered.services;
hostDir = "/var/lib/private/swarm-ci-metrics";
rule = "d ${hostDir} 0700 root root -";
in
pv.spec.nodeAffinity.required.nodeSelectorTerms == [
{
matchExpressions = [
{
key = "hyperhive.darkest.space/state-ci-metrics";
operator = "In";
values = [ "true" ];
}
];
}
]
&& spec.nodeSelector == { "hyperhive.darkest.space/state-ci-metrics" = "true"; }
&& pv.spec.local.path == hostDir
&& pv.spec.persistentVolumeReclaimPolicy == "Retain"
&& !(pv.metadata ? namespace)
&& pvc.spec.volumeName == pv.metadata.name
&& pvc.spec.storageClassName == pv.spec.storageClassName
&& pv.spec.storageClassName != ""
&& state.persistentVolumeClaim.claimName == pvc.metadata.name
&& !(podSpec "swarm-controller" ? nodeSelector)
&& !(podSpec "swarm-stt" ? nodeSelector)
&& (podSpec "swarm-nats").nodeSelector == { "hyperhive.darkest.space/state-nats" = "true"; }
&& lib.hasInfix "nodeAffinity" text
&& !(lib.hasInfix "kubernetes.io/hostname" text)
&& lib.elem rule onCluster.systemd.tmpfiles.rules
&& !(lib.elem rule withNode.systemd.tmpfiles.rules);
}
];
in
runGroup "k8s" cases