k8s: deploy.ci-metrics.runtime moves the CI run poller between its timer and the cluster
This commit is contained in:
parent
49406498a7
commit
6512aaa3e9
2 changed files with 351 additions and 107 deletions
|
|
@ -74,8 +74,12 @@ let
|
|||
# which the kubelet cannot probe. `publicCredentials` maps the ids of the
|
||||
# credentials that hold a public CA file to their key in the CA ConfigMap.
|
||||
# `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 that
|
||||
# runs the service when it is `"host"`.
|
||||
# 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
|
||||
# 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).
|
||||
services = {
|
||||
swarm-controller = {
|
||||
inherit (deployCfg.swarm-controller) enable package;
|
||||
|
|
@ -84,6 +88,7 @@ let
|
|||
healthEnv = null;
|
||||
etcFiles = [ "hyperhive/swarm-controller.json" ];
|
||||
publicCredentials = { };
|
||||
otlp = "hive";
|
||||
switch = null;
|
||||
};
|
||||
swarm-notify-router = {
|
||||
|
|
@ -93,6 +98,7 @@ let
|
|||
healthEnv = "SWARM_NOTIFY_ROUTER_HEALTH_ADDR";
|
||||
etcFiles = [ ];
|
||||
publicCredentials.notify-router-bao-server-ca = baoServerCaKey;
|
||||
otlp = "hive";
|
||||
switch = {
|
||||
inherit (deployCfg.notify-router) runtime;
|
||||
hostUnit = "container@swarm-notify-router.service";
|
||||
|
|
@ -105,6 +111,7 @@ let
|
|||
healthEnv = "SWARM_STT_HEALTH_ADDR";
|
||||
etcFiles = [ ];
|
||||
publicCredentials.stt-bao-server-ca = baoServerCaKey;
|
||||
otlp = "hive";
|
||||
switch = {
|
||||
inherit (deployCfg.stt) runtime;
|
||||
hostUnit = "container@swarm-stt.service";
|
||||
|
|
@ -112,21 +119,32 @@ let
|
|||
};
|
||||
swarm-ci-metrics = {
|
||||
inherit (deployCfg.ci-metrics) enable package;
|
||||
unit = config.systemd.services.swarm-ci-metrics;
|
||||
timer = config.systemd.timers.swarm-ci-metrics;
|
||||
unit = deployCfg.ci-metrics.unit;
|
||||
timer = deployCfg.ci-metrics.timer;
|
||||
kind = "CronJob";
|
||||
healthEnv = null;
|
||||
etcFiles = [ ];
|
||||
publicCredentials = { };
|
||||
switch = null;
|
||||
publicCredentials."bao-ca.pem" = baoServerCaKey;
|
||||
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"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Where a pod pushes telemetry: the hive collector, by the name the node's
|
||||
# CoreDNS answers with the bridge address (./host-services.nix). A unit's own
|
||||
# endpoint is a loopback forwarder or a gateway route that needs a token, and
|
||||
# a pod has neither. `otlpEndpointVars` are the variables a unit may name its
|
||||
# endpoint in; the first is the standard one and is always set.
|
||||
# Where a pod pushes telemetry. A `"hive"` service pushes to the hive
|
||||
# collector, by the name the node's CoreDNS answers with the bridge address
|
||||
# (./host-services.nix): a unit's own endpoint is a loopback forwarder or a
|
||||
# gateway route that needs a token, and a pod has neither. An `"own"` service
|
||||
# keeps its unit's endpoint, a swarm route it logs in to by itself.
|
||||
# `otlpEndpointVars` are the variables a unit may name its endpoint in; the
|
||||
# first is the standard one and is always set for a `"hive"` service.
|
||||
otelCfg = hyperhiveCfg.otel;
|
||||
collectorEndpoint = "http://${otelCfg.collector.host}:${toString hyperhiveCfg.swarm.hiveOtel.collectorPort}";
|
||||
otlpEndpointVars = [
|
||||
|
|
@ -134,8 +152,8 @@ let
|
|||
"SWARM_CI_METRICS_OTLP_ENDPOINT"
|
||||
];
|
||||
podOtlpEnv =
|
||||
unitEnv:
|
||||
lib.optionalAttrs otelCfg.collector.enable (
|
||||
svc: unitEnv:
|
||||
lib.optionalAttrs (svc.otlp == "hive" && otelCfg.collector.enable) (
|
||||
lib.genAttrs (lib.filter (
|
||||
n: n == "OTEL_EXPORTER_OTLP_ENDPOINT" || unitEnv ? ${n}
|
||||
) otlpEndpointVars) (_: collectorEndpoint)
|
||||
|
|
@ -289,7 +307,7 @@ let
|
|||
else
|
||||
unitEnv
|
||||
)
|
||||
// podOtlpEnv unitEnv
|
||||
// podOtlpEnv svc unitEnv
|
||||
// lib.optionalAttrs (runtimeDir != null) { RUNTIME_DIRECTORY = runtimeDir; }
|
||||
// lib.optionalAttrs (stateDir != null) { STATE_DIRECTORY = stateDir; }
|
||||
// lib.optionalAttrs (svc.healthEnv != null) {
|
||||
|
|
@ -628,6 +646,8 @@ let
|
|||
in
|
||||
if !(lib.all (p: lib.elem (lib.getName p) nixosDefaultPath) unit.path) then
|
||||
fail name "the unit puts packages on PATH, which the image does not carry"
|
||||
else if svc.otlp == "own" && !(lib.any (n: unitEnv ? ${n}) otlpEndpointVars) then
|
||||
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 lib.head execWords != entrypoint then
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
# Which of a service's two homes runs it: its host unit, or its objects in the
|
||||
# cluster. A service with a `runtime` option (`swarm-notify-router`) is on the
|
||||
# cluster when the option says `"k8s"`, and then only: its host unit is gone
|
||||
# from the configuration, and its manifests are in `services.k3s.manifests`.
|
||||
# cluster. A service with a `runtime` option is on the cluster when the option
|
||||
# says `"k8s"`, and then only: its host unit or units are gone from the
|
||||
# configuration, and its manifests are in `services.k3s.manifests`.
|
||||
# The cluster does not remove what a manifest created once the manifest is
|
||||
# gone, so a service back on the host has its objects deleted before its host
|
||||
# unit starts. docs/4-implementation/k8s/runtime.md has the design.
|
||||
|
|
@ -91,8 +91,8 @@ in
|
|||
};
|
||||
})
|
||||
|
||||
# A service back on the host first loses its objects. The unit that
|
||||
# starts the host copy requires this one, so the pod is gone before the
|
||||
# A service back on the host first loses its objects. The units that
|
||||
# start the host copy require this one, so the pod is gone before the
|
||||
# host copy starts, and a failure here leaves the host copy stopped.
|
||||
#
|
||||
# Its marker is the manifest's link in the cluster's manifests
|
||||
|
|
@ -107,8 +107,8 @@ in
|
|||
lib.nameValuePair "${name}-k8s-prune" {
|
||||
description = "delete ${name}'s objects from the cluster before its host unit starts";
|
||||
after = [ "k3s.service" ];
|
||||
before = [ s.hostUnit ];
|
||||
requiredBy = [ s.hostUnit ];
|
||||
before = lib.toList s.hostUnit;
|
||||
requiredBy = lib.toList s.hostUnit;
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue