Skip to content

feat(haproxy-route): support a configurable default backend - #674

Open
Thanhphan1147 wants to merge 10 commits into
mainfrom
feat/default-backend
Open

Thanhphan1147 wants to merge 10 commits into
mainfrom
feat/default-backend

Conversation

@Thanhphan1147

@Thanhphan1147 Thanhphan1147 commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Implements #664 by allowing a haproxy-route requirer to designate its backend as the default landing page for requests that do not match any configured hostname/backend.

A new boolean default_backend is added to the haproxy-route v2 library. A default backend:

  • renders no ACL (no acl_path_*, acl_host_*, acl_deny_path_*, use_backend),
  • is used as the target of the default_backend directive in the frontend,
  • is otherwise rendered as a normal backend (servers, health checks, timeouts, load balancing, rewrites, rate limits, ...).

When no requirer requests the flag, the existing inline backend default response (Default page for the haproxy-operator charm) is kept.

If more than one requirer sets default_backend, all requesting backends are rejected (their relation ids are added to relation_ids_with_invalid_data) and the inline default is used.

Related PR: canonical/ingress-configurator-operator#221

Changes

  • lib/charms/haproxy/v2/haproxy_route.py: new default_backend field/parameter + single-default-backend validation. LIBPATCH bumped to 5.
  • src/state/haproxy_route.py: HAProxyRouteBackend.is_default_backend and HaproxyRouteRequirersInformation.default_backend (gRPC backends excluded).
  • src/haproxy.py: pass the resolved default backend to the template.
  • templates/haproxy.cfg.j2, templates/haproxy_route.cfg.j2: render the requirer backend as default_backend target; only render the inline default when unset.

Tests

  • Unit tests for the new library field and the multi-requester rejection.
  • Scenario tests asserting the rendered config (default backend directive, no ACL, no inline default) and the fallback behaviour.
  • Integration test asserting the directive and end-to-end routing to a backend for an unmatched Host.
  • Manual e2e (Juju + LXD): single default backend serves requests for an unmatched host; multiple requesting backends are rejected and the inline default is restored.

Add a `default_backend` boolean to the haproxy-route v2 library. A requirer
application can set it to designate its backend as the default landing page
for requests that do not match any configured hostname/backend.

- The library rejects all requesting backends when more than one requirer sets
  the flag, marking their relation ids as invalid.
- The charm renders the default backend without any ACL and uses it as the
  target of the `default_backend` directive. The inline "Default page for the
  haproxy-operator charm" backend is only rendered when no requirer requests to
  be the default backend.
- The default backend still renders as a normal backend (servers, health
  checks, timeouts, rewrites, ...).

Bump LIBPATCH to 5.

Implements #664
Comment thread haproxy-operator/src/state/haproxy_route.py Outdated
Comment thread haproxy-operator/src/haproxy.py Outdated
Comment thread haproxy-operator/templates/haproxy_route.cfg.j2
Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
Comment thread haproxy-operator/src/state/haproxy_route.py Outdated
… selection

Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
@Thanhphan1147

Copy link
Copy Markdown
Collaborator Author

[merge bot]: This PR is now being monitored to automatically rerun failing tests

@Thanhphan1147
Thanhphan1147 enabled auto-merge (squash) October 8, 2026 11:59
Comment on lines +294 to +301
def is_default_backend(self) -> bool:
"""Return whether this backend is the default landing page.

Returns:
bool: True if this backend is requested as the default backend.
"""
return self.application_data.default_backend

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there is no need to have this as a property

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants