Repository navigation
feat(haproxy-route): support a configurable default backend #674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Thanhphan1147
wants to merge
10
commits into
main
Choose a base branch
from
feat/default-backend
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3cc5521
feat(haproxy-route): support a configurable default backend
Thanhphan1147 3bed523
docs: add release note artifact for haproxy-route default backend
Thanhphan1147 9f4fe4a
test: run default backend integration test in its own model
Thanhphan1147 bcac2ca
fix(haproxy-route): reject default backends with external gRPC ports
Copilot e20115d
fix(haproxy-route): render default backend separately from HTTP routes
Copilot d18a0d9
refactor(haproxy-route): rely on model validation for default backend…
Copilot bc747dc
Merge branch 'main' into feat/default-backend
Thanhphan1147 a345435
Merge branch 'main' into feat/default-backend
Thanhphan1147 82ed2ec
Merge branch 'main' into feat/default-backend
Thanhphan1147 b766c43
Merge branch 'main' into feat/default-backend
Thanhphan1147 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| version_schema: 2 | ||
|
|
||
| changes: | ||
| - title: Support a configurable default backend for haproxy-route | ||
| author: Thanhphan1147 | ||
| type: minor | ||
| description: > | ||
| Added a `default_backend` attribute to the `haproxy-route` interface so a | ||
| requirer application can designate its backend as the default landing page | ||
| for requests that do not match any configured hostname or backend. The | ||
| default backend renders no ACL and is used as the target of the | ||
| `default_backend` directive. If more than one backend requests the | ||
| attribute, all of them are rejected and the built-in default page is used. | ||
| urls: | ||
| pr: | ||
| - https://github.com/canonical/haproxy-operator/pull/674 | ||
| related_issue: https://github.com/canonical/haproxy-operator/issues/664 | ||
| visibility: public | ||
| highlight: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Thanhphan1147 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
haproxy-operator/tests/integration/test_haproxy_route_default_backend.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # Copyright 2025 Canonical Ltd. | ||
| # See LICENSE file for licensing details. | ||
|
|
||
| """Integration tests for the haproxy-route default backend support.""" | ||
|
|
||
| import json | ||
|
|
||
| import httpx | ||
| import jubilant | ||
| import pytest | ||
|
|
||
| from .conftest import all_active_and_idle | ||
| from .helper import get_unit_ip_address | ||
|
|
||
|
|
||
| @pytest.mark.abort_on_fail | ||
| def test_haproxy_route_default_backend( | ||
| configured_application_with_tls: str, | ||
| any_charm_haproxy_route_requirer: str, | ||
| juju: jubilant.Juju, | ||
| ): | ||
| """Deploy the charm with anycharm haproxy-route requirer that installs apache2. | ||
|
|
||
| Mark the requirer as the default backend and assert that it is used as the target of | ||
| the default_backend directive, renders no ACL, and serves requests that do not match | ||
| any configured hostname. | ||
| """ | ||
| juju.run(f"{any_charm_haproxy_route_requirer}/0", "rpc", {"method": "start_server"}) | ||
|
|
||
| juju.integrate( | ||
| f"{configured_application_with_tls}:haproxy-route", any_charm_haproxy_route_requirer | ||
| ) | ||
| juju.wait( | ||
| lambda status: ( | ||
| jubilant.all_blocked(status, configured_application_with_tls) | ||
| and jubilant.all_agents_idle( | ||
| status, configured_application_with_tls, any_charm_haproxy_route_requirer | ||
| ) | ||
| ), | ||
| ) | ||
| juju.run( | ||
| f"{any_charm_haproxy_route_requirer}/0", | ||
| "rpc", | ||
| { | ||
| "method": "update_relation", | ||
| "args": json.dumps( | ||
| [ | ||
| { | ||
| "service": "any_charm_default_backend", | ||
| "ports": [80], | ||
| "default_backend": True, | ||
| } | ||
| ] | ||
| ), | ||
| }, | ||
| ) | ||
| juju.wait( | ||
| lambda status: all_active_and_idle( | ||
| status, configured_application_with_tls, any_charm_haproxy_route_requirer | ||
| ) | ||
| ) | ||
| haproxy_config = juju.exec( | ||
| "cat /etc/haproxy/haproxy.cfg", unit=f"{configured_application_with_tls}/0" | ||
| ).stdout | ||
| assert "default_backend default\n" not in haproxy_config | ||
| assert "backend default\n" not in haproxy_config | ||
| assert "default_backend any_charm_default_backend\n" in haproxy_config | ||
| assert "use_backend any_charm_default_backend" not in haproxy_config | ||
| assert "acl_host_any_charm_default_backend" not in haproxy_config | ||
|
|
||
| haproxy_ip_address = get_unit_ip_address(juju, configured_application_with_tls) | ||
| with httpx.Client(http2=False, verify=False) as client: # nosec: B501 | ||
| response = client.get( | ||
| f"https://{haproxy_ip_address}", | ||
| headers={"Host": "does-not-match.example.com"}, | ||
| timeout=5.0, | ||
| ) | ||
| assert response.status_code == httpx.codes.OK | ||
| assert "ok!" in response.text |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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