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 292b97e commit 60ff049
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions reconcile/endpoints_discovery/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,27 @@ def get_routes(self, oc_map: OCMap, namespace: NamespaceV1) -> list[Route]:
)
return []

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

return list(routes.values())
return [
# merge all routes with the same hostname into one and combine the names
Route(name="|".join(r.name for r in rs), host=rs[0].host, tls=rs[0].tls)
for rs in routes.values()
]

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 60ff049

Please sign in to comment.