Fix HAProxy peer entries to include name, address, and port#462
Draft
Fix HAProxy peer entries to include name, address, and port#462
Conversation
Add HAPROXY_PEER_PORT constant (10000) and _format_peer_entries helper to render peer entries as '<name> <address>:<port>' instead of just '<address>'. Also add 'bind *:<port>' to the peers section in all templates. This fixes HAProxy discarding peers due to invalid config. Agent-Logs-Url: https://github.com/canonical/haproxy-operator/sessions/71b67230-85a7-4437-ba07-80b49a93c036 Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
…bjects Agent-Logs-Url: https://github.com/canonical/haproxy-operator/sessions/71b67230-85a7-4437-ba07-80b49a93c036 Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix invalid peer configuration in HAProxy
Fix HAProxy peer entries to include name, address, and port
Apr 13, 2026
Comment on lines
+290
to
+309
| def _format_peer_entries(peers: list[IPvAnyAddress]) -> list[str]: | ||
| """Format peer IP addresses into HAProxy peer entry strings. | ||
|
|
||
| Each entry is formatted as ``<name> <address>:<port>`` where ``<name>`` | ||
| is derived from the IP address with non-alphanumeric characters replaced | ||
| by hyphens. | ||
|
|
||
| Args: | ||
| peers: List of peer IP addresses. | ||
|
|
||
| Returns: | ||
| list[str]: Formatted peer entry strings. | ||
| """ | ||
| entries: list[str] = [] | ||
| for addr in peers: | ||
| name = str(addr).replace(".", "-").replace(":", "-") | ||
| entries.append(f"{name} {addr}:{HAPROXY_PEER_PORT}") | ||
| return entries | ||
|
|
||
|
|
Collaborator
Contributor
Author
There was a problem hiding this comment.
Moved HAPROXY_PEER_PORT and the formatting logic into a PeersInformation mixin class in state/peers.py with formatted_peer_entries and peer_tcp_port as @property methods. IngressRequirersInformation, IngressPerUnitRequirersInformation, and HaproxyRouteRequirersInformation all subclass it. src/haproxy.py now reads the properties from the state objects. See d1ac83e.
…ataclasses Move HAPROXY_PEER_PORT and peer formatting logic from src/haproxy.py into a PeersInformation mixin class in state/peers.py. All three state dataclasses (IngressRequirersInformation, IngressPerUnitRequirersInformation, HaproxyRouteRequirersInformation) now subclass PeersInformation and expose formatted_peer_entries and peer_tcp_port as @Property methods. Agent-Logs-Url: https://github.com/canonical/haproxy-operator/sessions/29068634-9a26-492a-a765-4ae185a92429 Co-authored-by: Thanhphan1147 <42444001+Thanhphan1147@users.noreply.github.com>
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.
HAProxy was discarding the entire
peerssection because entries were rendered aspeer <address>instead of the requiredpeer <name> <address>:<port>format.Changes
state/peers.py(new): AddPeersInformationmixin class withHAPROXY_PEER_PORT = 10000constant andformatted_peer_entries/peer_tcp_port@propertymethods that pre-render peer lines (e.g.10-68-79-144 10.68.79.144:10000).IngressRequirersInformation,IngressPerUnitRequirersInformation, andHaproxyRouteRequirersInformationnow subclassPeersInformation, exposing the peer formatting as properties.src/haproxy.py:reconcile_ingressandreconcile_haproxy_routenow readformatted_peer_entriesandpeer_tcp_portdirectly from the state objects instead of calling a standalone helper.haproxy_route.cfg.j2,haproxy_ingress.cfg.j2,haproxy_ingress_per_unit.cfg.j2): Addbind *:{{ peer_tcp_port }}and consume pre-rendered peer entries.PeersInformationmixin covering IPv4, IPv6, empty input, and port property.Before/After