32
32
generate_appwrapper ,
33
33
)
34
34
from ..utils .kube_api_helpers import _kube_api_error_handling
35
+ from ..utils .generate_yaml import is_openshift_cluster
35
36
from ..utils .openshift_oauth import (
36
37
create_openshift_oauth_objects ,
37
38
delete_openshift_oauth_objects ,
@@ -189,7 +190,7 @@ def create_app_wrapper(self):
189
190
local_interactive = self .config .local_interactive
190
191
image_pull_secrets = self .config .image_pull_secrets
191
192
dispatch_priority = self .config .dispatch_priority
192
- domain_name = self .config .domain_name
193
+ ingress_domain = self .config .ingress_domain
193
194
ingress_options = self .config .ingress_options
194
195
return generate_appwrapper (
195
196
name = name ,
@@ -214,7 +215,7 @@ def create_app_wrapper(self):
214
215
dispatch_priority = dispatch_priority ,
215
216
priority_val = priority_val ,
216
217
openshift_oauth = self .config .openshift_oauth ,
217
- domain_name = domain_name ,
218
+ ingress_domain = ingress_domain ,
218
219
ingress_options = ingress_options ,
219
220
)
220
221
@@ -415,25 +416,48 @@ def cluster_dashboard_uri(self) -> str:
415
416
"""
416
417
Returns a string containing the cluster's dashboard URI.
417
418
"""
418
- try :
419
- config_check ()
420
- api_instance = client .NetworkingV1Api (api_config_handler ())
421
- ingresses = api_instance .list_namespaced_ingress (self .config .namespace )
422
- except Exception as e : # pragma no cover
423
- return _kube_api_error_handling (e )
419
+ config_check ()
420
+ if is_openshift_cluster ():
421
+ try :
422
+ api_instance = client .CustomObjectsApi (api_config_handler ())
423
+ routes = api_instance .list_namespaced_custom_object (
424
+ group = "route.openshift.io" ,
425
+ version = "v1" ,
426
+ namespace = self .config .namespace ,
427
+ plural = "routes" ,
428
+ )
429
+ except Exception as e : # pragma: no cover
430
+ return _kube_api_error_handling (e )
431
+
432
+ for route in routes ["items" ]:
433
+ if route ["metadata" ][
434
+ "name"
435
+ ] == f"ray-dashboard-{ self .config .name } " or route ["metadata" ][
436
+ "name"
437
+ ].startswith (
438
+ f"{ self .config .name } -ingress"
439
+ ):
440
+ protocol = "https" if route ["spec" ].get ("tls" ) else "http"
441
+ return f"{ protocol } ://{ route ['spec' ]['host' ]} "
442
+ else :
443
+ try :
444
+ api_instance = client .NetworkingV1Api (api_config_handler ())
445
+ ingresses = api_instance .list_namespaced_ingress (self .config .namespace )
446
+ except Exception as e : # pragma no cover
447
+ return _kube_api_error_handling (e )
424
448
425
- for ingress in ingresses .items :
426
- annotations = ingress .metadata .annotations
427
- protocol = "http"
428
- if (
429
- ingress .metadata .name == f"ray-dashboard-{ self .config .name } "
430
- or ingress .metadata .name .startswith (f"{ self .config .name } -ingress" )
431
- ):
432
- if annotations == None :
433
- protocol = "http"
434
- elif "route.openshift.io/termination" in annotations :
435
- protocol = "https"
436
- return f"{ protocol } ://{ ingress .spec .rules [0 ].host } "
449
+ for ingress in ingresses .items :
450
+ annotations = ingress .metadata .annotations
451
+ protocol = "http"
452
+ if (
453
+ ingress .metadata .name == f"ray-dashboard-{ self .config .name } "
454
+ or ingress .metadata .name .startswith (f"{ self .config .name } -ingress" )
455
+ ):
456
+ if annotations == None :
457
+ protocol = "http"
458
+ elif "route.openshift.io/termination" in annotations :
459
+ protocol = "https"
460
+ return f"{ protocol } ://{ ingress .spec .rules [0 ].host } "
437
461
return "Dashboard ingress not available yet, have you run cluster.up()?"
438
462
439
463
def list_jobs (self ) -> List :
@@ -468,7 +492,7 @@ def torchx_config(
468
492
to_return ["requirements" ] = requirements
469
493
return to_return
470
494
471
- def from_k8_cluster_object (rc , mcad = True , domain_name = None ):
495
+ def from_k8_cluster_object (rc , mcad = True , ingress_domain = None ):
472
496
machine_types = (
473
497
rc ["metadata" ]["labels" ]["orderedinstance" ].split ("_" )
474
498
if "orderedinstance" in rc ["metadata" ]["labels" ]
@@ -508,7 +532,7 @@ def from_k8_cluster_object(rc, mcad=True, domain_name=None):
508
532
]["image" ],
509
533
local_interactive = local_interactive ,
510
534
mcad = mcad ,
511
- domain_name = domain_name ,
535
+ ingress_domain = ingress_domain ,
512
536
)
513
537
return Cluster (cluster_config )
514
538
@@ -533,6 +557,14 @@ def _component_resources_up(
533
557
plural = "rayclusters" ,
534
558
body = resource ,
535
559
)
560
+ elif resource ["kind" ] == "Ingress" :
561
+ api_instance .create_namespaced_custom_object (
562
+ group = "networking.k8s.io" ,
563
+ version = "v1" ,
564
+ namespace = namespace ,
565
+ plural = "ingresses" ,
566
+ body = resource ,
567
+ )
536
568
elif resource ["kind" ] == "Route" :
537
569
api_instance .create_namespaced_custom_object (
538
570
group = "route.openshift.io" ,
@@ -562,6 +594,15 @@ def _component_resources_down(
562
594
plural = "rayclusters" ,
563
595
name = self .app_wrapper_name ,
564
596
)
597
+ elif resource ["kind" ] == "Ingress" :
598
+ name = resource ["metadata" ]["name" ]
599
+ api_instance .delete_namespaced_custom_object (
600
+ group = "networking.k8s.io" ,
601
+ version = "v1" ,
602
+ namespace = namespace ,
603
+ plural = "ingresses" ,
604
+ name = name ,
605
+ )
565
606
elif resource ["kind" ] == "Route" :
566
607
name = resource ["metadata" ]["name" ]
567
608
api_instance .delete_namespaced_custom_object (
@@ -629,7 +670,7 @@ def get_current_namespace(): # pragma: no cover
629
670
return None
630
671
631
672
632
- def get_cluster (cluster_name : str , namespace : str = "default" ):
673
+ def get_cluster (cluster_name : str , namespace : str = "default" , ingress_domain = None ):
633
674
try :
634
675
config_check ()
635
676
api_instance = client .CustomObjectsApi (api_config_handler ())
@@ -645,9 +686,8 @@ def get_cluster(cluster_name: str, namespace: str = "default"):
645
686
for rc in rcs ["items" ]:
646
687
if rc ["metadata" ]["name" ] == cluster_name :
647
688
mcad = _check_aw_exists (cluster_name , namespace )
648
- domain_name = _extract_domain_name (cluster_name , namespace )
649
689
return Cluster .from_k8_cluster_object (
650
- rc , mcad = mcad , domain_name = domain_name
690
+ rc , mcad = mcad , ingress_domain = ingress_domain
651
691
)
652
692
raise FileNotFoundError (
653
693
f"Cluster { cluster_name } is not found in { namespace } namespace"
@@ -673,49 +713,42 @@ def _check_aw_exists(name: str, namespace: str) -> bool:
673
713
return False
674
714
675
715
676
- def _extract_domain_name (name : str , namespace : str ) -> str :
677
- try :
678
- config_check ()
679
- api_instance = client .CustomObjectsApi (api_config_handler ())
680
- aws = api_instance .list_namespaced_custom_object (
681
- group = "workload.codeflare.dev" ,
682
- version = "v1beta1" ,
683
- namespace = namespace ,
684
- plural = "appwrappers" ,
685
- )
686
- except Exception as e : # pragma: no cover
687
- return _kube_api_error_handling (e , print_error = False )
688
- for aw in aws ["items" ]:
689
- if aw ["metadata" ]["name" ] == name :
690
- host = aw ["spec" ]["resources" ]["GenericItems" ][1 ]["generictemplate" ][
691
- "spec"
692
- ]["rules" ][0 ]["host" ]
693
-
694
- dot_index = host .find ("." )
695
- if dot_index != - 1 :
696
- domain_name = host [dot_index + 1 :]
697
- return domain_name
698
- else :
699
- print ("Host is not configured correctly." )
700
- return None
701
-
702
-
703
716
# Cant test this until get_current_namespace is fixed and placed in this function over using `self`
704
717
def _get_ingress_domain (self ): # pragma: no cover
705
- try :
706
- config_check ()
707
- api_client = client .NetworkingV1Api (api_config_handler ())
708
- if self .config .namespace != None :
709
- namespace = self .config .namespace
710
- else :
711
- namespace = get_current_namespace ()
712
- ingresses = api_client .list_namespaced_ingress (namespace )
713
- except Exception as e : # pragma: no cover
714
- return _kube_api_error_handling (e )
718
+ config_check ()
719
+
720
+ if self .config .namespace != None :
721
+ namespace = self .config .namespace
722
+ else :
723
+ namespace = get_current_namespace ()
715
724
domain = None
716
- for ingress in ingresses .items :
717
- if ingress .spec .rules [0 ].http .paths [0 ].backend .service .port .number == 10001 :
718
- domain = ingress .spec .rules [0 ].host
725
+
726
+ if is_openshift_cluster ():
727
+ try :
728
+ api_instance = client .CustomObjectsApi (api_config_handler ())
729
+
730
+ routes = api_instance .list_namespaced_custom_object (
731
+ group = "route.openshift.io" ,
732
+ version = "v1" ,
733
+ namespace = namespace ,
734
+ plural = "routes" ,
735
+ )
736
+ except Exception as e : # pragma: no cover
737
+ return _kube_api_error_handling (e )
738
+
739
+ for route in routes ["items" ]:
740
+ if route ["spec" ]["port" ]["targetPort" ] == "client" :
741
+ domain = route ["spec" ]["host" ]
742
+ else :
743
+ try :
744
+ api_client = client .NetworkingV1Api (api_config_handler ())
745
+ ingresses = api_client .list_namespaced_ingress (namespace )
746
+ except Exception as e : # pragma: no cover
747
+ return _kube_api_error_handling (e )
748
+
749
+ for ingress in ingresses .items :
750
+ if ingress .spec .rules [0 ].http .paths [0 ].backend .service .port .number == 10001 :
751
+ domain = ingress .spec .rules [0 ].host
719
752
return domain
720
753
721
754
0 commit comments