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 mara
commit 052b559196

View file

@ -5,8 +5,9 @@
#
# The main node holds the images of the services ./render.nix renders and
# shares them with the nodes that join through k3s's embedded registry mirror
# of the images' registry host. No service's objects are applied until its `runtime` is `k8s`
# (./runtime.nix): until then its host unit runs.
# of the images' registry host. Every swarm service this host enables runs on it,
# so enabling one turns the node on, and a host that turns the node off while it
# enables one fails at evaluation (./runtime.nix applies the manifests).
{
config,
lib,
@ -118,9 +119,22 @@ let
'') nodePorts
) addresses;
# The services whose data the module keeps in the cluster: those with a
# `runtime` that is `k8s`. Each puts its state label on this node.
stateful = lib.filterAttrs (_: svc: svc.enable && svc.runtime == "k8s") {
# The swarm services that run in the cluster, by the name of their
# `deploy.<name>.enable` option.
swarmServices = [
"notify-router"
"stt"
"ci-metrics"
"review-classifier"
"claude-login"
"nats"
"swarm-controller"
];
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;
};
in
@ -129,16 +143,17 @@ in
enable = lib.mkOption {
type = lib.types.bool;
default = false;
defaultText = lib.literalMD "`true` where the host enables a swarm service that runs in the cluster, else `false`";
description = ''
Run a k3s server on this host, the cluster's main node, with the images of the
swarm services that run in the cluster loaded into it, and render
their manifests (`services.hyperhive.k8s.enable`). Set it on the host
that runs the swarm's services, which is the one
`services.hyperhive.deploy.singleHostSwarm` names.
their manifests (`services.hyperhive.k8s.enable`).
The cluster starts with no hyperhive workload: a service keeps
running as its systemd unit unless its `runtime` option is `k8s`.
Its secrets are encrypted at rest, and traefik and metrics-server
Defaults on where this host enables any swarm service that runs in the
cluster: `deploy.notify-router`, `stt`, `ci-metrics`, `review-classifier`,
`claude-login`, `nats` and `swarm-controller`, which
`services.hyperhive.deploy.singleHostSwarm` and `allSwarmServices` turn
on. Setting it to `false` on such a host fails the evaluation. Its secrets are encrypted at rest, and traefik and metrics-server
stay off. Pods and services take their
addresses from {option}`services.hyperhive.deploy.k8s.podCidr` and
{option}`services.hyperhive.deploy.k8s.serviceCidr`. The firewall
@ -241,7 +256,7 @@ in
labels.loadBalancerLabel
] (_: "true")
// lib.mapAttrs' (name: _: lib.nameValuePair (labels.stateLabel name) "true") stateful;
defaultText = lib.literalMD "computed from the services whose `runtime` is `k8s`";
defaultText = lib.literalMD "computed from the enabled services whose data the cluster keeps";
description = ''
The labels this node carries, which the module sets with
`services.k3s.nodeLabel`. The pods and volumes that need a node select
@ -249,17 +264,16 @@ in
none of those pods.
- `hyperhive.darkest.space/state-<service>` for each service whose data the
cluster keeps: `nats` and `ci-metrics`, each when its `runtime` is
`k8s`. A volume's `nodeAffinity` and the pod's `nodeSelector` name it.
cluster keeps: `nats` and `ci-metrics`, 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
only, so a joined node does not publish the queue's port.
k3s puts these on the node's object at every start, registered or not.
It never takes one off: a label left from a service that has moved
back to `host` stays and does nothing, and `kubectl label node <name>
<label>-` removes one.
It never takes one off: a label left from a service that is disabled
stays and does nothing, and `kubectl label node <name> <label>-`
removes one.
'';
};
@ -336,6 +350,24 @@ in
};
config = lib.mkMerge [
{
services.hyperhive.deploy.k8s.enable = lib.mkDefault (enabledServices != [ ] && cfg.join == null);
assertions = [
{
assertion = cfg.enable || cfg.join != null || enabledServices == [ ];
message = ''
services.hyperhive.deploy.k8s.enable is false, and this host enables
swarm services that run only in the cluster: ${
lib.concatMapStringsSep ", " (n: "deploy.${n}.enable") enabledServices
}.
Set services.hyperhive.deploy.k8s.enable to true (it is the default
where one is enabled) or disable those services on this host.
'';
}
];
}
(lib.mkIf cfg.enable {
assertions = [
{