25
25
from kubernetes import config
26
26
from ray .job_submission import JobSubmissionClient
27
27
28
- from .auth import config_check , api_config_handler
28
+ from .auth import config_check , get_api_client
29
29
from ..utils import pretty_print
30
30
from ..utils .generate_yaml import (
31
31
generate_appwrapper ,
@@ -80,7 +80,7 @@ def __init__(self, config: ClusterConfiguration):
80
80
81
81
@property
82
82
def _client_headers (self ):
83
- k8_client = api_config_handler () or client . ApiClient ()
83
+ k8_client = get_api_client ()
84
84
return {
85
85
"Authorization" : k8_client .configuration .get_api_key_with_prefix (
86
86
"authorization"
@@ -95,7 +95,7 @@ def _client_verify_tls(self):
95
95
96
96
@property
97
97
def job_client (self ):
98
- k8client = api_config_handler () or client . ApiClient ()
98
+ k8client = get_api_client ()
99
99
if self ._job_submission_client :
100
100
return self ._job_submission_client
101
101
if is_openshift_cluster ():
@@ -141,7 +141,7 @@ def up(self):
141
141
142
142
try :
143
143
config_check ()
144
- api_instance = client .CustomObjectsApi (api_config_handler ())
144
+ api_instance = client .CustomObjectsApi (get_api_client ())
145
145
if self .config .appwrapper :
146
146
if self .config .write_to_file :
147
147
with open (self .app_wrapper_yaml ) as f :
@@ -172,7 +172,7 @@ def up(self):
172
172
return _kube_api_error_handling (e )
173
173
174
174
def _throw_for_no_raycluster (self ):
175
- api_instance = client .CustomObjectsApi (api_config_handler ())
175
+ api_instance = client .CustomObjectsApi (get_api_client ())
176
176
try :
177
177
api_instance .list_namespaced_custom_object (
178
178
group = "ray.io" ,
@@ -199,7 +199,7 @@ def down(self):
199
199
self ._throw_for_no_raycluster ()
200
200
try :
201
201
config_check ()
202
- api_instance = client .CustomObjectsApi (api_config_handler ())
202
+ api_instance = client .CustomObjectsApi (get_api_client ())
203
203
if self .config .appwrapper :
204
204
api_instance .delete_namespaced_custom_object (
205
205
group = "workload.codeflare.dev" ,
@@ -358,7 +358,7 @@ def cluster_dashboard_uri(self) -> str:
358
358
config_check ()
359
359
if is_openshift_cluster ():
360
360
try :
361
- api_instance = client .CustomObjectsApi (api_config_handler ())
361
+ api_instance = client .CustomObjectsApi (get_api_client ())
362
362
routes = api_instance .list_namespaced_custom_object (
363
363
group = "route.openshift.io" ,
364
364
version = "v1" ,
@@ -380,7 +380,7 @@ def cluster_dashboard_uri(self) -> str:
380
380
return f"{ protocol } ://{ route ['spec' ]['host' ]} "
381
381
else :
382
382
try :
383
- api_instance = client .NetworkingV1Api (api_config_handler ())
383
+ api_instance = client .NetworkingV1Api (get_api_client ())
384
384
ingresses = api_instance .list_namespaced_ingress (self .config .namespace )
385
385
except Exception as e : # pragma no cover
386
386
return _kube_api_error_handling (e )
@@ -579,9 +579,6 @@ def get_current_namespace(): # pragma: no cover
579
579
return active_context
580
580
except Exception as e :
581
581
print ("Unable to find current namespace" )
582
-
583
- if api_config_handler () != None :
584
- return None
585
582
print ("trying to gather from current context" )
586
583
try :
587
584
_ , active_context = config .list_kube_config_contexts (config_check ())
@@ -601,7 +598,7 @@ def get_cluster(
601
598
):
602
599
try :
603
600
config_check ()
604
- api_instance = client .CustomObjectsApi (api_config_handler ())
601
+ api_instance = client .CustomObjectsApi (get_api_client ())
605
602
rcs = api_instance .list_namespaced_custom_object (
606
603
group = "ray.io" ,
607
604
version = "v1" ,
@@ -656,7 +653,7 @@ def _create_resources(yamls, namespace: str, api_instance: client.CustomObjectsA
656
653
def _check_aw_exists (name : str , namespace : str ) -> bool :
657
654
try :
658
655
config_check ()
659
- api_instance = client .CustomObjectsApi (api_config_handler ())
656
+ api_instance = client .CustomObjectsApi (get_api_client ())
660
657
aws = api_instance .list_namespaced_custom_object (
661
658
group = "workload.codeflare.dev" ,
662
659
version = "v1beta2" ,
@@ -683,7 +680,7 @@ def _get_ingress_domain(self): # pragma: no cover
683
680
684
681
if is_openshift_cluster ():
685
682
try :
686
- api_instance = client .CustomObjectsApi (api_config_handler ())
683
+ api_instance = client .CustomObjectsApi (get_api_client ())
687
684
688
685
routes = api_instance .list_namespaced_custom_object (
689
686
group = "route.openshift.io" ,
@@ -702,7 +699,7 @@ def _get_ingress_domain(self): # pragma: no cover
702
699
domain = route ["spec" ]["host" ]
703
700
else :
704
701
try :
705
- api_client = client .NetworkingV1Api (api_config_handler ())
702
+ api_client = client .NetworkingV1Api (get_api_client ())
706
703
ingresses = api_client .list_namespaced_ingress (namespace )
707
704
except Exception as e : # pragma: no cover
708
705
return _kube_api_error_handling (e )
@@ -716,7 +713,7 @@ def _get_ingress_domain(self): # pragma: no cover
716
713
def _app_wrapper_status (name , namespace = "default" ) -> Optional [AppWrapper ]:
717
714
try :
718
715
config_check ()
719
- api_instance = client .CustomObjectsApi (api_config_handler ())
716
+ api_instance = client .CustomObjectsApi (get_api_client ())
720
717
aws = api_instance .list_namespaced_custom_object (
721
718
group = "workload.codeflare.dev" ,
722
719
version = "v1beta2" ,
@@ -735,7 +732,7 @@ def _app_wrapper_status(name, namespace="default") -> Optional[AppWrapper]:
735
732
def _ray_cluster_status (name , namespace = "default" ) -> Optional [RayCluster ]:
736
733
try :
737
734
config_check ()
738
- api_instance = client .CustomObjectsApi (api_config_handler ())
735
+ api_instance = client .CustomObjectsApi (get_api_client ())
739
736
rcs = api_instance .list_namespaced_custom_object (
740
737
group = "ray.io" ,
741
738
version = "v1" ,
@@ -757,7 +754,7 @@ def _get_ray_clusters(
757
754
list_of_clusters = []
758
755
try :
759
756
config_check ()
760
- api_instance = client .CustomObjectsApi (api_config_handler ())
757
+ api_instance = client .CustomObjectsApi (get_api_client ())
761
758
rcs = api_instance .list_namespaced_custom_object (
762
759
group = "ray.io" ,
763
760
version = "v1" ,
@@ -786,7 +783,7 @@ def _get_app_wrappers(
786
783
787
784
try :
788
785
config_check ()
789
- api_instance = client .CustomObjectsApi (api_config_handler ())
786
+ api_instance = client .CustomObjectsApi (get_api_client ())
790
787
aws = api_instance .list_namespaced_custom_object (
791
788
group = "workload.codeflare.dev" ,
792
789
version = "v1beta2" ,
@@ -815,7 +812,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
815
812
dashboard_url = None
816
813
if is_openshift_cluster ():
817
814
try :
818
- api_instance = client .CustomObjectsApi (api_config_handler ())
815
+ api_instance = client .CustomObjectsApi (get_api_client ())
819
816
routes = api_instance .list_namespaced_custom_object (
820
817
group = "route.openshift.io" ,
821
818
version = "v1" ,
@@ -834,7 +831,7 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
834
831
dashboard_url = f"{ protocol } ://{ route ['spec' ]['host' ]} "
835
832
else :
836
833
try :
837
- api_instance = client .NetworkingV1Api (api_config_handler ())
834
+ api_instance = client .NetworkingV1Api (get_api_client ())
838
835
ingresses = api_instance .list_namespaced_ingress (
839
836
rc ["metadata" ]["namespace" ]
840
837
)
0 commit comments