2626from kubernetes import config
2727from ray .job_submission import JobSubmissionClient
2828
29- from .auth import config_check , api_config_handler
29+ from .auth import config_check , get_api_client
3030from ..utils import pretty_print
3131from ..utils .generate_yaml import (
3232 generate_appwrapper ,
@@ -81,7 +81,7 @@ def __init__(self, config: ClusterConfiguration):
8181
8282 @property
8383 def _client_headers (self ):
84- k8_client = api_config_handler () or client . ApiClient ()
84+ k8_client = get_api_client ()
8585 return {
8686 "Authorization" : k8_client .configuration .get_api_key_with_prefix (
8787 "authorization"
@@ -96,7 +96,7 @@ def _client_verify_tls(self):
9696
9797 @property
9898 def job_client (self ):
99- k8client = api_config_handler () or client . ApiClient ()
99+ k8client = get_api_client ()
100100 if self ._job_submission_client :
101101 return self ._job_submission_client
102102 if is_openshift_cluster ():
@@ -142,7 +142,7 @@ def up(self):
142142
143143 try :
144144 config_check ()
145- api_instance = client .CustomObjectsApi (api_config_handler ())
145+ api_instance = client .CustomObjectsApi (get_api_client ())
146146 if self .config .appwrapper :
147147 if self .config .write_to_file :
148148 with open (self .app_wrapper_yaml ) as f :
@@ -173,7 +173,7 @@ def up(self):
173173 return _kube_api_error_handling (e )
174174
175175 def _throw_for_no_raycluster (self ):
176- api_instance = client .CustomObjectsApi (api_config_handler ())
176+ api_instance = client .CustomObjectsApi (get_api_client ())
177177 try :
178178 api_instance .list_namespaced_custom_object (
179179 group = "ray.io" ,
@@ -200,7 +200,7 @@ def down(self):
200200 self ._throw_for_no_raycluster ()
201201 try :
202202 config_check ()
203- api_instance = client .CustomObjectsApi (api_config_handler ())
203+ api_instance = client .CustomObjectsApi (get_api_client ())
204204 if self .config .appwrapper :
205205 api_instance .delete_namespaced_custom_object (
206206 group = "workload.codeflare.dev" ,
@@ -359,7 +359,7 @@ def cluster_dashboard_uri(self) -> str:
359359 config_check ()
360360 if is_openshift_cluster ():
361361 try :
362- api_instance = client .CustomObjectsApi (api_config_handler ())
362+ api_instance = client .CustomObjectsApi (get_api_client ())
363363 routes = api_instance .list_namespaced_custom_object (
364364 group = "route.openshift.io" ,
365365 version = "v1" ,
@@ -381,7 +381,7 @@ def cluster_dashboard_uri(self) -> str:
381381 return f"{ protocol } ://{ route ['spec' ]['host' ]} "
382382 else :
383383 try :
384- api_instance = client .NetworkingV1Api (api_config_handler ())
384+ api_instance = client .NetworkingV1Api (get_api_client ())
385385 ingresses = api_instance .list_namespaced_ingress (self .config .namespace )
386386 except Exception as e : # pragma no cover
387387 return _kube_api_error_handling (e )
@@ -580,9 +580,6 @@ def get_current_namespace(): # pragma: no cover
580580 return active_context
581581 except Exception as e :
582582 print ("Unable to find current namespace" )
583-
584- if api_config_handler () != None :
585- return None
586583 print ("trying to gather from current context" )
587584 try :
588585 _ , active_context = config .list_kube_config_contexts (config_check ())
@@ -602,7 +599,7 @@ def get_cluster(
602599):
603600 try :
604601 config_check ()
605- api_instance = client .CustomObjectsApi (api_config_handler ())
602+ api_instance = client .CustomObjectsApi (get_api_client ())
606603 rcs = api_instance .list_namespaced_custom_object (
607604 group = "ray.io" ,
608605 version = "v1" ,
@@ -657,7 +654,7 @@ def _create_resources(yamls, namespace: str, api_instance: client.CustomObjectsA
657654def _check_aw_exists (name : str , namespace : str ) -> bool :
658655 try :
659656 config_check ()
660- api_instance = client .CustomObjectsApi (api_config_handler ())
657+ api_instance = client .CustomObjectsApi (get_api_client ())
661658 aws = api_instance .list_namespaced_custom_object (
662659 group = "workload.codeflare.dev" ,
663660 version = "v1beta2" ,
@@ -684,7 +681,7 @@ def _get_ingress_domain(self): # pragma: no cover
684681
685682 if is_openshift_cluster ():
686683 try :
687- api_instance = client .CustomObjectsApi (api_config_handler ())
684+ api_instance = client .CustomObjectsApi (get_api_client ())
688685
689686 routes = api_instance .list_namespaced_custom_object (
690687 group = "route.openshift.io" ,
@@ -703,7 +700,7 @@ def _get_ingress_domain(self): # pragma: no cover
703700 domain = route ["spec" ]["host" ]
704701 else :
705702 try :
706- api_client = client .NetworkingV1Api (api_config_handler ())
703+ api_client = client .NetworkingV1Api (get_api_client ())
707704 ingresses = api_client .list_namespaced_ingress (namespace )
708705 except Exception as e : # pragma: no cover
709706 return _kube_api_error_handling (e )
@@ -717,7 +714,7 @@ def _get_ingress_domain(self): # pragma: no cover
717714def _app_wrapper_status (name , namespace = "default" ) -> Optional [AppWrapper ]:
718715 try :
719716 config_check ()
720- api_instance = client .CustomObjectsApi (api_config_handler ())
717+ api_instance = client .CustomObjectsApi (get_api_client ())
721718 aws = api_instance .list_namespaced_custom_object (
722719 group = "workload.codeflare.dev" ,
723720 version = "v1beta2" ,
@@ -736,7 +733,7 @@ def _app_wrapper_status(name, namespace="default") -> Optional[AppWrapper]:
736733def _ray_cluster_status (name , namespace = "default" ) -> Optional [RayCluster ]:
737734 try :
738735 config_check ()
739- api_instance = client .CustomObjectsApi (api_config_handler ())
736+ api_instance = client .CustomObjectsApi (get_api_client ())
740737 rcs = api_instance .list_namespaced_custom_object (
741738 group = "ray.io" ,
742739 version = "v1" ,
@@ -758,7 +755,7 @@ def _get_ray_clusters(
758755 list_of_clusters = []
759756 try :
760757 config_check ()
761- api_instance = client .CustomObjectsApi (api_config_handler ())
758+ api_instance = client .CustomObjectsApi (get_api_client ())
762759 rcs = api_instance .list_namespaced_custom_object (
763760 group = "ray.io" ,
764761 version = "v1" ,
@@ -787,7 +784,7 @@ def _get_app_wrappers(
787784
788785 try :
789786 config_check ()
790- api_instance = client .CustomObjectsApi (api_config_handler ())
787+ api_instance = client .CustomObjectsApi (get_api_client ())
791788 aws = api_instance .list_namespaced_custom_object (
792789 group = "workload.codeflare.dev" ,
793790 version = "v1beta2" ,
@@ -816,7 +813,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
816813 dashboard_url = None
817814 if is_openshift_cluster ():
818815 try :
819- api_instance = client .CustomObjectsApi (api_config_handler ())
816+ api_instance = client .CustomObjectsApi (get_api_client ())
820817 routes = api_instance .list_namespaced_custom_object (
821818 group = "route.openshift.io" ,
822819 version = "v1" ,
@@ -835,7 +832,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
835832 dashboard_url = f"{ protocol } ://{ route ['spec' ]['host' ]} "
836833 else :
837834 try :
838- api_instance = client .NetworkingV1Api (api_config_handler ())
835+ api_instance = client .NetworkingV1Api (get_api_client ())
839836 ingresses = api_instance .list_namespaced_ingress (
840837 rc ["metadata" ]["namespace" ]
841838 )
0 commit comments