Skip to content

Commit d85cee9

Browse files
committed
Altered comments and changed config_check() function
1 parent ce6be49 commit d85cee9

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

Diff for: src/codeflare_sdk/cluster/auth.py

+21-17
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import os
2424
from kubernetes import client, config
2525

26-
global path_set
27-
path_set = False
2826
global api_client
2927
api_client = None
28+
global config_path
29+
config_path = None
3030

3131

3232
class Authentication(metaclass=abc.ABCMeta):
@@ -61,7 +61,7 @@ def load_kube_config(self):
6161

6262
def config_check(self):
6363
"""
64-
Method for setting your Kubernetes configuration to a certain file
64+
Method for checking if a user is authenticated via token and server or with their own config file
6565
"""
6666
pass
6767

@@ -99,9 +99,9 @@ def login(self) -> str:
9999
"""
100100
This function is used to log in to a Kubernetes cluster using the user's API token and API server address.
101101
Depending on the cluster, a user can choose to login in with `--insecure-skip-tls-verify` by setting `skip_tls`
102-
to `True` or `--certificate-authority` by setting `skip_tls` to false and providing a path to a ca bundle with `ca_cert_path`.
102+
to `True` or `--certificate-authority` by setting `skip_tls` to False and providing a path to a ca bundle with `ca_cert_path`.
103103
"""
104-
global path_set
104+
global config_path
105105
global api_client
106106
try:
107107
configuration = client.Configuration()
@@ -113,16 +113,16 @@ def login(self) -> str:
113113
else:
114114
configuration.verify_ssl = False
115115
api_client = client.ApiClient(configuration)
116-
path_set = False
116+
config_path = None
117117
return "Logged into %s" % self.server
118118
except client.ApiException as exception:
119119
return exception
120120

121-
def api_config_handler():
121+
def api_config_handler() -> str:
122122
"""
123123
This function is used to load the api client if the user has logged in
124124
"""
125-
if api_client != None and path_set == False:
125+
if api_client != None and config_path == None:
126126
return api_client
127127
else:
128128
return None
@@ -131,10 +131,11 @@ def logout(self) -> str:
131131
"""
132132
This function is used to logout of a Kubernetes cluster.
133133
"""
134-
global path_set
135-
path_set = False
134+
global config_path
135+
config_path = None
136136
global api_client
137137
api_client = None
138+
return "Successfully logged out of %s" % self.server
138139

139140

140141
class KubeConfigFileAuthentication(KubeConfiguration):
@@ -150,24 +151,27 @@ def load_kube_config(self):
150151
"""
151152
Function for loading a user's own predefined Kubernetes config file.
152153
"""
153-
global path_set
154+
global config_path
154155
global api_client
155156
try:
156-
path_set = True
157+
if self.kube_config_path == None:
158+
return "Please specify a config file path"
159+
config_path = self.kube_config_path
157160
api_client = None
158-
config.load_kube_config(self.kube_config_path)
159161
response = "Loaded user config file at path %s" % self.kube_config_path
160162
except config.ConfigException:
161-
path_set = False
163+
config_path = None
162164
raise Exception("Please specify a config file path")
163165
return response
164166

165-
def config_check():
167+
def config_check() -> str:
166168
"""
167169
Function for loading the config file at the default config location ~/.kube/config if the user has not
168170
specified their own config file or has logged in with their token and server.
169171
"""
170-
global path_set
172+
global config_path
171173
global api_client
172-
if path_set == False and api_client == None:
174+
if config_path == None and api_client == None:
173175
config.load_kube_config()
176+
if config_path != None and api_client == None:
177+
return config_path

Diff for: src/codeflare_sdk/cluster/cluster.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,10 @@ def list_all_queued(namespace: str, print_to_console: bool = True):
383383

384384
def get_current_namespace(): # pragma: no cover
385385
try:
386-
KubeConfigFileAuthentication.config_check()
387-
_, active_context = config.list_kube_config_contexts()
386+
# KubeConfigFileAuthentication.config_check()
387+
_, active_context = config.list_kube_config_contexts(
388+
KubeConfigFileAuthentication.config_check()
389+
)
388390
except Exception as e:
389391
return _kube_api_error_handling(e)
390392
try:

0 commit comments

Comments
 (0)