feat: add port-range support for haproxy-route-tcp#532
Draft
swetha1654 wants to merge 1 commit into
Draft
Conversation
Enable requirers to specify a port range (e.g. '10500-10600') instead
of a single port. HAProxy is configured with:
- bind [::]:START-END v4v6 (frontend port range binding)
- tcp-request session set-dst-port fc_dst_port (captures incoming port)
- server NAME IP:0 (port 0 uses the set-dst-port value, 1:1 passthrough)
Changes:
- lib/charms/haproxy/v1/haproxy_route_tcp.py (LIBPATCH=4):
* TcpRequirerApplicationData: port made Optional, port_range field added
* Validators: mutual exclusivity, format check, port_range+sni forbidden,
port_range+backend_port forbidden
* check_ports_unique: expands ranges to detect overlaps
* provide_haproxy_route_tcp_requirements: accepts port_range parameter
- src/state/haproxy_route_tcp.py:
* HaproxyRouteTcpServer.port: Optional[int] (None = dynamic passthrough)
* HAProxyRouteTcpBackend: port_range servers get port=None, check=None
* HAProxyRouteTcpFrontend: port_range field, frontend_name/bind_address/
all_frontend_ports/default_backend_name properties updated
- src/state/haproxy_route.py:
* parse_haproxy_route_tcp_requirers_data: groups by port_range string
* check_tcp_http_port_conflicts: expands ranges into tcp_ports dict
* valid_tcp_frontends: checks all ports in range for conflicts
- templates/haproxy_route_tcp.cfg.j2:
* server rendered as IP:0 when port is None
* bind uses frontend.bind_address (port or port range)
* tcp-request session set-dst-port fc_dst_port added for port_range
* TLS termination skipped for port_range frontends
- src/charm.py:
* set_ports: expands all_frontend_ports for port_range frontends
* publish endpoints: uses port_range string as port_str
Closes canonical#525
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
36a1a4e to
8b498cb
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements port-range support for the
haproxy-route-tcpinterface as requested in issue #525.This allows
haproxy-route-tcprequirers to specify a port range (e.g."10500-10600") instead of a single port. HAProxy will bind to the entire range and forward each incoming connection to the backend on the same port (1:1 passthrough viaset-dst-port fc_dst_port).Changes
Library (
lib/charms/haproxy/v1/haproxy_route_tcp.py, LIBPATCH 3→4)port_range: Optional[str]field toTcpRequirerApplicationDatavalidate_port_or_port_range: exactly one ofportorport_rangemust be set; format^\d+-\d+$with start < endassign_default_backend_port: raises ifbackend_portis set withport_rangesni_set_when_not_enforcing_tls: raises ifsniis set withport_rangetls_terminate_requires_no_port_range: raises iftls_terminate=Truewithport_range(passthrough mode only)check_ports_uniqueto expand ranges for overlap detectionprovide_haproxy_route_tcp_requirementssignature to acceptport_rangeupdate_relation_dataguard to also acceptport_range(was checking onlyport)State (
src/state/haproxy_route_tcp.py,src/state/haproxy_route.py)HaproxyRouteTcpServer.portis nowOptional[int](None for port-range passthrough)HAProxyRouteTcpBackend.servers: setsport=None, check=Nonefor port_range backendsHAProxyRouteTcpFrontend: newport_rangefield,frontend_name,bind_address,all_frontend_portspropertiesparse_haproxy_route_tcp_requirers_data: groups by port_range string as keycheck_tcp_http_port_conflicts/valid_tcp_frontends: expand ranges for conflict detectionTemplate (
templates/haproxy_route_tcp.cfg.j2)bind [::]:START-END v4v6tcp-request session set-dst-port fc_dst_portfor dynamic port passthroughserver NAME IP:0(port 0 = use set-dst-port value)Charm (
src/charm.py)set_portsand endpoint publishing useall_frontend_portsto handle both single ports and rangesHAProxy mechanism
Tests
tests/unit/test_haproxy_route_tcp_lib.pytests/unit/test_state.pytest_haproxy_route_tcp_port_range— locally verified passingCloses #525