From 7e38818cd7a6ba69dbafbd48ee85c09cef69047a Mon Sep 17 00:00:00 2001 From: Ben Banfield-Zanin Date: Wed, 22 Oct 2025 16:35:10 +0100 Subject: [PATCH] Ensure haproxy.cfg ends with 2 newlines? --- .../templates/haproxy/_helpers.tpl | 3 ++- newsfragments/829.changed.md | 1 + tests/manifests/__init__.py | 1 + tests/manifests/test_haproxy.py | 23 +++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 newsfragments/829.changed.md diff --git a/charts/matrix-stack/templates/haproxy/_helpers.tpl b/charts/matrix-stack/templates/haproxy/_helpers.tpl index a51f19f9..0b093c67 100644 --- a/charts/matrix-stack/templates/haproxy/_helpers.tpl +++ b/charts/matrix-stack/templates/haproxy/_helpers.tpl @@ -18,8 +18,9 @@ app.kubernetes.io/version: {{ include "element-io.ess-library.labels.makeSafe" . {{- define "element-io.haproxy.configmap-data" }} {{- $root := .root -}} {{- with required "element-io.haproxy.configmap-data missing context" .context -}} -haproxy.cfg: | +haproxy.cfg: |+ {{- tpl ($root.Files.Get "configs/haproxy/haproxy.cfg.tpl") (dict "root" $root "context" .) | nindent 2 }} +placeholder: Ensure there's something after haproxy.cfg for https://github.com/element-hq/ess-helm/issues/821 {{- end -}} {{- end -}} diff --git a/newsfragments/829.changed.md b/newsfragments/829.changed.md new file mode 100644 index 00000000..ff6f9fd0 --- /dev/null +++ b/newsfragments/829.changed.md @@ -0,0 +1 @@ +Ensure there's at least 2 newlines at the end of the `haproxy.cfg` file. diff --git a/tests/manifests/__init__.py b/tests/manifests/__init__.py index eed6efe2..1c9855f1 100644 --- a/tests/manifests/__init__.py +++ b/tests/manifests/__init__.py @@ -453,6 +453,7 @@ all_components_details = [ has_ingress=False, is_shared_component=True, makes_outbound_requests=False, + paths_consistency_noqa=("/usr/local/etc/haproxy/placeholder",), skip_path_consistency_for_files=("haproxy.cfg", "429.http", "path_map_file", "path_map_file_get"), ), ComponentDetails( diff --git a/tests/manifests/test_haproxy.py b/tests/manifests/test_haproxy.py index 69697b4c..6adefc23 100644 --- a/tests/manifests/test_haproxy.py +++ b/tests/manifests/test_haproxy.py @@ -55,3 +55,26 @@ async def test_haproxy_server_templates_reference_valid_services(templates): break else: raise AssertionError(f"{service_name} did not have a port named {desired_port} referenced in {line}") + + +@pytest.mark.parametrize("values_file", values_files_to_test) +@pytest.mark.asyncio_cooperative +async def test_haproxy_config_ends_in_2_newlines(templates): + seen_haproxy = False + haproxy_configmap = None + for template in templates: + if template_to_deployable_details(template).name != "haproxy": + continue + seen_haproxy = True + + if template["kind"] == "ConfigMap": + haproxy_configmap = template + + if not seen_haproxy: + return + + assert haproxy_configmap, "No HAProxy ConfigMap found" + assert "haproxy.cfg" in haproxy_configmap["data"], f"{template_id(haproxy_configmap)} didn't contain haproxy.cfg" + assert haproxy_configmap["data"]["haproxy.cfg"].endswith("\n\n"), ( + f"{template_id(haproxy_configmap)}/haproxy.cfg should end with at least 2 \\n" + )