Skip to content

Commit

Permalink
show all route names in endpoint name
Browse files Browse the repository at this point in the history
  • Loading branch information
chassing committed Oct 3, 2024
1 parent 35634cf commit cacbeec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
22 changes: 12 additions & 10 deletions reconcile/endpoints_discovery/integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from collections import defaultdict
from collections.abc import Callable, Iterable
from typing import TypedDict

Expand Down Expand Up @@ -137,21 +138,22 @@ def get_routes(self, oc_map: OCMap, namespace: NamespaceV1) -> list[Route]:
)
return []

routes = {}
for item in sorted(
oc.get_items(kind="Route", namespace=namespace.name),
key=lambda x: x["metadata"]["name"],
reverse=True,
):
routes = defaultdict(list)
for item in oc.get_items(kind="Route", namespace=namespace.name):
tls = bool(item["spec"].get("tls"))
host = item["spec"]["host"]
routes[f"{host}:{tls}"] = Route(
name=item["metadata"]["name"],
# group all routes with the same hostname/tls
routes[(host, tls)].append(item["metadata"]["name"])

# merge all routes with the same hostname into one and combine the names
return [
Route(
name="|".join(sorted(names)),
host=host,
tls=tls,
)

return list(routes.values())
for (host, tls), names in routes.items()
]

def get_endpoint_changes(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_endpoints_discovery_integration_get_routes(
# see fake_route fixture!
assert len(routes) == 1
assert isinstance(routes[0], Route)
assert routes[0].name == "fake-route"
assert routes[0].name == "fake-route|zzz-fake-route"


def test_endpoints_discovery_integration_get_endpoint_changes_no_routes_no_endpoints(
Expand Down Expand Up @@ -158,9 +158,9 @@ def test_endpoints_discovery_integration_get_apps(
path="/path/app-1.yml",
endpoints_to_add=[
Endpoint(
name="endpoints-discovery/cluster-1/app-1-ns-1/fake-route",
name="endpoints-discovery/cluster-1/app-1-ns-1/fake-route|zzz-fake-route",
data={
"name": "endpoints-discovery/cluster-1/app-1-ns-1/fake-route",
"name": "endpoints-discovery/cluster-1/app-1-ns-1/fake-route|zzz-fake-route",
"url": "https://fake-route.com:80",
},
)
Expand All @@ -173,9 +173,9 @@ def test_endpoints_discovery_integration_get_apps(
path="/path/app-2.yml",
endpoints_to_add=[
Endpoint(
name="endpoints-discovery/cluster-1/app-2-ns-1/fake-route",
name="endpoints-discovery/cluster-1/app-2-ns-1/fake-route|zzz-fake-route",
data={
"name": "endpoints-discovery/cluster-1/app-2-ns-1/fake-route",
"name": "endpoints-discovery/cluster-1/app-2-ns-1/fake-route|zzz-fake-route",
"url": "https://fake-route.com:80",
},
)
Expand Down

0 comments on commit cacbeec

Please sign in to comment.