Watch
0
0
Fork
You've already forked hyperhive
0

bind health listeners to the pod's loopback and probe them by exec

This commit is contained in:
atlas 2026-11-27 23:45:00 +01:00
commit 62cc95671d

View file

@ -201,24 +201,24 @@ let
swarm-controller = {
RUNTIME_DIRECTORY = "/run/swarm-controller";
STATE_DIRECTORY = "/var/lib/swarm-controller";
SWARM_CONTROLLER_HEALTH_ADDR = "0.0.0.0:8080";
SWARM_CONTROLLER_HEALTH_ADDR = "127.0.0.1:8080";
};
swarm-notify-router = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_NOTIFY_ROUTER_HEALTH_ADDR = "0.0.0.0:8080";
SWARM_NOTIFY_ROUTER_HEALTH_ADDR = "127.0.0.1:8080";
};
swarm-stt = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_STT_HEALTH_ADDR = "0.0.0.0:8080";
SWARM_STT_HEALTH_ADDR = "127.0.0.1:8080";
STATE_DIRECTORY = "/var/lib/swarm-stt";
};
swarm-review-classifier = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_REVIEW_CLASSIFIER_HEALTH_ADDR = "0.0.0.0:8080";
SWARM_REVIEW_CLASSIFIER_HEALTH_ADDR = "127.0.0.1:8080";
};
swarm-claude-login = {
OTEL_EXPORTER_OTLP_ENDPOINT = collectorEndpoint;
SWARM_CLAUDE_LOGIN_HEALTH_ADDR = "0.0.0.0:8080";
SWARM_CLAUDE_LOGIN_HEALTH_ADDR = "127.0.0.1:8080";
};
# No endpoint: the poller keeps the route its unit names.
swarm-ci-metrics = {
@ -347,11 +347,52 @@ let
let
c = container "swarm-notify-router";
in
(lib.head c.ports).containerPort == 8080
&& c.readinessProbe.httpGet.path == "/readyz"
&& c.livenessProbe.httpGet.path == "/healthz"
!(c ? ports)
&& lib.last c.readinessProbe.exec.command == "http://127.0.0.1:8080/readyz"
&& lib.last c.livenessProbe.exec.command == "http://127.0.0.1:8080/healthz"
&& lib.all (name: (podSpec name).terminationGracePeriodSeconds > 10) (lib.attrNames units);
}
{
# The presence arms are the controls: the listener's variables, the probes
# and the VictoriaLogs/Metrics `api` probes are found, so an empty list
# cannot pass.
name = "every health listener binds to the pod's loopback and is probed by exec, and no pod declares a port for it";
ok =
let
workloads = lib.filter (o: o.kind == "Deployment" || o.kind == "CronJob") (lib.attrValues objects);
podOf =
o: if o.kind == "CronJob" then o.spec.jobTemplate.spec.template.spec else o.spec.template.spec;
cs = lib.concatMap (o: (podOf o).containers) workloads;
env = c: lib.listToAttrs (map (e: lib.nameValuePair e.name e.value) (c.env or [ ]));
healthAddrs = lib.concatMap (
c: lib.attrValues (lib.filterAttrs (n: _: lib.hasSuffix "_HEALTH_ADDR" n) (env c))
) cs;
probes = lib.concatMap (
c:
lib.filter (p: p != null) [
(c.livenessProbe or null)
(c.readinessProbe or null)
(c.startupProbe or null)
]
) cs;
httpProbes = lib.filter (p: p ? httpGet) probes;
execProbes = lib.filter (p: p ? exec) probes;
in
lib.length healthAddrs == 10
&& lib.all (a: lib.hasPrefix "127.0.0.1:" a) healthAddrs
&& lib.length execProbes >= 20
&& lib.all (p: lib.hasPrefix "http://127.0.0.1:" (lib.last p.exec.command)) execProbes
&& lib.all (p: p.timeoutSeconds == 5) execProbes
&& httpProbes != [ ]
&& lib.all (p: p.httpGet.port == "api") httpProbes
&& !(lib.any (
p:
lib.elem p.name [
"health"
"grafana-health"
]
) (lib.concatMap (c: c.ports or [ ]) cs));
}
{
# The unchanged host is the control that the render itself succeeds.
name = "a unit variable naming a path the pod does not mount fails the render";
@ -1287,9 +1328,9 @@ let
spec = podSpec "swarm-stt";
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"
!(c ? ports)
&& lib.last c.readinessProbe.exec.command == "http://127.0.0.1:8080/readyz"
&& lib.last c.livenessProbe.exec.command == "http://127.0.0.1:8080/healthz"
&& lib.any (m: m.name == "state" && m.mountPath == "/var/lib/swarm-stt") c.volumeMounts
# The cache needs no claim, and is no state to gate. The poller beside
# it, whose cursor is kept, is the control that a claim renders.
@ -1342,10 +1383,10 @@ let
"Deployment"
"ServiceAccount"
]
&& (lib.head c.ports).containerPort == 8080
&& c.readinessProbe.httpGet.path == "/readyz"
&& c.livenessProbe.httpGet.path == "/healthz"
&& (envOf name)."${prefix}_HEALTH_ADDR" == "0.0.0.0:8080"
&& !(c ? ports)
&& lib.last c.readinessProbe.exec.command == "http://127.0.0.1:8080/readyz"
&& lib.last c.livenessProbe.exec.command == "http://127.0.0.1:8080/healthz"
&& (envOf name)."${prefix}_HEALTH_ADDR" == "127.0.0.1:8080"
&& lib.any (m: m.name == "tmp" && m.mountPath == "/tmp") c.volumeMounts
&& (lib.findFirst (v: v.name == "tmp") null spec.volumes).emptyDir == { }
&& !(lib.any (v: v ? persistentVolumeClaim) spec.volumes)
@ -1565,9 +1606,9 @@ let
annotationOf =
o: (render o)."swarm-controller/deployment".spec.template.metadata.annotations."checksum/etc";
in
c.readinessProbe.httpGet.path == "/readyz"
&& c.livenessProbe.httpGet.path == "/healthz"
&& (byName "health" c.ports).containerPort == 8080
lib.last c.readinessProbe.exec.command == "http://127.0.0.1:8080/readyz"
&& lib.last c.livenessProbe.exec.command == "http://127.0.0.1:8080/healthz"
&& byName "health" c.ports == null
&& api.containerPort == 9443
&& !(api ? hostPort)
&& !(api ? hostIP)
@ -1728,8 +1769,8 @@ let
"http://127.0.0.1:8222/healthz?js-enabled-only=true"
]
# The responder's own probes, on an address of the pod's own.
&& env.SWARM_NATS_AUTH_HEALTH_ADDR == "0.0.0.0:8080"
&& (named "swarm-nats").readinessProbe.httpGet.path == "/readyz"
&& env.SWARM_NATS_AUTH_HEALTH_ADDR == "127.0.0.1:8080"
&& lib.last (named "swarm-nats").readinessProbe.exec.command == "http://127.0.0.1:8080/readyz"
&& env.BAO_JWT_ROLE == "swarm-nats-auth"
&& !(env ? BAO_CLIENT_CERT)
# The per-agent subjects keep their `$`: a pod's arguments are not
@ -1981,7 +2022,6 @@ let
&&
lib.sort lib.lessThan (map (p: p.name) ports) == [
"client"
"health"
"metrics"
]
&& (render withNode)."swarm-nats/loadbalancer" == svc;
@ -2444,7 +2484,8 @@ let
(lib.listToAttrs (map (e: lib.nameValuePair e.name e.value) grafana.env)).BAO_JWT_ROLE
== "swarm-logs-auth"
&& !(lib.any (e: lib.hasPrefix "BAO_CLIENT" e.name) (logs.env ++ grafana.env))
&& grafana.livenessProbe.httpGet.port == "health"
&& lib.last grafana.livenessProbe.exec.command == "http://127.0.0.1:8083/healthz"
&& !(lib.any (p: p.name == "health") grafana.ports)
&& spec.serviceAccountName == "swarm-logs-auth"
&& objects."swarm-logs-auth/serviceaccount".metadata.name == "swarm-logs-auth"
&& hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-logs-auth" script
@ -2641,7 +2682,8 @@ let
&& (envOfC agents).BAO_JWT_ROLE == "swarm-metrics-auth"
&& (envOfC grafana).BAO_JWT_ROLE == "swarm-metrics-auth"
&& !(lib.any (e: lib.hasPrefix "BAO_CLIENT" e.name) (agents.env ++ grafana.env))
&& grafana.livenessProbe.httpGet.port == "grafana-health"
&& lib.last grafana.livenessProbe.exec.command == "http://127.0.0.1:8085/healthz"
&& !(lib.any (p: p.name == "grafana-health") grafana.ports)
&& spec.serviceAccountName == "swarm-metrics-auth"
&& objects."swarm-metrics-auth/serviceaccount".metadata.name == "swarm-metrics-auth"
&& hasInfix "bound_subject=system:serviceaccount:hyperhive:swarm-metrics-auth" script