Skip to content

Commit e83b4a9

Browse files
seperate auth from cluster methods
1 parent 433fd71 commit e83b4a9

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def login(self) -> str:
7474
error_msg = osp.result.err()
7575
if "The server uses a certificate signed by unknown authority" in error_msg:
7676
return "Error: certificate auth failure, please set `skip_tls=True` in TokenAuthentication"
77+
elif "invalid" in error_msg:
78+
raise PermissionError(error_msg)
7779
else:
7880
return error_msg
7981
return response.out()
@@ -82,7 +84,8 @@ def logout(self) -> str:
8284
"""
8385
This function is used to logout of an OpenShift cluster.
8486
"""
85-
response = oc.invoke("logout")
87+
args = [f"--token={self.token}", f"--server={self.server}:6443"]
88+
response = oc.invoke("logout", args)
8689
return response.out()
8790

8891

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

-4
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ def up(self):
9696
Applies the AppWrapper yaml, pushing the resource request onto
9797
the MCAD queue.
9898
"""
99-
resp = self.config.auth.login()
100-
if "invalid" in resp:
101-
raise PermissionError(resp)
10299
namespace = self.config.namespace
103100
try:
104101
with oc.project(namespace):
@@ -135,7 +132,6 @@ def down(self):
135132
print("Cluster not found, have you run cluster.up() yet?")
136133
else:
137134
raise osp
138-
self.config.auth.logout()
139135

140136
def status(
141137
self, print_to_console: bool = True

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

-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ class ClusterConfiguration:
4747
instascale: bool = False
4848
envs: dict = field(default_factory=dict)
4949
image: str = "ghcr.io/foundation-model-stack/base:ray2.1.0-py38-gpu-pytorch1.12.0cu116-20221213-193103"
50-
auth: Authentication = Authentication()

Diff for: tests/unit_test.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,10 @@ def test_token_auth_login_logout(mocker):
121121
"login",
122122
["--token=testtoken", "--server=testserver:6443"],
123123
)
124-
assert token_auth.logout() == ("logout",)
124+
assert token_auth.logout() == (
125+
"logout",
126+
["--token=testtoken", "--server=testserver:6443"],
127+
)
125128

126129

127130
def test_token_auth_login_tls(mocker):
@@ -198,7 +201,6 @@ def test_config_creation():
198201
gpu=7,
199202
instascale=True,
200203
machine_types=["cpu.small", "gpu.large"],
201-
auth=TokenAuthentication(token="testtoken", server="testserver"),
202204
)
203205

204206
assert config.name == "unit-test-cluster" and config.namespace == "ns"

0 commit comments

Comments
 (0)