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