@@ -492,7 +492,7 @@ def torchx_config(
492492 to_return ["requirements" ] = requirements
493493 return to_return
494494
495- def from_k8_cluster_object (rc , mcad = True , ingress_domain = None ):
495+ def from_k8_cluster_object (rc , mcad = True , ingress_domain = None , ingress_options = {} ):
496496 machine_types = (
497497 rc ["metadata" ]["labels" ]["orderedinstance" ].split ("_" )
498498 if "orderedinstance" in rc ["metadata" ]["labels" ]
@@ -502,6 +502,10 @@ def from_k8_cluster_object(rc, mcad=True, ingress_domain=None):
502502 "volumeMounts"
503503 in rc ["spec" ]["workerGroupSpecs" ][0 ]["template" ]["spec" ]["containers" ][0 ]
504504 )
505+ if local_interactive :
506+ ingress_domain = get_ingress_domain_from_client (
507+ rc ["metadata" ]["name" ], rc ["metadata" ]["namespace" ]
508+ )
505509 cluster_config = ClusterConfiguration (
506510 name = rc ["metadata" ]["name" ],
507511 namespace = rc ["metadata" ]["namespace" ],
@@ -533,6 +537,7 @@ def from_k8_cluster_object(rc, mcad=True, ingress_domain=None):
533537 local_interactive = local_interactive ,
534538 mcad = mcad ,
535539 ingress_domain = ingress_domain ,
540+ ingress_options = ingress_options ,
536541 )
537542 return Cluster (cluster_config )
538543
@@ -692,27 +697,55 @@ def get_cluster(cluster_name: str, namespace: str = "default"):
692697 api_instance = client .NetworkingV1Api (api_config_handler ())
693698 ingresses = api_instance .list_namespaced_ingress (namespace )
694699 ingress_host = None
695- if mcad == True :
696- for ingress in ingresses .items :
697- # Search for ingress with AppWrapper name as the owner
698- if cluster_name == ingress .metadata .owner_references [0 ].name :
699- ingress_host = ingress .spec .rules [0 ].host
700- else :
701- for ingress in ingresses .items :
702- # Search for the ingress with the ingress-owner label
703- if ingress .metadata .labels ["ingress-owner" ] == cluster_name :
704- ingress_host = ingress .spec .rules [0 ].host
700+ ingress_options = {}
701+ for ingress in ingresses .items :
702+ # Search for ingress with AppWrapper name as the owner
703+ if (
704+ "ingress-owner" in ingress .metadata .labels
705+ and ingress .metadata .labels ["ingress-owner" ] == cluster_name
706+ ):
707+ ingress_host = ingress .spec .rules [0 ].host
708+ if (
709+ "ingress-options" in ingress .metadata .labels
710+ and ingress .metadata .labels ["ingress-options" ] == "true"
711+ ):
712+ ingress_name = ingress .metadata .name
713+ port = (
714+ ingress .spec .rules [0 ]
715+ .http .paths [0 ]
716+ .backend .service .port .number
717+ )
718+ annotations = ingress .metadata .annotations
719+ path = ingress .spec .rules [0 ].http .paths [0 ].path
720+ ingress_class_name = ingress .spec .ingress_class_name
721+ path_type = ingress .spec .rules [0 ].http .paths [0 ].path_type
722+
723+ ingress_options = {
724+ "ingresses" : [
725+ {
726+ "ingressName" : ingress_name ,
727+ "port" : port ,
728+ "annotations" : annotations ,
729+ "ingressClassName" : ingress_class_name ,
730+ "pathType" : path_type ,
731+ "path" : path ,
732+ "host" : ingress_host ,
733+ }
734+ ]
735+ }
705736 except Exception as e :
706737 return _kube_api_error_handling (e )
707-
708738 # We gather the ingress domain from the host
709- if ingress_host is not None :
739+ if ingress_host is not None and ingress_options == {} :
710740 ingress_domain = ingress_host .split ("." , 1 )[1 ]
711741 else :
712742 ingress_domain = None
713743
714744 return Cluster .from_k8_cluster_object (
715- rc , mcad = mcad , ingress_domain = ingress_domain
745+ rc ,
746+ mcad = mcad ,
747+ ingress_domain = ingress_domain ,
748+ ingress_options = ingress_options ,
716749 )
717750 raise FileNotFoundError (
718751 f"Cluster { cluster_name } is not found in { namespace } namespace"
@@ -762,7 +795,10 @@ def _get_ingress_domain(self): # pragma: no cover
762795 return _kube_api_error_handling (e )
763796
764797 for route in routes ["items" ]:
765- if route ["spec" ]["port" ]["targetPort" ] == "client" :
798+ if (
799+ route ["spec" ]["port" ]["targetPort" ] == "client"
800+ or route ["spec" ]["port" ]["targetPort" ] == 10001
801+ ):
766802 domain = route ["spec" ]["host" ]
767803 else :
768804 try :
@@ -949,3 +985,30 @@ def _copy_to_ray(cluster: Cluster) -> RayCluster:
949985 if ray .status == CodeFlareClusterStatus .READY :
950986 ray .status = RayClusterStatus .READY
951987 return ray
988+
989+
990+ def get_ingress_domain_from_client (cluster_name : str , namespace : str = "default" ):
991+ if is_openshift_cluster ():
992+ try :
993+ config_check ()
994+ api_instance = client .CustomObjectsApi (api_config_handler ())
995+ route = api_instance .get_namespaced_custom_object (
996+ group = "route.openshift.io" ,
997+ version = "v1" ,
998+ namespace = namespace ,
999+ plural = "routes" ,
1000+ name = f"rayclient-{ cluster_name } " ,
1001+ )
1002+ return route ["spec" ]["host" ].split ("." , 1 )[1 ]
1003+ except Exception as e : # pragma no cover
1004+ return _kube_api_error_handling (e )
1005+ else :
1006+ try :
1007+ config_check ()
1008+ api_instance = client .NetworkingV1Api (api_config_handler ())
1009+ ingress = api_instance .read_namespaced_ingress (
1010+ f"rayclient-{ cluster_name } " , namespace
1011+ )
1012+ return ingress .spec .rules [0 ].host .split ("." , 1 )[1 ]
1013+ except Exception as e : # pragma no cover
1014+ return _kube_api_error_handling (e )
0 commit comments