|
1 | 1 | """ |
2 | 2 | Helm template tests for `runner.enabled` (Holmes-only installs). |
3 | | -
|
4 | | -The golden tests pin the rendered chart for values that existing installs use, so any change to |
5 | | -the runner-enabled output shows up as a diff. Regenerate the golden files only for an intended |
6 | | -change to that output: |
7 | | -
|
8 | | - UPDATE_HELM_GOLDEN=1 pytest tests/test_helm_holmes_only.py |
9 | 3 | """ |
10 | 4 | import base64 |
11 | | -import os |
12 | 5 | import shutil |
13 | 6 | import subprocess |
14 | 7 | from pathlib import Path |
|
18 | 11 | import yaml |
19 | 12 |
|
20 | 13 | CHART_PATH = Path(__file__).parent.parent / "helm" / "robusta" |
21 | | -GOLDEN_DIR = Path(__file__).parent / "helm_golden" |
22 | | -HOLMES_VALUES = GOLDEN_DIR / "holmes_values.yaml" |
| 14 | +HOLMES_VALUES = Path(__file__).parent / "holmes_values.yaml" |
23 | 15 | KPS_ALERTMANAGER_SECRET = "charts/kube-prometheus-stack/templates/alertmanager/secret.yaml" |
24 | 16 |
|
25 | 17 | pytestmark = pytest.mark.skipif(shutil.which("helm") is None, reason="helm binary not available") |
26 | 18 |
|
27 | 19 | # Pinned so the output doesn't depend on the helm client's default Kubernetes version. |
28 | 20 | BASE_ARGS = ["--namespace", "robusta", "--kube-version", "1.30.0"] |
29 | 21 |
|
30 | | -GOLDEN_SCENARIOS = { |
31 | | - "default": ["--set", "clusterName=test", "--set", "sinksConfig[0].file_sink.name=test"], |
32 | | - "holmes": ["-f", str(HOLMES_VALUES)], |
33 | | - "openshift": [ |
34 | | - "-f", |
35 | | - str(HOLMES_VALUES), |
36 | | - "--set", |
37 | | - "openshift.enabled=true,openshift.createScc=true,openshift.createPrivilegedScc=true", |
38 | | - ], |
39 | | - "prometheus_stack_alertmanager": [ |
40 | | - "-f", |
41 | | - str(HOLMES_VALUES), |
42 | | - "--set", |
43 | | - "enablePrometheusStack=true", |
44 | | - "-s", |
45 | | - KPS_ALERTMANAGER_SECRET, |
46 | | - ], |
47 | | -} |
48 | | - |
49 | | -HOLMES_ONLY_ARGS = ["-f", str(HOLMES_VALUES), "--set", "runner.enabled=false"] |
| 22 | +HOLMES_ARGS = ["-f", str(HOLMES_VALUES)] |
| 23 | +HOLMES_ONLY_ARGS = HOLMES_ARGS + ["--set", "runner.enabled=false"] |
50 | 24 |
|
51 | 25 | RUNNER_ONLY_KINDS_AND_NAMES = ["-runner", "kubewatch", "forwarder"] |
52 | 26 |
|
53 | 27 |
|
54 | | -def normalize_versions(output: str) -> str: |
55 | | - # CI and releases stamp the runner version over the 0.0.0 placeholder before running tests, |
56 | | - # and the holmes dependency moves with every Holmes release. |
57 | | - chart = yaml.safe_load((CHART_PATH / "Chart.yaml").read_text()) |
58 | | - app_version = str(chart["appVersion"]) |
59 | | - if app_version != "0.0.0": |
60 | | - output = output.replace(app_version, "0.0.0") |
61 | | - holmes_version = next(d["version"] for d in chart["dependencies"] if d["name"] == "holmes") |
62 | | - return output.replace(f"holmes:{holmes_version}", "holmes:0.0.0") |
63 | | - |
64 | 28 |
|
65 | 29 | def helm_template(args: List[str], check: bool = True) -> subprocess.CompletedProcess: |
66 | 30 | cmd = ["helm", "template", "robusta", str(CHART_PATH)] + BASE_ARGS + args |
@@ -88,24 +52,14 @@ def playbooks_config(docs: List[dict]) -> dict: |
88 | 52 | return yaml.safe_load(base64.b64decode(secret["data"]["active_playbooks.yaml"]).decode()) |
89 | 53 |
|
90 | 54 |
|
91 | | -@pytest.mark.parametrize("scenario", sorted(GOLDEN_SCENARIOS)) |
92 | | -def test_runner_enabled_render_matches_golden(scenario): |
93 | | - output = normalize_versions(render(GOLDEN_SCENARIOS[scenario])) |
94 | | - golden = GOLDEN_DIR / f"{scenario}.yaml" |
95 | | - if os.environ.get("UPDATE_HELM_GOLDEN"): |
96 | | - golden.write_text(output) |
97 | | - assert golden.exists(), f"missing {golden}; run with UPDATE_HELM_GOLDEN=1" |
98 | | - assert output == golden.read_text(), f"render of '{scenario}' differs from {golden}" |
99 | | - |
100 | | - |
101 | 55 | def test_explicit_runner_enabled_matches_default(): |
102 | | - args = GOLDEN_SCENARIOS["holmes"] |
| 56 | + args = HOLMES_ARGS |
103 | 57 | assert render(args + ["--set", "runner.enabled=true"]) == render(args) |
104 | 58 |
|
105 | 59 |
|
106 | 60 | def test_missing_runner_enabled_keeps_the_runner(): |
107 | 61 | # `helm upgrade --reuse-values` from an older chart keeps the old defaults, which lack the key |
108 | | - args = GOLDEN_SCENARIOS["holmes"] |
| 62 | + args = HOLMES_ARGS |
109 | 63 | assert render(args + ["--set", "runner.enabled=null"]) == render(args) |
110 | 64 |
|
111 | 65 |
|
@@ -223,15 +177,6 @@ def render_notes(tmp_path: Path, args: List[str]) -> str: |
223 | 177 | return yaml.safe_load(output)["notes"] |
224 | 178 |
|
225 | 179 |
|
226 | | -@pytest.mark.parametrize("scenario", ["default", "holmes"]) |
227 | | -def test_runner_enabled_notes_match_golden(tmp_path, scenario): |
228 | | - output = normalize_versions(render_notes(tmp_path, GOLDEN_SCENARIOS[scenario])) |
229 | | - golden = GOLDEN_DIR / f"{scenario}.NOTES.txt" |
230 | | - if os.environ.get("UPDATE_HELM_GOLDEN"): |
231 | | - golden.write_text(output) |
232 | | - assert output == golden.read_text() |
233 | | - |
234 | | - |
235 | 180 | def test_holmes_only_notes(tmp_path): |
236 | 181 | notes = render_notes(tmp_path, HOLMES_ONLY_ARGS) |
237 | 182 | assert "robusta-runner" not in notes |
|
0 commit comments