diff --git a/docs/changelog.md b/docs/changelog.md index db0223ef..d6ecfea1 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Each revision is versioned by the date of the revision. +## 2026-04-21 + +- Do not render the default backend if there are no other backends in in the haproxy-route-tcp. + ## 2026-04-17 - Added missing settings from haproxy-route-tcp relation template. diff --git a/docs/release-notes/artifacts/pr0476.yaml b/docs/release-notes/artifacts/pr0476.yaml new file mode 100644 index 00000000..bcb22900 --- /dev/null +++ b/docs/release-notes/artifacts/pr0476.yaml @@ -0,0 +1,14 @@ +version_schema: 2 +changes: + - title: Do not render the default backend if there are no other backends + author: skatsaounis + type: bugfix + description: > + Do not render the default backend if there are no other backends in the + haproxy-route-tcp relation template, to avoid rendering unused + configuration. + urls: + pr: + - https://github.com/canonical/haproxy-operator/pull/476 + visibility: public + highlight: false diff --git a/haproxy-operator/templates/haproxy_route_tcp.cfg.j2 b/haproxy-operator/templates/haproxy_route_tcp.cfg.j2 index 1ae76cc4..2ff669b6 100644 --- a/haproxy-operator/templates/haproxy_route_tcp.cfg.j2 +++ b/haproxy-operator/templates/haproxy_route_tcp.cfg.j2 @@ -95,8 +95,8 @@ backend {{ frontend.default_backend_name }} {% endfor %} {% endif %} -{# Render each backend for the frontend. #} -{% for backend in frontend.backends %} +{# Render each backend for the frontend. Skip rendering if there's only the default backend. #} +{% for backend in frontend.backends if frontend.backends|length > 1 %} backend {{ backend.name }} mode tcp {% if backend.application_data.load_balancing %} diff --git a/haproxy-operator/tests/integration/test_haproxy_route_tcp.py b/haproxy-operator/tests/integration/test_haproxy_route_tcp.py index 02102b00..bcd8f642 100644 --- a/haproxy-operator/tests/integration/test_haproxy_route_tcp.py +++ b/haproxy-operator/tests/integration/test_haproxy_route_tcp.py @@ -97,3 +97,18 @@ def test_haproxy_route_tcp( "timeout queue 2s", ] ) + + assert all( + entry in haproxy_config + for entry in [ + "backend haproxy_route_tcp_4444_default_backend", + "default_backend haproxy_route_tcp_4444_default_backend", + ] + ) + assert all( + entry not in haproxy_config + for entry in [ + f"{any_charm_haproxy_route_tcp_requirer}_4444", + f"default_backend {any_charm_haproxy_route_tcp_requirer}_4444", + ] + )