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