Skip to content

Commit 9e6088a

Browse files
Fix cluster.status() for Routes
1 parent 660f328 commit 9e6088a

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -902,25 +902,47 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
902902
status = RayClusterStatus(rc["status"]["state"].lower())
903903
else:
904904
status = RayClusterStatus.UNKNOWN
905-
try:
906-
config_check()
907-
api_instance = client.NetworkingV1Api(api_config_handler())
908-
ingresses = api_instance.list_namespaced_ingress(rc["metadata"]["namespace"])
909-
except Exception as e: # pragma no cover
910-
return _kube_api_error_handling(e)
911-
ray_ingress = None
912-
for ingress in ingresses.items:
913-
annotations = ingress.metadata.annotations
914-
protocol = "http"
915-
if (
916-
ingress.metadata.name == f"ray-dashboard-{rc['metadata']['name']}"
917-
or ingress.metadata.name.startswith(f"{rc['metadata']['name']}-ingress")
918-
):
919-
if annotations == None:
920-
protocol = "http"
921-
elif "route.openshift.io/termination" in annotations:
922-
protocol = "https"
923-
ray_ingress = f"{protocol}://{ingress.spec.rules[0].host}"
905+
config_check()
906+
dashboard_url = None
907+
if is_openshift_cluster():
908+
try:
909+
api_instance = client.CustomObjectsApi(api_config_handler())
910+
routes = api_instance.list_namespaced_custom_object(
911+
group="route.openshift.io",
912+
version="v1",
913+
namespace=rc["metadata"]["namespace"],
914+
plural="routes",
915+
)
916+
except Exception as e: # pragma: no cover
917+
return _kube_api_error_handling(e)
918+
919+
for route in routes["items"]:
920+
rc_name = rc["metadata"]["name"]
921+
if route["metadata"]["name"] == f"ray-dashboard-{rc_name}" or route[
922+
"metadata"
923+
]["name"].startswith(f"{rc_name}-ingress"):
924+
protocol = "https" if route["spec"].get("tls") else "http"
925+
dashboard_url = f"{protocol}://{route['spec']['host']}"
926+
else:
927+
try:
928+
api_instance = client.NetworkingV1Api(api_config_handler())
929+
ingresses = api_instance.list_namespaced_ingress(
930+
rc["metadata"]["namespace"]
931+
)
932+
except Exception as e: # pragma no cover
933+
return _kube_api_error_handling(e)
934+
for ingress in ingresses.items:
935+
annotations = ingress.metadata.annotations
936+
protocol = "http"
937+
if (
938+
ingress.metadata.name == f"ray-dashboard-{rc['metadata']['name']}"
939+
or ingress.metadata.name.startswith(f"{rc['metadata']['name']}-ingress")
940+
):
941+
if annotations == None:
942+
protocol = "http"
943+
elif "route.openshift.io/termination" in annotations:
944+
protocol = "https"
945+
dashboard_url = f"{protocol}://{ingress.spec.rules[0].host}"
924946

925947
return RayCluster(
926948
name=rc["metadata"]["name"],
@@ -947,7 +969,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
947969
head_gpu=rc["spec"]["headGroupSpec"]["template"]["spec"]["containers"][0][
948970
"resources"
949971
]["limits"]["nvidia.com/gpu"],
950-
dashboard=ray_ingress,
972+
dashboard=dashboard_url,
951973
)
952974

953975

tests/unit_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,6 +1903,7 @@ def route_retrieval(group, version, namespace, plural, name):
19031903

19041904
def test_list_clusters(mocker, capsys):
19051905
mocker.patch("kubernetes.config.load_kube_config", return_value="ignore")
1906+
mocker.patch("kubernetes.client.ApisApi.get_api_versions")
19061907
mocker.patch(
19071908
"kubernetes.client.CustomObjectsApi.list_namespaced_custom_object",
19081909
side_effect=get_obj_none,

0 commit comments

Comments
 (0)