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
4 changed files with 255 additions and 185 deletions

View file

@ -60,7 +60,12 @@ let
# `serviceUser` is the user every image runs its daemon as. Mounted files are
# group-owned by its group through `fsGroup`.
inherit (import ../../images { inherit pkgs lib; }) mkServiceImage serviceUser;
inherit (import ../../images { inherit pkgs lib; })
mkServiceImage
serviceUser
wgetOnly
loopbackProbe
;
# `DRAIN` in swarm-secret-client/src/shutdown.rs: how long a daemon keeps
# finishing in-flight work after SIGTERM before it exits on its own. The
@ -444,7 +449,7 @@ let
# runs in the cluster, because the `hostPort` they bind is forwarded to them
# before the policy sees the packet. The policy selects every pod of the
# service for ingress too and allows none, so only the node's own traffic
# (the kubelet's probes, which the policy engine always admits) reaches it.
# (which the policy engine always admits) reaches it.
networkPolicyOf =
name: reaches:
let
@ -686,7 +691,7 @@ let
// lib.optionalAttrs (runtimeDir != null) { RUNTIME_DIRECTORY = runtimeDir; }
// lib.optionalAttrs (stateDir != null) { STATE_DIRECTORY = stateDir; }
// lib.optionalAttrs (svc.healthEnv != null) {
${svc.healthEnv} = "0.0.0.0:${toString healthPort}";
${svc.healthEnv} = "127.0.0.1:${toString healthPort}";
};
mountRoots = [
@ -713,9 +718,11 @@ let
inherit name;
inherit (svc) package;
bin = daemon;
extraContents = lib.optional (storeValues != [ ]) (
pkgs.writeTextDir "share/hyperhive/${name}.env-refs" (lib.concatLines storeValues)
);
extraContents =
lib.optional (storeValues != [ ]) (
pkgs.writeTextDir "share/hyperhive/${name}.env-refs" (lib.concatLines storeValues)
)
++ lib.optional (svc.healthEnv != null) wgetOnly;
};
# A systemd `%d` in an argument is the credential directory, as in the
@ -896,16 +903,12 @@ let
cpu = "0";
};
# The listener's Service targets this port by its name.
ports =
lib.optional (svc.healthEnv != null) {
name = "health";
containerPort = healthPort;
}
++ lib.optional (listener != { }) {
name = "api";
containerPort = listener.port;
};
# The listener's Service targets this port by its name. The health
# listener is not a port: it binds to the pod's loopback.
ports = lib.optional (listener != { }) {
name = "api";
containerPort = listener.port;
};
container = {
inherit name volumeMounts;
@ -962,20 +965,8 @@ let
};
}
// lib.optionalAttrs (svc.healthEnv != null) {
livenessProbe = {
httpGet = {
path = "/healthz";
port = "health";
};
periodSeconds = 10;
};
readinessProbe = {
httpGet = {
path = "/readyz";
port = "health";
};
periodSeconds = 10;
};
livenessProbe = loopbackProbe healthPort "/healthz";
readinessProbe = loopbackProbe healthPort "/readyz";
};
# The listener's leaf: issued before the daemon starts, renewed beside it.
@ -1253,7 +1244,7 @@ in
# anyone, so a pod is reachable from the node alone until a policy of its own
# admits more. The cluster's policy engine takes the union of the policies
# that select a pod and always admits the node's own addresses, so the
# kubelet's probes and the host's gateway still reach every pod. A port a pod
# host's gateway still reaches every pod. A port a pod
# opens later is closed to the other pods and to the hive bridge without a
# line here.
// {

View file

@ -774,7 +774,11 @@ let
...
}:
let
inherit (import ../images { inherit pkgs lib; }) mkServiceImage;
inherit (import ../images { inherit pkgs lib; })
mkServiceImage
wgetOnly
loopbackProbe
;
podAuth = import ./lib/bao-pod-auth.nix;
tools = [
@ -870,10 +874,7 @@ let
bin = "nats-server";
extraContents = [
(pkgs.writeTextDir "share/hyperhive/${machine}-settings.refs" "${renderedSettings}\n")
(pkgs.runCommand "wget-only" { } ''
mkdir -p $out/bin
ln -s ${pkgs.pkgsStatic.busybox}/bin/busybox $out/bin/wget
'')
wgetOnly
];
};
exporter = mkServiceImage {
@ -972,17 +973,7 @@ let
# The monitor is on the pod's loopback, so the probe runs in the
# container. A server that has not opened its JetStream store is not
# ready.
readinessProbe = {
exec.command = [
"/bin/wget"
"-q"
"-O"
"/dev/null"
"http://127.0.0.1:${toString deployCfg.nats.monitorPort}/healthz?js-enabled-only=true"
];
periodSeconds = 10;
timeoutSeconds = 5;
};
readinessProbe = loopbackProbe deployCfg.nats.monitorPort "/healthz?js-enabled-only=true";
volumeMounts = [
(volumeNamed "nats-tls" tlsDir true)
(volumeNamed "nats-config" runtimeDir true)

View file

@ -41,7 +41,11 @@ let
hyperhiveCfg = config.services.hyperhive;
gatewayCfg = hyperhiveCfg.gateway;
k8sCfg = hyperhiveCfg.k8s;
inherit (import ../images { inherit pkgs lib; }) mkServiceImage;
inherit (import ../images { inherit pkgs lib; })
mkServiceImage
wgetOnly
loopbackProbe
;
storeAuth = import ./lib/store-auth.nix;
# Copy of `swarm-ui.nix`'s own `swarmAuthRequest` — not shared code because
@ -199,13 +203,7 @@ let
name = grafanaAuthService;
package = deployCfg.victorialogs.grafanaAuthPackage;
bin = "swarm-metrics-auth";
};
probe = path: {
httpGet = {
inherit path;
port = "health";
};
periodSeconds = 10;
extraContents = [ wgetOnly ];
};
in
{
@ -225,7 +223,7 @@ let
env = lib.mapAttrsToList (name: value: { inherit name value; }) (
lib.filterAttrs (n: _: lib.hasPrefix "BAO_" n) env
// {
SWARM_METRICS_AUTH_HEALTH_ADDR = "0.0.0.0:${toString grafanaAuthHealthPort}";
SWARM_METRICS_AUTH_HEALTH_ADDR = "127.0.0.1:${toString grafanaAuthHealthPort}";
}
);
# Not `api`: a Service resolves a named port to the first container of the
@ -235,13 +233,9 @@ let
name = "grafana-api";
containerPort = grafanaAuthPort;
}
{
name = "health";
containerPort = grafanaAuthHealthPort;
}
];
livenessProbe = probe "/healthz";
readinessProbe = probe "/readyz";
livenessProbe = loopbackProbe grafanaAuthHealthPort "/healthz";
readinessProbe = loopbackProbe grafanaAuthHealthPort "/readyz";
volumeMounts = lib.filter (
m:
lib.elem m.name [

View file

@ -31,7 +31,11 @@ let
networkCfg = hyperhiveCfg.network;
k8sCfg = hyperhiveCfg.k8s;
baoCfg = hyperhiveCfg.swarm.bao;
inherit (import ../images { inherit pkgs lib; }) mkServiceImage;
inherit (import ../images { inherit pkgs lib; })
mkServiceImage
wgetOnly
loopbackProbe
;
storeAuth = import ./lib/store-auth.nix;
# The workloads, as the cluster names them: the store, and the one pod that
@ -254,13 +258,7 @@ let
name = grafanaAuthService;
package = deployCfg.victoriametrics.authPackage;
bin = "swarm-metrics-auth";
};
probe = path: {
httpGet = {
inherit path;
port = "grafana-health";
};
periodSeconds = 10;
extraContents = [ wgetOnly ];
};
in
{
@ -280,10 +278,10 @@ let
env = lib.mapAttrsToList (name: value: { inherit name value; }) (
lib.filterAttrs (n: _: lib.hasPrefix "BAO_" n) env
// {
SWARM_METRICS_AUTH_HEALTH_ADDR = "0.0.0.0:${toString grafanaAuthHealthPort}";
SWARM_METRICS_AUTH_HEALTH_ADDR = "127.0.0.1:${toString grafanaAuthHealthPort}";
}
);
# Not `api` and `health`: a Service resolves a named port to the first
# Not `api`: a Service resolves a named port to the first
# container of the pod that declares the name, which is the agents'
# responder's.
ports = [
@ -291,13 +289,9 @@ let
name = "grafana-api";
containerPort = grafanaAuthPort;
}
{
name = "grafana-health";
containerPort = grafanaAuthHealthPort;
}
];
livenessProbe = probe "/healthz";
readinessProbe = probe "/readyz";
livenessProbe = loopbackProbe grafanaAuthHealthPort "/healthz";
readinessProbe = loopbackProbe grafanaAuthHealthPort "/readyz";
volumeMounts = lib.filter (
m:
lib.elem m.name [