grafana pod: open the database the earlier container left
The pod's volume is the earlier container's data directory, and the NixOS grafana module keeps its database at `<dataDir>/data/grafana.db`. The pod set `paths.data` to the directory itself, so it opened a new, empty `grafana.db` beside the carried one, and the secret-key guard read that new file. Datasources with secrets, API tokens, hand-made dashboards, users and teams of a switched host were orphaned. `paths.data` and the guard's database path are now `<dataDir>/data`. The VM test's earlier Grafana keeps its database in the NixOS layout, and the test asserts the carried file is the only `grafana.db` in the volume. Closes #6979
This commit is contained in:
parent
42199dfa76
commit
fe6221138c
1 changed files with 41 additions and 8 deletions
|
|
@ -604,6 +604,8 @@ pkgs.testers.runNixOSTest {
|
|||
mkdir -p ${grafanaDir}
|
||||
chown ${legacyGrafanaUser}:${legacyGrafanaUser} ${grafanaDir}
|
||||
chmod 0700 ${grafanaDir}
|
||||
mkdir -p ${grafanaDir}/data
|
||||
chown ${legacyGrafanaUser}:${legacyGrafanaUser} ${grafanaDir}/data
|
||||
mkdir -p ${legacyKeyDir}
|
||||
chown ${legacyGrafanaUser}:${legacyGrafanaUser} ${legacyKeyDir}
|
||||
chmod 0700 ${legacyKeyDir}
|
||||
|
|
@ -611,7 +613,9 @@ pkgs.testers.runNixOSTest {
|
|||
RuntimeDirectory = "grafana-legacy";
|
||||
};
|
||||
environment = {
|
||||
GF_PATHS_DATA = grafanaDir;
|
||||
# The NixOS grafana module's layout, which is what the earlier
|
||||
# container left on a real host.
|
||||
GF_PATHS_DATA = "${grafanaDir}/data";
|
||||
GF_PATHS_LOGS = "/run/grafana-legacy";
|
||||
GF_PATHS_PLUGINS = "/run/grafana-legacy/plugins";
|
||||
GF_PATHS_PROVISIONING = "/run/grafana-legacy/provisioning";
|
||||
|
|
@ -660,7 +664,7 @@ pkgs.testers.runNixOSTest {
|
|||
fi
|
||||
kill -TERM "$pid"
|
||||
wait "$pid" || true
|
||||
test -s ${grafanaDir}/grafana.db
|
||||
test -s ${grafanaDir}/data/grafana.db
|
||||
test -s ${legacyKeyFile}
|
||||
'';
|
||||
};
|
||||
|
|
@ -1812,7 +1816,12 @@ pkgs.testers.runNixOSTest {
|
|||
pvc = json.loads(kube(machine, f"get pvc {GRAFANA}-store -o json"))
|
||||
assert pvc["status"]["phase"] == "Bound" and pvc["spec"]["volumeName"] == pv["metadata"]["name"], pvc
|
||||
assert machine.succeed(f"stat -c %g {GRAFANA_DIR}").strip() == "65532"
|
||||
assert machine.succeed(f"find {GRAFANA_DIR} -name grafana.db -user ${legacyGrafanaUser} -print -quit").strip() != ""
|
||||
# The earlier container's database is where the NixOS module keeps it
|
||||
# (`data/grafana.db`), and it is the only one: a pod that opened its own
|
||||
# beside it would start empty.
|
||||
dbs = machine.succeed(f"find {GRAFANA_DIR} -name grafana.db").split()
|
||||
assert dbs == [f"{GRAFANA_DIR}/data/grafana.db"], dbs
|
||||
assert machine.succeed(f"stat -c %U {dbs[0]}").strip() == "${legacyGrafanaUser}"
|
||||
status = json.loads(kube(machine, f"get pod {grafana_pod} -o json"))
|
||||
main = next(c for c in status["spec"]["containers"] if c["name"] == GRAFANA)
|
||||
assert main["startupProbe"]["failureThreshold"] == 30, main
|
||||
|
|
|
|||
Loading…
Reference in a new issue