@@ -69,7 +69,7 @@ def create_app_wrapper(self):
69
69
"""
70
70
71
71
if self .config .namespace is None :
72
- self .config .namespace = oc . get_project_name ()
72
+ self .config .namespace = get_current_namespace ()
73
73
if type (self .config .namespace ) is not str :
74
74
raise TypeError (
75
75
f"Namespace { self .config .namespace } is of type { type (self .config .namespace )} . Check your Kubernetes Authentication."
@@ -263,16 +263,21 @@ def cluster_dashboard_uri(self) -> str:
263
263
Returns a string containing the cluster's dashboard URI.
264
264
"""
265
265
try :
266
- with oc . project ( self . config .namespace ):
267
- route = oc . invoke (
268
- "get" , [ "route" , "-o" , "jsonpath='{$.items[*].spec.host}'" ]
269
- )
270
- route = route . out (). split ( " " )
271
- route = [ x for x in route if f"ray-dashboard- { self .config .name } " in x ]
272
- route = route [ 0 ]. strip (). strip ( "'" )
273
- return f"http:// { route } "
266
+ config .load_kube_config ()
267
+ api_instance = client . CustomObjectsApi ()
268
+ routes = api_instance . list_namespaced_custom_object (
269
+ group = "route.openshift.io" ,
270
+ version = "v1" ,
271
+ namespace = self .config .namespace ,
272
+ plural = "routes" ,
273
+ )
274
274
except :
275
- return "Dashboard route not available yet, have you run cluster.up()?"
275
+ pass
276
+
277
+ for route in routes ["items" ]:
278
+ if route ["metadata" ]["name" ] == f"ray-dashboard-{ self .config .name } " :
279
+ return f"http://{ route ['spec' ]['host' ]} "
280
+ return "Dashboard route not available yet, have you run cluster.up()?"
276
281
277
282
def list_jobs (self ) -> List :
278
283
"""
@@ -336,6 +341,19 @@ def list_all_queued(namespace: str, print_to_console: bool = True):
336
341
return app_wrappers
337
342
338
343
344
+ def get_current_namespace ():
345
+ try :
346
+ _ , active_context = config .list_kube_config_contexts ()
347
+ except config .ConfigException :
348
+ raise PermissionError (
349
+ "Retrieving current namespace not permitted, have you put in correct/up-to-date auth credentials?"
350
+ )
351
+ try :
352
+ return active_context ["context" ]["namespace" ]
353
+ except KeyError :
354
+ return "default"
355
+
356
+
339
357
# private methods
340
358
341
359
@@ -465,12 +483,25 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
465
483
else :
466
484
status = RayClusterStatus .UNKNOWN
467
485
468
- with oc .project (rc ["metadata" ]["namespace" ]), oc .timeout (10 * 60 ):
469
- route = (
470
- oc .selector (f"route/ray-dashboard-{ rc ['metadata' ]['name' ]} " )
471
- .object ()
472
- .model .spec .host
473
- )
486
+ config .load_kube_config ()
487
+ api_instance = client .CustomObjectsApi ()
488
+ routes = api_instance .list_namespaced_custom_object (
489
+ group = "route.openshift.io" ,
490
+ version = "v1" ,
491
+ namespace = rc ["metadata" ]["namespace" ],
492
+ plural = "routes" ,
493
+ )
494
+ ray_route = None
495
+ for route in routes ["items" ]:
496
+ if route ["metadata" ]["name" ] == f"ray-dashboard-{ rc ['metadata' ]['name' ]} " :
497
+ ray_route = route ["spec" ]["host" ]
498
+
499
+ # with oc.project(rc["metadata"]["namespace"]), oc.timeout(10 * 60):
500
+ # route = (
501
+ # oc.selector(f"route/ray-dashboard-{rc['metadata']['name']}")
502
+ # .object()
503
+ # .model.spec.host
504
+ # )
474
505
475
506
return RayCluster (
476
507
name = rc ["metadata" ]["name" ],
@@ -489,7 +520,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
489
520
]["resources" ]["limits" ]["cpu" ],
490
521
worker_gpu = 0 , # hard to detect currently how many gpus, can override it with what the user asked for
491
522
namespace = rc ["metadata" ]["namespace" ],
492
- dashboard = route ,
523
+ dashboard = ray_route ,
493
524
)
494
525
495
526
0 commit comments