23
23
24
24
from ray .job_submission import JobSubmissionClient
25
25
26
- from .auth import KubeConfigFileAuthentication , TokenAuthentication
26
+ from .auth import config_check , api_config_handler
27
27
from ..utils import pretty_print
28
28
from ..utils .generate_yaml import generate_appwrapper
29
29
from ..utils .kube_api_helpers import _kube_api_error_handling
@@ -69,7 +69,11 @@ def create_app_wrapper(self):
69
69
70
70
if self .config .namespace is None :
71
71
self .config .namespace = get_current_namespace ()
72
- if type (self .config .namespace ) is not str :
72
+ if self .config .namespace is None :
73
+ print (
74
+ "Unable to find current namespace please specify with namespace=<your_current_namespace>"
75
+ )
76
+ elif type (self .config .namespace ) is not str :
73
77
raise TypeError (
74
78
f"Namespace { self .config .namespace } is of type { type (self .config .namespace )} . Check your Kubernetes Authentication."
75
79
)
@@ -115,10 +119,8 @@ def up(self):
115
119
"""
116
120
namespace = self .config .namespace
117
121
try :
118
- KubeConfigFileAuthentication .config_check ()
119
- api_instance = client .CustomObjectsApi (
120
- TokenAuthentication .api_config_handler ()
121
- )
122
+ config_check ()
123
+ api_instance = client .CustomObjectsApi (api_config_handler ())
122
124
with open (self .app_wrapper_yaml ) as f :
123
125
aw = yaml .load (f , Loader = yaml .FullLoader )
124
126
api_instance .create_namespaced_custom_object (
@@ -138,10 +140,8 @@ def down(self):
138
140
"""
139
141
namespace = self .config .namespace
140
142
try :
141
- KubeConfigFileAuthentication .config_check ()
142
- api_instance = client .CustomObjectsApi (
143
- TokenAuthentication .api_config_handler ()
144
- )
143
+ config_check ()
144
+ api_instance = client .CustomObjectsApi (api_config_handler ())
145
145
api_instance .delete_namespaced_custom_object (
146
146
group = "mcad.ibm.com" ,
147
147
version = "v1beta1" ,
@@ -252,10 +252,8 @@ def cluster_dashboard_uri(self) -> str:
252
252
Returns a string containing the cluster's dashboard URI.
253
253
"""
254
254
try :
255
- KubeConfigFileAuthentication .config_check ()
256
- api_instance = client .CustomObjectsApi (
257
- TokenAuthentication .api_config_handler ()
258
- )
255
+ config_check ()
256
+ api_instance = client .CustomObjectsApi (api_config_handler ())
259
257
routes = api_instance .list_namespaced_custom_object (
260
258
group = "route.openshift.io" ,
261
259
version = "v1" ,
@@ -383,8 +381,7 @@ def list_all_queued(namespace: str, print_to_console: bool = True):
383
381
384
382
385
383
def get_current_namespace (): # pragma: no cover
386
- namespace_error = "Unable to find current namespace please specify with namespace=<your_current_namespace>"
387
- if TokenAuthentication .api_config_handler () != None :
384
+ if api_config_handler () != None :
388
385
if os .path .isfile ("/var/run/secrets/kubernetes.io/serviceaccount/namespace" ):
389
386
try :
390
387
file = open (
@@ -393,21 +390,20 @@ def get_current_namespace(): # pragma: no cover
393
390
active_context = file .readline ().strip ("\n " )
394
391
return active_context
395
392
except Exception as e :
396
- return namespace_error
393
+ print ("Unable to find current namespace" )
394
+ return None
397
395
else :
398
- return namespace_error
396
+ print ("Unable to find current namespace" )
397
+ return None
399
398
else :
400
399
try :
401
- # KubeConfigFileAuthentication.config_check()
402
- _ , active_context = config .list_kube_config_contexts (
403
- KubeConfigFileAuthentication .config_check ()
404
- )
400
+ _ , active_context = config .list_kube_config_contexts (config_check ())
405
401
except Exception as e :
406
402
return _kube_api_error_handling (e )
407
403
try :
408
404
return active_context ["context" ]["namespace" ]
409
405
except KeyError :
410
- return namespace_error
406
+ return None
411
407
412
408
413
409
def get_cluster (cluster_name : str , namespace : str = "default" ):
@@ -446,8 +442,8 @@ def _get_ingress_domain():
446
442
447
443
def _app_wrapper_status (name , namespace = "default" ) -> Optional [AppWrapper ]:
448
444
try :
449
- KubeConfigFileAuthentication . config_check ()
450
- api_instance = client .CustomObjectsApi (TokenAuthentication . api_config_handler ())
445
+ config_check ()
446
+ api_instance = client .CustomObjectsApi (api_config_handler ())
451
447
aws = api_instance .list_namespaced_custom_object (
452
448
group = "mcad.ibm.com" ,
453
449
version = "v1beta1" ,
@@ -465,8 +461,8 @@ def _app_wrapper_status(name, namespace="default") -> Optional[AppWrapper]:
465
461
466
462
def _ray_cluster_status (name , namespace = "default" ) -> Optional [RayCluster ]:
467
463
try :
468
- KubeConfigFileAuthentication . config_check ()
469
- api_instance = client .CustomObjectsApi (TokenAuthentication . api_config_handler ())
464
+ config_check ()
465
+ api_instance = client .CustomObjectsApi (api_config_handler ())
470
466
rcs = api_instance .list_namespaced_custom_object (
471
467
group = "ray.io" ,
472
468
version = "v1alpha1" ,
@@ -485,8 +481,8 @@ def _ray_cluster_status(name, namespace="default") -> Optional[RayCluster]:
485
481
def _get_ray_clusters (namespace = "default" ) -> List [RayCluster ]:
486
482
list_of_clusters = []
487
483
try :
488
- KubeConfigFileAuthentication . config_check ()
489
- api_instance = client .CustomObjectsApi (TokenAuthentication . api_config_handler ())
484
+ config_check ()
485
+ api_instance = client .CustomObjectsApi (api_config_handler ())
490
486
rcs = api_instance .list_namespaced_custom_object (
491
487
group = "ray.io" ,
492
488
version = "v1alpha1" ,
@@ -507,8 +503,8 @@ def _get_app_wrappers(
507
503
list_of_app_wrappers = []
508
504
509
505
try :
510
- KubeConfigFileAuthentication . config_check ()
511
- api_instance = client .CustomObjectsApi (TokenAuthentication . api_config_handler ())
506
+ config_check ()
507
+ api_instance = client .CustomObjectsApi (api_config_handler ())
512
508
aws = api_instance .list_namespaced_custom_object (
513
509
group = "mcad.ibm.com" ,
514
510
version = "v1beta1" ,
@@ -534,8 +530,8 @@ def _map_to_ray_cluster(rc) -> Optional[RayCluster]:
534
530
else :
535
531
status = RayClusterStatus .UNKNOWN
536
532
537
- KubeConfigFileAuthentication . config_check ()
538
- api_instance = client .CustomObjectsApi (TokenAuthentication . api_config_handler ())
533
+ config_check ()
534
+ api_instance = client .CustomObjectsApi (api_config_handler ())
539
535
routes = api_instance .list_namespaced_custom_object (
540
536
group = "route.openshift.io" ,
541
537
version = "v1" ,
0 commit comments