Watch
0
0
Fork
You've already forked hyperhive
0

require k8s: swarm services with a pod run in the cluster only

This commit is contained in:
atlas 2026-11-26 00:36:09 +01:00 • committed by maia
commit 57d40ae8ea

View file

@ -43,7 +43,7 @@ let
hiveClientCaKey = "hive-client-ca.pem";
servicesRootKey = "swarm-services-root.pem";
controllerCfg = deployCfg.swarm-controller;
controllerOnCluster = controllerCfg.enable && controllerCfg.runtime == "k8s";
controllerOnCluster = controllerCfg.enable;
controllerTcp = hyperhiveCfg.swarm.controller.tcp;
natsCfg = deployCfg.nats;
labels = import ./labels.nix;
@ -81,11 +81,9 @@ let
];
# The controller's listener leaf: its pod issues the leaf itself, from the
# store, with its ServiceAccount token, as the host's
# `swarm-controller-tls.service` does with its certificate
# (../lib/swarm-controller-tls-issue.nix is the one script). An init
# container writes it before the daemon starts and a second container renews
# it, both into an emptyDir only the pod holds.
# store, with its ServiceAccount token (../lib/swarm-controller-tls-issue.nix is
# the script). An init container writes it before the daemon starts and a
# second container renews it, both into an emptyDir only the pod holds.
tlsIssue = import ../lib/swarm-controller-tls-issue.nix { inherit lib config; };
leafTools = [
baoDeployCfg.package
@ -103,8 +101,6 @@ let
${tlsIssue.script {
login = "bao write -field=token auth/${podAuth.mount}/login role=swarm-controller jwt=@${podAuth.tokenFile}";
credential = "ServiceAccount token";
group = null;
createDir = false;
}}
'';
# The host's timer runs the same check daily: the script leaves a leaf
@ -140,9 +136,7 @@ let
# `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.
# `switch` is null for a service that always runs on the host, and for one
# with a `runtime` option names the option's value and the host unit or units
# that run the service when it is `"host"`. `otlp` is where the pod pushes
# `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
@ -179,10 +173,6 @@ let
# (../glue-controller-env.nix, `otel_http_client.rs`).
otlp = "own";
ephemeralState = true;
switch = {
inherit (controllerCfg) runtime;
hostUnit = "swarm-controller.service";
};
};
# The queue and its auth-callout responder are one pod: the responder is the
# daemon below, and the server (with its exporter) is `pod`'s.
@ -198,10 +188,6 @@ let
etcFiles = [ ];
publicCredentials."bao-ca.pem" = baoServerCaKey;
otlp = "none";
switch = {
inherit (natsCfg) runtime;
hostUnit = "container@swarm-nats.service";
};
};
swarm-notify-router = {
inherit (deployCfg.notify-router) enable package;
@ -211,10 +197,6 @@ let
etcFiles = [ ];
publicCredentials.notify-router-bao-server-ca = baoServerCaKey;
otlp = "hive";
switch = {
inherit (deployCfg.notify-router) runtime;
hostUnit = "container@swarm-notify-router.service";
};
};
swarm-stt = {
inherit (deployCfg.stt) enable package;
@ -237,10 +219,6 @@ let
# Stands in for the unit's `PrivateUsers`: the decoder reads audio that
# strangers sent.
hostUsers = false;
switch = {
inherit (deployCfg.stt) runtime;
hostUnit = "container@swarm-stt.service";
};
};
swarm-review-classifier = {
inherit (deployCfg.review-classifier) enable package;
@ -250,10 +228,6 @@ let
etcFiles = [ ];
publicCredentials.review-classifier-bao-server-ca = baoServerCaKey;
otlp = "hive";
switch = {
inherit (deployCfg.review-classifier) runtime;
hostUnit = "container@swarm-review-classifier.service";
};
};
swarm-claude-login = {
inherit (deployCfg.claude-login) enable package;
@ -263,10 +237,6 @@ let
etcFiles = [ ];
publicCredentials.claude-login-bao-server-ca = baoServerCaKey;
otlp = "hive";
switch = {
inherit (deployCfg.claude-login) runtime;
hostUnit = "container@swarm-claude-login.service";
};
};
swarm-ci-metrics = {
inherit (deployCfg.ci-metrics) enable package;
@ -284,15 +254,6 @@ let
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.
switch = {
inherit (deployCfg.ci-metrics) runtime;
hostUnit = [
"swarm-ci-metrics.timer"
"swarm-ci-metrics.service"
];
};
};
};
@ -390,7 +351,7 @@ let
protocol = "TCP";
inherit port;
};
queueOnCluster = natsCfg.enable && natsCfg.runtime == "k8s";
queueOnCluster = natsCfg.enable;
in
{
apiVersion = "networking.k8s.io/v1";
@ -1148,15 +1109,12 @@ in
# for the others to pull from it.
images = lib.unique (lib.concatMap (w: [ w.image ] ++ w.extraImages) (lib.attrValues enabled));
# What ./runtime.nix moves services with. `switches` holds the services that
# have a runtime option and is cheap to read: it names the units that a
# switch adds or removes, so it cannot depend on rendering a unit. `services`
# holds the objects. `caSources` is the host file behind each key of the CA
# ConfigMap, null where there is none.
switches = lib.mapAttrs (_: svc: svc.switch) (
lib.filterAttrs (_: svc: svc.enable && svc.switch != null) services
);
# The services whose pods run in a user namespace. Cheap to read, like `switches`.
# What ./runtime.nix applies. `serviceNames` and `userNamespaces` are cheap to
# read: they force no unit, which ./runtime.nix's own units depend on.
# `services` holds the objects. `caSources` is the host file behind each key of
# the CA ConfigMap, null where there is none.
serviceNames = lib.attrNames (lib.filterAttrs (_: svc: svc.enable) services);
userNamespaces = lib.attrNames (
lib.filterAttrs (_: svc: svc.enable && svc ? hostUsers && !svc.hostUsers) services
);