@@ -128,6 +128,8 @@ def up(self):
128
128
plural = "appwrappers" ,
129
129
body = aw ,
130
130
)
131
+ # Create the ingress
132
+ create_ingress (self )
131
133
except Exception as e : # pragma: no cover
132
134
return _kube_api_error_handling (e )
133
135
@@ -147,6 +149,9 @@ def down(self):
147
149
plural = "appwrappers" ,
148
150
name = self .app_wrapper_name ,
149
151
)
152
+ # Delete the ingress
153
+ api_instance = client .NetworkingV1Api (api_config_handler ())
154
+ api_instance .delete_namespaced_ingress (name = f"ray-dashboard-{ self .config .name } " , namespace = namespace )
150
155
except Exception as e : # pragma: no cover
151
156
return _kube_api_error_handling (e )
152
157
@@ -257,19 +262,17 @@ def cluster_dashboard_uri(self) -> str:
257
262
"""
258
263
try :
259
264
config_check ()
260
- api_instance = client .CustomObjectsApi (api_config_handler ())
261
- routes = api_instance .list_namespaced_custom_object (
262
- group = "route.openshift.io" ,
263
- version = "v1" ,
264
- namespace = self .config .namespace ,
265
- plural = "routes" ,
266
- )
267
- except Exception as e : # pragma: no cover
265
+ api_instance = client .NetworkingV1Api (api_config_handler ())
266
+ ingresses = api_instance .list_namespaced_ingress (self .config .namespace )
267
+ except Exception as e :
268
268
return _kube_api_error_handling (e )
269
-
270
- for route in routes ["items" ]:
271
- if route ["metadata" ]["name" ] == f"ray-dashboard-{ self .config .name } " :
272
- return f"http://{ route ['spec' ]['host' ]} "
269
+
270
+ for ingress in ingresses .items :
271
+ if (
272
+ ingress .metadata .name == f"ray-dashboard-{ self .config .name } "
273
+ and ingress .spec .rules [0 ].host .startswith (f"ray-dashboard-{ self .config .name } " )
274
+ ):
275
+ return f"http://{ ingress .spec .rules [0 ].host } "
273
276
return "Dashboard route not available yet, have you run cluster.up()?"
274
277
275
278
def list_jobs (self ) -> List :
@@ -359,6 +362,52 @@ def local_client_url(self):
359
362
else :
360
363
return "None"
361
364
365
+ def create_ingress (self ):
366
+ """
367
+ Create a Kubernetes Ingress resource to expose the Ray dashboard service externally.
368
+ """
369
+ ingress_domain = _get_ingress_domain ()
370
+ try :
371
+ config_check ()
372
+ api_instance = client .NetworkingV1Api (api_config_handler ())
373
+
374
+ ingress_manifest = {
375
+ "apiVersion" : "networking.k8s.io/v1" ,
376
+ "kind" : "Ingress" ,
377
+ "metadata" : {
378
+ "name" : f"ray-dashboard-{ self .config .name } " ,
379
+ "namespace" : self .config .namespace ,
380
+ },
381
+ "spec" : {
382
+ "rules" : [
383
+ {
384
+ "host" : f"ray-dashboard-{ self .config .name } .{ self .config .namespace } .{ ingress_domain } " ,
385
+ "http" : {
386
+ "paths" : [
387
+ {
388
+ "path" : "/" ,
389
+ "pathType" : "Prefix" ,
390
+ "backend" : {
391
+ "service" : {
392
+ "name" : f"{ self .config .name } -head-svc" ,
393
+ "port" : {
394
+ "number" : 8265 ,
395
+ },
396
+ }
397
+ },
398
+ }
399
+ ]
400
+ },
401
+ }
402
+ ],
403
+ },
404
+ }
405
+
406
+ api_instance .create_namespaced_ingress (
407
+ namespace = self .config .namespace , body = ingress_manifest
408
+ )
409
+ except Exception as e :
410
+ return _kube_api_error_handling (e )
362
411
363
412
def list_all_clusters (namespace : str , print_to_console : bool = True ):
364
413
"""
@@ -534,17 +583,15 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
534
583
status = RayClusterStatus .UNKNOWN
535
584
536
585
config_check ()
537
- api_instance = client .CustomObjectsApi (api_config_handler ())
538
- routes = api_instance .list_namespaced_custom_object (
539
- group = "route.openshift.io" ,
540
- version = "v1" ,
541
- namespace = rc ["metadata" ]["namespace" ],
542
- plural = "routes" ,
543
- )
586
+ api_instance = client .NetworkingV1Api (api_config_handler ())
587
+ ingresses = api_instance .list_namespaced_ingress (rc ["metadata" ]["namespace" ])
588
+
544
589
ray_route = None
545
- for route in routes ["items" ]:
546
- if route ["metadata" ]["name" ] == f"ray-dashboard-{ rc ['metadata' ]['name' ]} " :
547
- ray_route = route ["spec" ]["host" ]
590
+ for ingress in ingresses .items :
591
+ if ingress .metadata .name == f"ray-dashboard-{ rc ['metadata' ]['name' ]} " :
592
+ ray_route = ingress .spec .rules [0 ].host
593
+
594
+
548
595
549
596
return RayCluster (
550
597
name = rc ["metadata" ]["name" ],
0 commit comments