28
28
29
29
from .auth import config_check , api_config_handler
30
30
from ..utils import pretty_print
31
- from ..utils .generate_yaml import generate_appwrapper
31
+ from ..utils .generate_yaml import (
32
+ generate_appwrapper ,
33
+ )
32
34
from ..utils .kube_api_helpers import _kube_api_error_handling
33
35
from ..utils .openshift_oauth import (
34
36
create_openshift_oauth_objects ,
@@ -175,6 +177,8 @@ def create_app_wrapper(self):
175
177
local_interactive = self .config .local_interactive
176
178
image_pull_secrets = self .config .image_pull_secrets
177
179
dispatch_priority = self .config .dispatch_priority
180
+ ingress_domain = self .config .ingress_domain
181
+ ingress_options = self .config .ingress_options
178
182
return generate_appwrapper (
179
183
name = name ,
180
184
namespace = namespace ,
@@ -198,6 +202,8 @@ def create_app_wrapper(self):
198
202
dispatch_priority = dispatch_priority ,
199
203
priority_val = priority_val ,
200
204
openshift_oauth = self .config .openshift_oauth ,
205
+ ingress_domain = ingress_domain ,
206
+ ingress_options = ingress_options ,
201
207
)
202
208
203
209
# creates a new cluster with the provided or default spec
@@ -399,27 +405,22 @@ def cluster_dashboard_uri(self) -> str:
399
405
"""
400
406
try :
401
407
config_check ()
402
- api_instance = client .CustomObjectsApi (api_config_handler ())
403
- routes = api_instance .list_namespaced_custom_object (
404
- group = "route.openshift.io" ,
405
- version = "v1" ,
406
- namespace = self .config .namespace ,
407
- plural = "routes" ,
408
- )
409
- except Exception as e : # pragma: no cover
408
+ api_instance = client .NetworkingV1Api (api_config_handler ())
409
+ ingresses = api_instance .list_namespaced_ingress (self .config .namespace )
410
+ except Exception as e :
410
411
return _kube_api_error_handling (e )
411
412
412
- for route in routes ["items" ]:
413
- if route ["metadata" ][
414
- "name"
415
- ] == f"ray-dashboard-{ self .config .name } " or route ["metadata" ][
416
- "name"
417
- ].startswith (
418
- f"{ self .config .name } -ingress"
419
- ):
420
- protocol = "https" if route ["spec" ].get ("tls" ) else "http"
421
- return f"{ protocol } ://{ route ['spec' ]['host' ]} "
413
+ for ingress in ingresses .items :
414
+ annotations = ingress .metadata .annotations
415
+ if ingress .metadata .name == f"ray-dashboard-{ self .config .name } " or ingress .metadata .name .startswith (
416
+ f"{ self .config .name } -ingress" ):
417
+ if annotations == None :
418
+ protocol = "http"
419
+ elif "route.openshift.io/termination" in annotations :
420
+ protocol = "https"
421
+ return f"{ protocol } ://{ ingress .spec .rules [0 ].host } "
422
422
return "Dashboard route not available yet, have you run cluster.up()?"
423
+
423
424
424
425
def list_jobs (self ) -> List :
425
426
"""
@@ -498,8 +499,8 @@ def from_k8_cluster_object(rc, mcad=True):
498
499
499
500
def local_client_url (self ):
500
501
if self .config .local_interactive == True :
501
- ingress_domain = _get_ingress_domain ()
502
- return f"ray://rayclient- { self . config . name } - { self . config . namespace } . { ingress_domain } "
502
+ ingress_domain = _get_ingress_domain (self )
503
+ return f"ray://{ ingress_domain } "
503
504
else :
504
505
return "None"
505
506
@@ -655,16 +656,23 @@ def _check_aw_exists(name: str, namespace: str) -> bool:
655
656
return False
656
657
657
658
658
- def _get_ingress_domain ():
659
+ # Cant test this until get_current_namespace is fixed
660
+ def _get_ingress_domain (self ): # pragma: no cover
659
661
try :
660
662
config_check ()
661
- api_client = client .CustomObjectsApi (api_config_handler ())
662
- ingress = api_client .get_cluster_custom_object (
663
- "config.openshift.io" , "v1" , "ingresses" , "cluster"
664
- )
665
- except Exception as e : # pragma: no cover
663
+ api_client = client .NetworkingV1Api (api_config_handler ())
664
+ if self .config .namespace != None :
665
+ namespace = self .config .namespace
666
+ else :
667
+ namespace = get_current_namespace ()
668
+ ingresses = api_client .list_namespaced_ingress (namespace )
669
+ except Exception as e : # pragma: no cover
666
670
return _kube_api_error_handling (e )
667
- return ingress ["spec" ]["domain" ]
671
+ domain = None
672
+ for ingress in ingresses .items :
673
+ if ingress .spec .rules [0 ].http .paths [0 ].backend .service .port .number == 10001 :
674
+ domain = ingress .spec .rules [0 ].host
675
+ return domain
668
676
669
677
670
678
def _app_wrapper_status (name , namespace = "default" ) -> Optional [AppWrapper ]:
@@ -756,27 +764,22 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
756
764
status = RayClusterStatus (rc ["status" ]["state" ].lower ())
757
765
else :
758
766
status = RayClusterStatus .UNKNOWN
759
-
760
- config_check ()
761
- api_instance = client .CustomObjectsApi (api_config_handler ())
762
- # UPDATE THIS
763
- routes = api_instance .list_namespaced_custom_object (
764
- group = "route.openshift.io" ,
765
- version = "v1" ,
766
- namespace = rc ["metadata" ]["namespace" ],
767
- plural = "routes" ,
768
- )
769
- ray_route = None
770
- for route in routes ["items" ]:
771
- if route ["metadata" ][
772
- "name"
773
- ] == f"ray-dashboard-{ rc ['metadata' ]['name' ]} " or route ["metadata" ][
774
- "name"
775
- ].startswith (
776
- f"{ rc ['metadata' ]['name' ]} -ingress"
777
- ):
778
- protocol = "https" if route ["spec" ].get ("tls" ) else "http"
779
- ray_route = f"{ protocol } ://{ route ['spec' ]['host' ]} "
767
+ try :
768
+ config_check ()
769
+ api_instance = client .NetworkingV1Api (api_config_handler ())
770
+ ingresses = api_instance .list_namespaced_ingress (rc ["metadata" ]["namespace" ])
771
+ except Exception as e :
772
+ return _kube_api_error_handling (e )
773
+ ray_ingress = None
774
+ for ingress in ingresses .items :
775
+ annotations = ingress .metadata .annotations
776
+ if ingress .metadata .name == f"ray-dashboard-{ rc ['metadata' ]['name' ]} " or ingress .metadata .name .startswith (
777
+ f"{ rc ['metadata' ]['name' ]} -ingress" ):
778
+ if annotations == None :
779
+ protocol = "http"
780
+ elif "route.openshift.io/termination" in annotations :
781
+ protocol = "https"
782
+ ray_ingress = f"{ protocol } ://{ ingress .spec .rules [0 ].host } "
780
783
781
784
return RayCluster (
782
785
name = rc ["metadata" ]["name" ],
@@ -794,7 +797,6 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
794
797
]["resources" ]["limits" ]["cpu" ],
795
798
worker_gpu = 0 , # hard to detect currently how many gpus, can override it with what the user asked for
796
799
namespace = rc ["metadata" ]["namespace" ],
797
- dashboard = ray_route ,
798
800
head_cpus = rc ["spec" ]["headGroupSpec" ]["template" ]["spec" ]["containers" ][0 ][
799
801
"resources"
800
802
]["limits" ]["cpu" ],
@@ -804,6 +806,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
804
806
head_gpu = rc ["spec" ]["headGroupSpec" ]["template" ]["spec" ]["containers" ][0 ][
805
807
"resources"
806
808
]["limits" ]["nvidia.com/gpu" ],
809
+ dashboard = ray_ingress ,
807
810
)
808
811
809
812
0 commit comments