Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ The namespace and storage behaviour are controlled by these variables:
- **Description:** Default size of the persistent volume claim that HaRP creates for each ExApp.
- **Default:** `10Gi`
- **`HP_K8S_HOST_ALIASES`**
- **Description:** Additional host aliases set on the ExApp pods, as a comma-separated list of `hostname:ip` pairs, e.g. `nextcloud.example.com:10.0.0.5`. Useful when your Nextcloud domain is not resolvable by the cluster DNS.
- **Description:** Additional host aliases set on the ExApp pods, as a comma-separated list of `hostname:ip` pairs, e.g. `nextcloud.example.com:10.0.0.5`. Useful when your Nextcloud domain is not resolvable by the cluster DNS. An IPv6 address may be written with or without brackets, e.g. `nextcloud.example.com:[fd00::5]`.
- **Default:** empty

How HaRP reaches the API server:
Expand Down
5 changes: 3 additions & 2 deletions haproxy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2833,9 +2833,10 @@ def _k8s_parse_host_aliases() -> list[dict[str, Any]]:
entry = entry.strip()
if not entry or ":" not in entry:
continue
hostname, ip_addr = entry.rsplit(":", 1)
# A host name has no ':', so the address is everything after the first one
hostname, ip_addr = entry.split(":", 1)
hostname = hostname.strip()
ip_addr = ip_addr.strip()
ip_addr = ip_addr.strip().removeprefix("[").removesuffix("]")
if hostname and ip_addr:
ip_to_hosts.setdefault(ip_addr, []).append(hostname)

Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,25 @@ def test_in_cluster_api_server_url(monkeypatch, host, url):
assert agent._in_cluster_api_server() == url


@pytest.mark.parametrize(
("value", "aliases"),
[
("nc.example.com:10.0.0.5", [{"ip": "10.0.0.5", "hostnames": ["nc.example.com"]}]),
("nc.example.com:fd00::5", [{"ip": "fd00::5", "hostnames": ["nc.example.com"]}]),
(
"nc.example.com:[fd00::5], office.example.com:fd00::5,nc.example.com:10.0.0.5",
[
{"ip": "fd00::5", "hostnames": ["nc.example.com", "office.example.com"]},
{"ip": "10.0.0.5", "hostnames": ["nc.example.com"]},
],
),
],
)
def test_k8s_host_aliases(monkeypatch, value, aliases):
monkeypatch.setattr(agent, "K8S_HOST_ALIASES_RAW", value)
assert agent._k8s_parse_host_aliases() == aliases


def test_k8s_service_lookup_works_for_any_app_id(monkeypatch):
calls = []

Expand Down
Loading