File tree 2 files changed +25
-12
lines changed
src/codeflare_sdk/cluster
2 files changed +25
-12
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,7 @@ def load_kube_config(self):
158
158
return "Please specify a config file path"
159
159
config_path = self .kube_config_path
160
160
api_client = None
161
+ config .load_kube_config (config_path )
161
162
response = "Loaded user config file at path %s" % self .kube_config_path
162
163
except config .ConfigException :
163
164
config_path = None
Original file line number Diff line number Diff line change 37
37
)
38
38
from kubernetes import client , config
39
39
import yaml
40
-
40
+ import os
41
41
42
42
class Cluster :
43
43
"""
@@ -382,17 +382,29 @@ def list_all_queued(namespace: str, print_to_console: bool = True):
382
382
383
383
384
384
def get_current_namespace (): # pragma: no cover
385
- try :
386
- # KubeConfigFileAuthentication.config_check()
387
- _ , active_context = config .list_kube_config_contexts (
388
- KubeConfigFileAuthentication .config_check ()
389
- )
390
- except Exception as e :
391
- return _kube_api_error_handling (e )
392
- try :
393
- return active_context ["context" ]["namespace" ]
394
- except KeyError :
395
- return "default"
385
+ namespace_error = "Unable to find current namespace please specify with namespace=<your_current_namespace>"
386
+ if TokenAuthentication .api_config_handler () != None :
387
+ if os .path .isfile ("/var/run/secrets/kubernetes.io/serviceaccount/namespace" ):
388
+ try :
389
+ file = open ("/var/run/secrets/kubernetes.io/serviceaccount/namespace" , "r" )
390
+ active_context = file .readline ().strip ('\n ' )
391
+ return active_context
392
+ except Exception as e :
393
+ return namespace_error
394
+ else :
395
+ return namespace_error
396
+ else :
397
+ try :
398
+ # KubeConfigFileAuthentication.config_check()
399
+ _ , active_context = config .list_kube_config_contexts (
400
+ KubeConfigFileAuthentication .config_check ()
401
+ )
402
+ except Exception as e :
403
+ return _kube_api_error_handling (e )
404
+ try :
405
+ return active_context ["context" ]["namespace" ]
406
+ except KeyError :
407
+ return namespace_error
396
408
397
409
398
410
def get_cluster (cluster_name : str , namespace : str = "default" ):
You can’t perform that action at this time.
0 commit comments