require k8s: swarm services with a pod run in the cluster only
This commit is contained in:
parent
23865cb223
commit
44670249b6
1 changed files with 1044 additions and 3125 deletions
|
|
@ -7,9 +7,9 @@
|
|||
# sees and pushes each newly finished run's duration and queue wait to the
|
||||
# swarm collector, stamped at the run's end. The first pass, with no cursor in
|
||||
# the state directory, walks every run back to the first. docs/4-implementation/swarm/ci-metrics.md
|
||||
# has the design. With `deploy.ci-metrics.runtime = "k8s"` the host has neither
|
||||
# the service nor the timer: the poller is a CronJob in the host's cluster,
|
||||
# rendered from the unit and timer below (docs/4-implementation/k8s/runtime.md).
|
||||
# has the design. The poller is a CronJob in the host's cluster, rendered from
|
||||
# the unit and timer below (docs/4-implementation/k8s/runtime.md); the host runs
|
||||
# neither.
|
||||
#
|
||||
# It reaches the forge, authelia, the store and the collector by name, so
|
||||
# nothing here asks which host runs any of them. Its one credential on disk is
|
||||
|
|
@ -59,28 +59,21 @@ let
|
|||
"bao-ca.pem" = baoDeploy.serverCaFile;
|
||||
};
|
||||
|
||||
onK8s = cfg.runtime == "k8s";
|
||||
|
||||
# Where the host unit's `StateDirectory` is: `DynamicUser` keeps it under
|
||||
# `/var/lib/private`, so the pod's volume is the directory the unit uses.
|
||||
hostStateDir = "/var/lib/private/${unit}";
|
||||
|
||||
# `hostUnit`: a host service, so the bundle reads the host CA path and waits
|
||||
# on `hive-tls-ca.service`. `enable`: `imports` is unconditional, so without
|
||||
# it a host with the poller off gets the bundle unit and an `ExecStart`-less
|
||||
# `swarm-ci-metrics` service.
|
||||
trustBundle =
|
||||
enable:
|
||||
caTrust.trustBundle {
|
||||
inherit pkgs enable;
|
||||
name = unit;
|
||||
consumers = [ unit ];
|
||||
hostUnit = true;
|
||||
};
|
||||
# `hostUnit`: the bundle reads the host CA path and waits on
|
||||
# `hive-tls-ca.service`.
|
||||
trustBundle = caTrust.trustBundle {
|
||||
inherit pkgs;
|
||||
name = unit;
|
||||
consumers = [ unit ];
|
||||
hostUnit = true;
|
||||
};
|
||||
|
||||
# The poller's service and timer. The host runs them; with the poller in the
|
||||
# cluster they are only the source of the CronJob (`deploy.ci-metrics.unit`
|
||||
# and `.timer`).
|
||||
# The poller's service and timer, the source of the CronJob
|
||||
# (`deploy.ci-metrics.unit` and `.timer`).
|
||||
unitModule = {
|
||||
systemd.services.${unit} = {
|
||||
description = "push finished forge CI runs to the swarm metrics store";
|
||||
|
|
@ -133,8 +126,7 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
# The unit and timer evaluated as a host evaluates them, for a host that
|
||||
# does not run them.
|
||||
# The unit and timer evaluated as a host evaluates them.
|
||||
podSystem =
|
||||
(import "${pkgs.path}/nixos/lib/eval-config.nix" {
|
||||
modules = [
|
||||
|
|
@ -153,15 +145,13 @@ let
|
|||
};
|
||||
}
|
||||
)
|
||||
(trustBundle true)
|
||||
trustBundle
|
||||
unitModule
|
||||
];
|
||||
system = null;
|
||||
}).config;
|
||||
in
|
||||
{
|
||||
imports = [ (trustBundle (cfg.enable && !onK8s)) ];
|
||||
|
||||
options.services.hyperhive.swarm.ci-metrics.clientId = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
|
|
@ -200,30 +190,6 @@ in
|
|||
description = "The CI run poller package.";
|
||||
};
|
||||
|
||||
runtime = lib.mkOption {
|
||||
type = lib.types.enum [
|
||||
"host"
|
||||
"k8s"
|
||||
];
|
||||
default = "host";
|
||||
description = ''
|
||||
Where the CI run poller runs: `host` as the `swarm-ci-metrics` service
|
||||
and timer, or `k8s` as a CronJob in this host's cluster
|
||||
({option}`services.hyperhive.deploy.k8s.enable`), which the host's
|
||||
configuration must enable. A switch moves the poller: the service and
|
||||
timer go and the CronJob is applied, or the CronJob is deleted and the
|
||||
service and timer return, so one poller runs at any time. Its cursor is
|
||||
in the service's state directory on the host, and the cluster's volume
|
||||
for it is on that directory, so a switch moves the process and not the
|
||||
cursor. The pod runs on the node with the
|
||||
`hyperhive.darkest.space/state-ci-metrics` label, which the node
|
||||
module sets, and starts with no gate.
|
||||
|
||||
The poller keeps pushing to the swarm collector's route of its own,
|
||||
not to the hive collector the cluster's other pods push to.
|
||||
'';
|
||||
};
|
||||
|
||||
hostStateDir = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
readOnly = true;
|
||||
|
|
@ -239,11 +205,10 @@ in
|
|||
type = lib.types.raw;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default = if onK8s then podSystem.systemd.services.${unit} else config.systemd.services.${unit};
|
||||
default = podSystem.systemd.services.${unit};
|
||||
description = ''
|
||||
The poller's evaluated systemd service, which the cluster's CronJob is
|
||||
rendered from (./k8s/render.nix). It is the service the host runs, or,
|
||||
with the poller in the cluster, the same service evaluated alone.
|
||||
rendered from (./k8s/render.nix). The host does not run it.
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
@ -251,7 +216,7 @@ in
|
|||
type = lib.types.raw;
|
||||
readOnly = true;
|
||||
internal = true;
|
||||
default = if onK8s then podSystem.systemd.timers.${unit} else config.systemd.timers.${unit};
|
||||
default = podSystem.systemd.timers.${unit};
|
||||
description = ''
|
||||
The poller's evaluated systemd timer, which the CronJob's schedule is
|
||||
rendered from, taken as {option}`unit` is.
|
||||
|
|
@ -260,19 +225,6 @@ in
|
|||
};
|
||||
|
||||
config = lib.mkMerge [
|
||||
{
|
||||
assertions = [
|
||||
{
|
||||
assertion = !onK8s || hyperhiveCfg.deploy.k8s.enable;
|
||||
message = ''
|
||||
services.hyperhive.deploy.ci-metrics.runtime = "k8s" needs the
|
||||
cluster: set services.hyperhive.deploy.k8s.enable on this host, or
|
||||
leave the poller's runtime at "host".
|
||||
'';
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
(lib.mkIf cfg.enable {
|
||||
assertions = [
|
||||
{
|
||||
|
|
@ -297,11 +249,9 @@ in
|
|||
];
|
||||
})
|
||||
|
||||
(lib.mkIf (cfg.enable && !onK8s) unitModule)
|
||||
|
||||
# The pod reaches the store, authelia, the forge and the collector by
|
||||
# name, which the cluster resolves to the hive bridge.
|
||||
(lib.mkIf (cfg.enable && onK8s) {
|
||||
(lib.mkIf cfg.enable {
|
||||
services.hyperhive.network.enable = lib.mkDefault true;
|
||||
|
||||
# The pod's local volume needs its directory to exist before the pod
|
||||
|
|
|
|||
Loading…
Reference in a new issue