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 44670249b6

View file

@ -119,13 +119,16 @@ let
dest = "mirrors/tool";
};
hyperhiveElsewhere = "https://example.invalid/hyperhive";
# A store path: the controller's pod mounts no host path, and carries the files
# its unit names from the store.
markerAvatar = pkgs.writeText "marker-avatar.png" "marker";
controllerWithMirrors = hiveWithController {
deploy.swarm-controller.enable = true;
deploy.forgejo.enable = true;
deploy.forgejo.mirrors = [ aMirror ];
deploy.forgejo.actionsFromSelf = false;
deploy.forgejo.hyperhiveUpstream = null;
deploy.swarm-controller.configOrgAvatarPng = "/etc/marker-avatar.png";
deploy.swarm-controller.configOrgAvatarPng = markerAvatar;
};
mirrorsNoController = hive {
deploy.forgejo.enable = true;
@ -198,13 +201,8 @@ let
"swarm-bao"
"swarm-builder"
"swarm-ci-runner"
"swarm-claude-login"
"swarm-grafana"
"swarm-nats"
"swarm-notify-router"
"swarm-otel"
"swarm-review-classifier"
"swarm-stt"
"swarm-victorialogs"
"swarm-victoriametrics"
];
@ -265,7 +263,6 @@ let
"forgejo.service"
"gitea-runner-swarm.service"
"grafana.service"
"nats.service"
"opentelemetry-collector.service"
"tuwunel.service"
"victorialogs.service"
@ -345,12 +342,14 @@ let
lib.length (lib.attrNames es) == 8 && lib.all lib.id (lib.attrValues es);
}
{
# The container is the control that the toggle reaches the module, not
# only the option; `nats` is the control that the switch is on at all.
name = "hosting the swarm's shared services turns on the review classifier";
# The pod runs it, so no container: the unit is the control that the toggle
# reaches the module, not only the option; `nats` is the control that the
# switch is on at all.
name = "hosting the swarm's shared services turns on the review classifier as a pod";
ok =
swarmServicesHere.services.hyperhive.deploy.review-classifier.enable
&& swarmServicesHere.containers ? swarm-review-classifier
&& swarmServicesHere.services.hyperhive.deploy.review-classifier.unit.serviceConfig ? ExecStart
&& !(swarmServicesHere.containers ? swarm-review-classifier)
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
}
{
@ -392,16 +391,14 @@ let
&& swarmServicesBaoElsewhere.services.hyperhive.deploy.nats.enable;
}
{
# Static, not `DynamicUser`: the user is declared in the container and
# the unit names it. `nats` is the control that the switch is on at all.
name = "hosting the swarm's shared services runs the claude login minter in its container as a static user";
# Static, not `DynamicUser`: the unit names the user. `nats` is the control
# that the switch is on at all.
name = "hosting the swarm's shared services runs the claude login minter as a static user";
ok =
let
c = swarmServicesHere.containers.swarm-claude-login.config;
sc = c.systemd.services.swarm-claude-login.serviceConfig;
sc = swarmServicesHere.services.hyperhive.deploy.claude-login.unit.serviceConfig;
in
swarmServicesHere.services.hyperhive.deploy.claude-login.enable
&& c.users.users.swarm-claude-login.isSystemUser
&& sc.User == "swarm-claude-login"
&& !(sc.DynamicUser or false)
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
@ -416,16 +413,14 @@ let
&& swarmServicesBaoElsewhere.services.hyperhive.deploy.nats.enable;
}
{
# Same shape as the minter's: a static user in its own container. `nats`
# is the control that the switch is on at all.
name = "hosting the swarm's shared services runs the notification router in its container as a static user";
# Same shape as the minter's: a static user. `nats` is the control that
# the switch is on at all.
name = "hosting the swarm's shared services runs the notification router as a static user";
ok =
let
c = swarmServicesHere.containers.swarm-notify-router.config;
sc = c.systemd.services.swarm-notify-router.serviceConfig;
sc = swarmServicesHere.services.hyperhive.deploy.notify-router.unit.serviceConfig;
in
swarmServicesHere.services.hyperhive.deploy.notify-router.enable
&& c.users.users.swarm-notify-router.isSystemUser
&& sc.User == "swarm-notify-router"
&& !(sc.DynamicUser or false)
&& swarmServicesHere.services.hyperhive.deploy.nats.enable;
@ -434,11 +429,10 @@ let
name = "hosting the swarm's shared services runs the speech-to-text service as an unprivileged user under a sandbox";
ok =
let
c = swarmServicesHere.containers.swarm-stt.config;
sc = c.systemd.services.swarm-stt.serviceConfig;
unit = swarmServicesHere.services.hyperhive.deploy.stt.unit;
sc = unit.serviceConfig;
in
swarmServicesHere.services.hyperhive.deploy.stt.enable
&& c.users.users.swarm-stt.isSystemUser
&& sc.User == "swarm-stt"
&& !(sc.DynamicUser or false)
&& sc.NoNewPrivileges
@ -447,7 +441,7 @@ let
&& sc.CapabilityBoundingSet == ""
&& sc.MemoryMax == "3G"
&& sc.StateDirectory == "swarm-stt"
&& c.systemd.services.swarm-stt.environment.SWARM_STT_MAX_WAITING == "3";
&& unit.environment.SWARM_STT_MAX_WAITING == "3";
}
{
# dhcpcd without IPv4LL, waiting for IPv4: `network-online` is a lease.
@ -466,11 +460,8 @@ let
lib.hasInfix "noipv4ll" d.extraConfig && d.wait == "ipv4";
fetch = (cfgOf "swarm-builder").systemd.services.swarm-journal-forwarder-oidc;
in
leased "swarm-notify-router"
&& leased "swarm-authelia"
leased "swarm-authelia"
&& lib.hasInfix "nohook resolv.conf" (cfgOf "swarm-authelia").networking.dhcpcd.extraConfig
&& !(lib.hasInfix "noipv4ll" (cfgOf "swarm-nats").networking.dhcpcd.extraConfig)
&& (cfgOf "swarm-nats").networking.dhcpcd.wait == "any"
&& lib.elem "network-online.target" fetch.after
&& lib.elem "network-online.target" fetch.wants;
}
@ -506,8 +497,8 @@ let
ok =
let
claudeOf =
host: container: unit: var:
host.containers.${container}.config.systemd.services.${unit}.environment.${var};
host: service: var:
host.services.hyperhive.deploy.${service}.unit.environment.${var};
pinned = "${pkgs.hello}/bin/claude";
servedClaude =
host:
@ -517,18 +508,13 @@ let
in
servedClaude swarmServicesPinnedClaude == "${pkgs.hello}"
&& servedClaude swarmServicesHere == null
&&
claudeOf swarmServicesPinnedClaude "swarm-claude-login" "swarm-claude-login"
"SWARM_CLAUDE_LOGIN_CLAUDE" == pinned
&&
claudeOf swarmServicesPinnedClaude "swarm-review-classifier" "swarm-review-classifier"
"SWARM_REVIEW_CLASSIFIER_CLAUDE" == pinned
&& claudeOf swarmServicesPinnedClaude "claude-login" "SWARM_CLAUDE_LOGIN_CLAUDE" == pinned
&& claudeOf swarmServicesPinnedClaude "review-classifier" "SWARM_REVIEW_CLASSIFIER_CLAUDE" == pinned
&& lib.hasInfix "claude-code" (
claudeOf swarmServicesHere "swarm-claude-login" "swarm-claude-login" "SWARM_CLAUDE_LOGIN_CLAUDE"
claudeOf swarmServicesHere "claude-login" "SWARM_CLAUDE_LOGIN_CLAUDE"
)
&& lib.hasInfix "claude-code" (
claudeOf swarmServicesHere "swarm-review-classifier" "swarm-review-classifier"
"SWARM_REVIEW_CLASSIFIER_CLAUDE"
claudeOf swarmServicesHere "review-classifier" "SWARM_REVIEW_CLASSIFIER_CLAUDE"
);
}
{
@ -789,7 +775,6 @@ let
"swarm-victorialogs"
"swarm-victoriametrics"
"swarm-otel"
"swarm-nats"
"hive-matrix"
"hive-forge"
]
@ -836,7 +821,7 @@ let
# that lost a container can't pass by comparing fewer of them.
name = "every service container restates its host-side privateNetwork";
ok =
lib.length (lib.attrNames serviceContainers) == 16
lib.length (lib.attrNames serviceContainers) == 11
&& lib.all (
c: c.privateNetwork == (c.config.services.hyperhive.swarmContainer.privateNetwork or null)
) (lib.attrValues serviceContainers);
@ -850,7 +835,7 @@ let
let
shared = lib.filter (c: !c.privateNetwork) (lib.attrValues serviceContainers);
in
lib.length shared == 2
lib.length shared == 1
&& lib.all (
c: !c.config.networking.firewall.enable && !c.config.networking.resolvconf.enable
) shared;
@ -1568,7 +1553,7 @@ let
name = "the org avatar lands on the controller's unit, not hive-c0re's";
ok =
controllerWithMirrors.systemd.services.swarm-controller.environment.SWARM_CONTROLLER_CONFIG_ORG_AVATAR_PNG
== "/etc/marker-avatar.png"
== "${markerAvatar}"
&& !(controllerWithMirrors.systemd.services.hive-c0re.environment ? HIVE_ORG_AVATAR_PNG);
}
{
@ -1596,7 +1581,6 @@ let
"swarm-bao-grafana-metrics-bearer"
"swarm-bao-grafana-secret-key"
"swarm-bao-grafana-controller-token"
"swarm-bao-nats-callout-xkey"
"swarm-bao-ci-runner"
"swarm-bao-otel-oidc"
];
@ -1620,9 +1604,9 @@ let
!(lib.any (n: lib.elem n (s.after ++ s.wants ++ s.requires)) storeUnits);
in
lib.all waits readers
&& lib.length readersHere == 10
&& lib.length readersHere == 9
&& lib.elem "swarm-bao-grafana-admin" readersHere
&& lib.length readersElsewhere == 8
&& lib.length readersElsewhere == 7
&& lib.all namesNoStoreUnit readersElsewhere
&& !(lib.any (u: storeOnlyNoHive.systemd.services ? ${u}) readers);
}