run grafana as a pod in the cluster
The Deployment swarm-grafana replaces the swarm-grafana container: one replica on a static local volume that is the container's data directory, an init container that fetches the OIDC client secret and creates the administrator password, the datasources' bearer and the encryption key in the secret store, and a sidecar that keeps the controller's Viewer token. The datasources reach the stores through the gateway with that bearer, and Grafana's /metrics asks for the stores' kind of credential, which the vhost sends. The five host units, the journal forwarder, its client glue and the unix-socket directory go with the container.
This commit is contained in:
parent
26ef09b0d7
commit
9f62e71dae
1 changed files with 1938 additions and 1953 deletions
|
|
@ -195,10 +195,6 @@ let
|
|||
# changes (../host-modules/lib/refresh-consumer.nix), each on a fixture
|
||||
# that renders it.
|
||||
storeRefreshed = [
|
||||
{
|
||||
unit = "swarm-bao-grafana-oidc";
|
||||
machine = allLocal;
|
||||
}
|
||||
{
|
||||
unit = "swarm-bao-otel-oidc";
|
||||
machine = allLocal;
|
||||
|
|
@ -1284,7 +1280,7 @@ let
|
|||
&& lib.all (n: l.${n}.proxyPass == store) (lib.attrNames prefixes);
|
||||
}
|
||||
{
|
||||
# Grafana's host creates the bearer and its datasource sends it; the
|
||||
# Grafana's init container creates the bearer and its datasource sends it; the
|
||||
# store's responder reads it. Three modules spell the path, and the
|
||||
# store's grants name it twice: if any one drifts, Grafana sends a value
|
||||
# the responder never reads, or one of them is refused by the store.
|
||||
|
|
@ -1294,16 +1290,15 @@ let
|
|||
leaf = "swarm/services/${allLocal.services.hyperhive.swarm.grafana.oidc.clientId}/metrics/bearer";
|
||||
ds =
|
||||
lib.findFirst (d: d.uid == "swarm-victoriametrics") null
|
||||
allLocal.containers.swarm-grafana.config.services.grafana.provision.datasources.settings.datasources;
|
||||
bearerUnit = allLocal.systemd.services.swarm-bao-grafana-metrics-bearer;
|
||||
allLocal.services.hyperhive.deploy.grafana.rendered.provision.datasources.settings.datasources;
|
||||
fetch = allLocal.services.hyperhive.deploy.grafana.rendered.scripts.fetch;
|
||||
metricsPod =
|
||||
allLocal.services.hyperhive.k8s.rendered.services.swarm-metrics-auth.objects."swarm-metrics-auth/deployment".spec.template.spec;
|
||||
s = allLocal.systemd.services;
|
||||
in
|
||||
ds.jsonData.httpHeaderName1 == "Authorization"
|
||||
&& ds.secureJsonData.httpHeaderValue1 == "$__file{/run/swarm-grafana-secrets/metrics-bearer}"
|
||||
&& lib.hasInfix "bao kv put -cas=0 secret/${leaf} value=-" bearerUnit.script
|
||||
&& lib.hasInfix "/run/swarm-grafana-secrets/metrics-bearer \"Bearer $bearer\"" bearerUnit.script
|
||||
&& ds.secureJsonData.httpHeaderValue1 == "$__file{/run/grafana-secrets/metrics-bearer}"
|
||||
&& lib.hasInfix "put metrics-bearer \"Bearer $(seeded secret/${leaf})\"" fetch
|
||||
&& builtins.elem leaf (lib.findFirst (c: c.name == "grafana-auth") null metricsPod.containers).args
|
||||
&& lib.hasInfix "path \"secret/data/${leaf}\" {\n capabilities = [\"read\"]\n}" s.swarm-bao-metrics-auth-policy.script
|
||||
&& lib.hasInfix "path \"secret/data/${leaf}\" {\n capabilities = [\"create\", \"read\"]\n}" s.swarm-bao-grafana-oidc-policy.script;
|
||||
|
|
@ -1316,7 +1311,7 @@ let
|
|||
ok =
|
||||
let
|
||||
datasources =
|
||||
allLocal.containers.swarm-grafana.config.services.grafana.provision.datasources.settings.datasources;
|
||||
allLocal.services.hyperhive.deploy.grafana.rendered.provision.datasources.settings.datasources;
|
||||
metrics = lib.findFirst (d: d.uid == "swarm-victoriametrics") null datasources;
|
||||
logs = lib.findFirst (d: d.uid == "swarm-victorialogs") null datasources;
|
||||
leaf = "swarm/services/${allLocal.services.hyperhive.swarm.grafana.oidc.clientId}/metrics/bearer";
|
||||
|
|
@ -1494,7 +1489,7 @@ let
|
|||
# The controls: the match finds the sockets the gateway's vhosts still
|
||||
# dial, and the predicate flags a unit that is exactly the hazard and
|
||||
# passes one that is not.
|
||||
lib.elem "swarm-grafana" upstreamDirs
|
||||
lib.elem "swarm-authelia" upstreamDirs
|
||||
&& lib.elem "swarm-otel" upstreamDirs
|
||||
&& hidden {
|
||||
DynamicUser = true;
|
||||
|
|
@ -2862,11 +2857,11 @@ let
|
|||
{
|
||||
# Control: a store fetch with no timer still renders `RemainAfterExit`,
|
||||
# so the cases below read a real value rather than a missing one.
|
||||
name = "Grafana's admin-password fetch stays active after it exits and has no timer";
|
||||
name = "the store credential unit stays active after it exits and has no timer";
|
||||
ok =
|
||||
allLocal.systemd.services ? swarm-bao-grafana-admin
|
||||
&& remainsAfterExit allLocal.systemd.services.swarm-bao-grafana-admin
|
||||
&& !(allLocal.systemd.timers ? swarm-bao-grafana-admin);
|
||||
allLocal.systemd.services ? swarm-bao-store-auth
|
||||
&& remainsAfterExit allLocal.systemd.services.swarm-bao-store-auth
|
||||
&& !(allLocal.systemd.timers ? swarm-bao-store-auth);
|
||||
}
|
||||
{
|
||||
# A timer whose unit does not exist fails to load, so each timer is
|
||||
|
|
@ -2949,7 +2944,6 @@ let
|
|||
"swarm-authelia"
|
||||
"swarm-bao"
|
||||
"swarm-builder"
|
||||
"swarm-grafana"
|
||||
"swarm-otel"
|
||||
]
|
||||
&& lib.all (carries allLocal) names
|
||||
|
|
|
|||
Loading…
Reference in a new issue