Watch
0
0
Fork
You've already forked hyperhive
0

run the log store and its auth responders as pods

swarm-logs-auth and swarm-metrics-auth take --listen for a TCP address beside
--socket. The log store is a Deployment on a static local volume that is its
old container's data directory, behind a ClusterIP Service the gateway dials by
name. Its two auth_request responders are one unpinned pod with a jwt role.
The renderer gains a plain HTTP listener, a probe path, fsGroupChangePolicy,
and one policy for a pod with both a listener and egress.
This commit is contained in:
atlas 2026-11-26 10:17:57 +01:00 • committed by maia
commit dca4720b7b
2 changed files with 1385 additions and 746 deletions

View file

@ -129,13 +129,14 @@ let
"claude-login"
"nats"
"swarm-controller"
"victorialogs"
];
enabledServices = lib.filter (name: deployCfg.${name}.enable) swarmServices;
# The services whose data the module keeps in the cluster. Each puts its state
# label on this node.
stateful = lib.filterAttrs (_: svc: svc.enable) {
inherit (deployCfg) nats ci-metrics;
inherit (deployCfg) nats ci-metrics victorialogs;
};
in
{
@ -264,7 +265,7 @@ in
none of those pods.
- `hyperhive.darkest.space/state-<service>` for each service whose data the
cluster keeps: `nats` and `ci-metrics`, each when enabled. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
cluster keeps: `nats`, `ci-metrics` and `victorialogs`, each when enabled. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
- `hyperhive.darkest.space/entry`: the node the hosts' DNS points at.
- `svccontroller.k3s.cattle.io/enablelb`: with it on any node, the
service load balancer binds a published port on the labelled nodes

View file

@ -125,19 +125,21 @@ let
];
};
# The swarm services that run in the cluster. `unit` is the evaluated
# systemd unit the host runs today; nothing reads it unless `enable` holds.
# The swarm services that run in the cluster. `unit` is an evaluated systemd
# unit, or the `serviceConfig`, `environment` and `path` of one; nothing reads
# it unless `enable` holds.
# `healthEnv` names the variable that binds the daemon's /healthz and
# /readyz listener. `publicCredentials` maps the ids of the credentials that
# hold a public CA file to their key in the CA ConfigMap, and `publicFiles`
# the paths the unit names that hold one to theirs. `listener`, where a
# service has one, is the TCP port a Service publishes in the cluster and the
# directory the pod's init container writes the leaf to.
# service has one, is the TCP port a Service publishes and the directory the
# pod's init container writes the leaf to; without a `tlsDir` it is plain HTTP
# and no leaf is issued. `probe` is the path a service without a `healthEnv` is
# probed on, and `fsGroupChangePolicy` the pod's setting of that name.
# `ephemeralState` gives a service an `emptyDir` in place of a claim for its
# state directory: what it keeps there is re-derived at start. A pod starts on
# whatever volume it gets.
# `otlp` is where the pod pushes
# its telemetry: `"hive"` is the hive collector. A swarm-tier producer is
# `otlp` is where the pod pushes its telemetry: `"hive"` is the hive collector. A swarm-tier producer is
# `"own"` and keeps the route its unit names, because the hive collector
# stamps the `hive` label on what it forwards and a swarm-level series must
# not carry one (../swarm-otel.nix, the swarm tier's own pipeline).
@ -255,6 +257,44 @@ let
};
otlp = "own";
};
# The log store: the VictoriaLogs daemon alone, on a static local volume
# that is the old container's data directory. It holds no store identity
# and pushes no telemetry; its own `/metrics` is scraped through the
# gateway.
swarm-victorialogs = {
inherit (deployCfg.victorialogs) enable package unit;
daemon = "victoria-logs";
kind = "Deployment";
healthEnv = null;
probe.path = "/health";
etcFiles = [ ];
publicCredentials = { };
listener.port = deployCfg.victorialogs.servicePort;
localState = {
service = "victorialogs";
hostDir = deployCfg.victorialogs.hostDataDir;
};
# The first start gives the pod's group the tree the old container wrote;
# a later one looks at the root only.
fsGroupChangePolicy = "OnRootMismatch";
otlp = "none";
};
# The two `auth_request` responders of the log store's gateway vhost, which
# log in to the store under one role. They keep no state, so they run on any
# node. The Grafana responder is the second container of the pod, in `pod`.
swarm-logs-auth = {
inherit (deployCfg.victorialogs) enable;
package = deployCfg.victorialogs.authPackage;
unit = deployCfg.victorialogs.authUnit;
inherit (deployCfg.victorialogs) pod;
kind = "Deployment";
healthEnv = "SWARM_LOGS_AUTH_HEALTH_ADDR";
etcFiles = [ ];
publicCredentials."bao-ca.pem" = baoServerCaKey;
listener.port = deployCfg.victorialogs.authServicePort;
egress = [ "store" ];
otlp = "none";
};
};
# Where a pod pushes telemetry. A `"hive"` service pushes to the hive
@ -508,6 +548,9 @@ let
sc = unit.serviceConfig;
listener = svc.listener or { };
# A listener with a `tlsDir` serves TLS with a leaf the pod issues; one
# without serves plain HTTP, for a caller that is the node.
listenerTls = listener ? tlsDir;
publicFiles = svc.publicFiles or { };
daemon = svc.daemon or name;
baoRole = svc.baoRole or name;
@ -594,7 +637,7 @@ let
++ lib.optional (runtimeDir != null) runtimeDir
++ lib.optional (stateDir != null) stateDir
++ lib.attrNames publicFiles
++ lib.optional (listener != { }) listener.tlsDir
++ lib.optional listenerTls listener.tlsDir
++ map (f: "/etc/${f}") svc.etcFiles;
under = root: v: v == root || lib.hasPrefix "${root}/" v;
unmounted = lib.filterAttrs (_: v: lib.hasPrefix "/" v && !(lib.any (r: under r v) mountRoots)) env;
@ -690,7 +733,7 @@ let
name = "ca-trust";
configMap.name = caConfigMap;
}
++ lib.optional (listener != { }) {
++ lib.optional listenerTls {
name = "tls";
# In memory: the leaf's key never reaches the node's disk.
emptyDir.medium = "Memory";
@ -745,7 +788,7 @@ let
subPath = publicFiles.${path};
readOnly = true;
}) (lib.attrNames publicFiles)
++ lib.optional (listener != { }) tlsMount
++ lib.optional listenerTls tlsMount
++ lib.optional (runtimeDir != null) {
name = "runtime";
mountPath = runtimeDir;
@ -824,6 +867,24 @@ let
}
// lib.optionalAttrs (lib.tail execWords != [ ]) { args = lib.tail execWords; }
// lib.optionalAttrs (ports != [ ]) { inherit ports; }
# A daemon that has no health variable of ours (a third-party one) is
# probed on one path of its listener.
// lib.optionalAttrs (svc ? probe) {
livenessProbe = {
httpGet = {
inherit (svc.probe) path;
port = "api";
};
periodSeconds = 10;
};
readinessProbe = {
httpGet = {
inherit (svc.probe) path;
port = "api";
};
periodSeconds = 10;
};
}
// lib.optionalAttrs (svc.healthEnv != null) {
livenessProbe = {
httpGet = {
@ -906,7 +967,7 @@ let
containers = [
container
]
++ lib.optional (listener != { }) (
++ lib.optional listenerTls (
leafContainer
// {
name = "tls-renew";
@ -923,15 +984,16 @@ let
runAsGroup = serviceUser.gid;
fsGroup = serviceUser.gid;
seccompProfile.type = "RuntimeDefault";
};
}
// lib.optionalAttrs (svc ? fsGroupChangePolicy) { inherit (svc) fsGroupChangePolicy; };
}
// 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;
// lib.optionalAttrs (listenerTls || extra.initContainers != [ ]) {
initContainers = lib.optional listenerTls leafContainer ++ extra.initContainers;
}
// lib.optionalAttrs (extra.hostAliases != [ ]) { inherit (extra) hostAliases; }
// extra.podSpec;
@ -1007,7 +1069,13 @@ let
// lib.optionalAttrs (svc ? egress) {
"${name}/networkpolicy" = networkPolicyOf name svc.egress;
}
// lib.optionalAttrs (listener != { }) (listenerObjects name listener)
// lib.optionalAttrs (listener != { }) (
# A service with an egress policy has the ingress rule in that one.
if svc ? egress then
removeAttrs (listenerObjects name listener) [ "${name}/networkpolicy" ]
else
listenerObjects name listener
)
// lib.optionalAttrs baoLogin {
# Named after the service: the store's jwt role binds this account.
"${name}/serviceaccount" = {
@ -1063,10 +1131,10 @@ 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 svc ? probe && (listener == { } || svc.healthEnv != null) then
fail name "has a probe and no listener, or a health variable as well"
else if svc ? egress && !(lib.all (r: hostPorts ? ${r}) svc.egress) then
fail name "egress names a host service the renderer has no port for (${lib.concatStringsSep ", " (lib.attrNames hostPorts)})"
else if svc ? egress && listener != { } then
fail name "has an egress policy and a listener, which would share one NetworkPolicy"
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
@ -1079,7 +1147,7 @@ let
{
inherit objects image;
# What the pod's other containers run.
extraImages = lib.optional (listener != { }) leafImage ++ extra.images;
extraImages = lib.optional listenerTls leafImage ++ extra.images;
};
enabled = lib.mapAttrs workload (lib.filterAttrs (_: svc: svc.enable) services);