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