Skip to content

Commit 976b96c

Browse files
committed
Updated config_check() function
1 parent c8ee3b9 commit 976b96c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/codeflare_sdk/cluster/auth.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import abc
2323
from kubernetes import client, config
24+
import os
2425

2526
global api_client
2627
api_client = None
@@ -161,14 +162,16 @@ def config_check() -> str:
161162
"""
162163
global config_path
163164
global api_client
165+
home_directory = os.path.expanduser("~")
164166
if config_path == None and api_client == None:
165-
try:
167+
if os.path.isfile("%s/.kube/config" % home_directory):
166168
config.load_kube_config()
167-
except config.config_exception.ConfigException:
168-
try:
169-
config.load_incluster_config()
170-
except:
171-
print("Unable to load config file or in cluster configuration")
169+
elif "KUBERNETES_PORT" in os.environ:
170+
config.load_incluster_config()
171+
else:
172+
print(
173+
"Unable to load config file or in cluster configuration, try specifying a config file path with load_kube_config()"
174+
)
172175

173176
if config_path != None and api_client == None:
174177
return config_path

0 commit comments

Comments
 (0)