Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit be29bd8

Browse files
committedOct 23, 2023
add: abstraction to remove appwrapper yaml visibility from the NB console.
1 parent 2441f4f commit be29bd8

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed
 

‎src/codeflare_sdk/cluster/cluster.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def __init__(self, config: ClusterConfiguration):
6969
"""
7070
self.config = config
7171
self.app_wrapper_yaml = self.create_app_wrapper()
72-
self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
72+
self.app_wrapper_name = self.app_wrapper_yaml.replace(".yaml", "").split("/")[
73+
-1
74+
]
7375
self._client = None
7476

7577
@property

‎src/codeflare_sdk/utils/generate_yaml.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import yaml
2121
import sys
22+
import os
2223
import argparse
2324
import uuid
2425
from kubernetes import client, config
@@ -375,8 +376,14 @@ def disable_raycluster_tls(resources):
375376

376377

377378
def write_user_appwrapper(user_yaml, output_file_name):
379+
# Create the directory if it doesn't exist
380+
directory_path = os.path.dirname(output_file_name)
381+
if not os.path.exists(directory_path):
382+
os.makedirs(directory_path)
383+
378384
with open(output_file_name, "w") as outfile:
379385
yaml.dump(user_yaml, outfile, default_flow_style=False)
386+
380387
print(f"Written to: {output_file_name}")
381388

382389

@@ -526,6 +533,7 @@ def generate_appwrapper(
526533
if openshift_oauth:
527534
enable_openshift_oauth(user_yaml, cluster_name, namespace)
528535

529-
outfile = appwrapper_name + ".yaml"
536+
directory_path = os.path.expanduser("~/.codeflare/appwrapper/")
537+
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
530538
write_user_appwrapper(user_yaml, outfile)
531539
return outfile

‎tests/unit_test.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import re
2222

2323
parent = Path(__file__).resolve().parents[1]
24+
aw_dir = os.path.expanduser("~/.codeflare/appwrapper/")
2425
sys.path.append(str(parent) + "/src")
2526

2627
from kubernetes import client, config
@@ -246,10 +247,12 @@ def test_config_creation():
246247

247248
def test_cluster_creation():
248249
cluster = createClusterWithConfig()
249-
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
250+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster.yaml"
250251
assert cluster.app_wrapper_name == "unit-test-cluster"
251252
assert filecmp.cmp(
252-
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
253+
f"{aw_dir}unit-test-cluster.yaml",
254+
f"{parent}/tests/test-case.yaml",
255+
shallow=True,
253256
)
254257

255258

@@ -263,10 +266,12 @@ def test_cluster_creation_priority(mocker):
263266
config.name = "prio-test-cluster"
264267
config.dispatch_priority = "default"
265268
cluster = Cluster(config)
266-
assert cluster.app_wrapper_yaml == "prio-test-cluster.yaml"
269+
assert cluster.app_wrapper_yaml == f"{aw_dir}prio-test-cluster.yaml"
267270
assert cluster.app_wrapper_name == "prio-test-cluster"
268271
assert filecmp.cmp(
269-
"prio-test-cluster.yaml", f"{parent}/tests/test-case-prio.yaml", shallow=True
272+
f"{aw_dir}prio-test-cluster.yaml",
273+
f"{parent}/tests/test-case-prio.yaml",
274+
shallow=True,
270275
)
271276

272277

@@ -280,7 +285,7 @@ def test_default_cluster_creation(mocker):
280285
)
281286
cluster = Cluster(default_config)
282287

283-
assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
288+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-default-cluster.yaml"
284289
assert cluster.app_wrapper_name == "unit-test-default-cluster"
285290
assert cluster.config.namespace == "opendatahub"
286291

@@ -290,7 +295,7 @@ def arg_check_apply_effect(group, version, namespace, plural, body, *args):
290295
assert version == "v1beta1"
291296
assert namespace == "ns"
292297
assert plural == "appwrappers"
293-
with open("unit-test-cluster.yaml") as f:
298+
with open(f"{aw_dir}unit-test-cluster.yaml") as f:
294299
aw = yaml.load(f, Loader=yaml.FullLoader)
295300
assert body == aw
296301
assert args == tuple()
@@ -2151,7 +2156,7 @@ def parse_j(cmd):
21512156

21522157

21532158
def test_AWManager_creation():
2154-
testaw = AWManager("test.yaml")
2159+
testaw = AWManager(f"{aw_dir}test.yaml")
21552160
assert testaw.name == "test"
21562161
assert testaw.namespace == "ns"
21572162
assert testaw.submitted == False
@@ -2175,7 +2180,7 @@ def arg_check_aw_apply_effect(group, version, namespace, plural, body, *args):
21752180
assert version == "v1beta1"
21762181
assert namespace == "ns"
21772182
assert plural == "appwrappers"
2178-
with open("test.yaml") as f:
2183+
with open(f"{aw_dir}test.yaml") as f:
21792184
aw = yaml.load(f, Loader=yaml.FullLoader)
21802185
assert body == aw
21812186
assert args == tuple()
@@ -2191,7 +2196,7 @@ def arg_check_aw_del_effect(group, version, namespace, plural, name, *args):
21912196

21922197

21932198
def test_AWManager_submit_remove(mocker, capsys):
2194-
testaw = AWManager("test.yaml")
2199+
testaw = AWManager(f"{aw_dir}test.yaml")
21952200
testaw.remove()
21962201
captured = capsys.readouterr()
21972202
assert (
@@ -2429,12 +2434,12 @@ def test_gen_app_wrapper_with_oauth(mocker: MockerFixture):
24292434

24302435
# Make sure to always keep this function last
24312436
def test_cleanup():
2432-
os.remove("unit-test-cluster.yaml")
2433-
os.remove("prio-test-cluster.yaml")
2434-
os.remove("unit-test-default-cluster.yaml")
2435-
os.remove("test.yaml")
2436-
os.remove("raytest2.yaml")
2437-
os.remove("quicktest.yaml")
2437+
os.remove(f"{aw_dir}unit-test-cluster.yaml")
2438+
os.remove(f"{aw_dir}prio-test-cluster.yaml")
2439+
os.remove(f"{aw_dir}unit-test-default-cluster.yaml")
2440+
os.remove(f"{aw_dir}test.yaml")
2441+
os.remove(f"{aw_dir}raytest2.yaml")
2442+
os.remove(f"{aw_dir}quicktest.yaml")
24382443
os.remove("tls-cluster-namespace/ca.crt")
24392444
os.remove("tls-cluster-namespace/tls.crt")
24402445
os.remove("tls-cluster-namespace/tls.key")

0 commit comments

Comments
 (0)
Please sign in to comment.