Skip to content

Commit c212bd8

Browse files
add: abstraction to remove appwrapper yaml visibility from the NB console.
1 parent 53177f2 commit c212bd8

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

src/codeflare_sdk/cluster/cluster.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ def __init__(self, config: ClusterConfiguration):
7171
"""
7272
self.config = config
7373
self.app_wrapper_yaml = self.create_app_wrapper()
74-
self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
7574
self._job_submission_client = None
75+
self.app_wrapper_name = self.app_wrapper_yaml.replace(".yaml", "").split("/")[
76+
-1
77+
]
7678

7779
@property
7880
def _client_headers(self):

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
@@ -506,8 +507,14 @@ def disable_raycluster_tls(resources):
506507

507508

508509
def write_user_appwrapper(user_yaml, output_file_name):
510+
# Create the directory if it doesn't exist
511+
directory_path = os.path.dirname(output_file_name)
512+
if not os.path.exists(directory_path):
513+
os.makedirs(directory_path)
514+
509515
with open(output_file_name, "w") as outfile:
510516
yaml.dump(user_yaml, outfile, default_flow_style=False)
517+
511518
print(f"Written to: {output_file_name}")
512519

513520

@@ -675,7 +682,8 @@ def generate_appwrapper(
675682
if openshift_oauth:
676683
enable_openshift_oauth(user_yaml, cluster_name, namespace)
677684

678-
outfile = appwrapper_name + ".yaml"
685+
directory_path = os.path.expanduser("~/.codeflare/appwrapper/")
686+
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
679687
if not mcad:
680688
write_components(user_yaml, outfile)
681689
else:

tests/unit_test.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from codeflare_sdk.cluster import cluster
2525

2626
parent = Path(__file__).resolve().parents[1]
27+
aw_dir = os.path.expanduser("~/.codeflare/appwrapper/")
2728
sys.path.append(str(parent) + "/src")
2829

2930
from kubernetes import client, config
@@ -261,10 +262,12 @@ def test_config_creation():
261262

262263
def test_cluster_creation(mocker):
263264
cluster = createClusterWithConfig(mocker)
264-
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
265+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster.yaml"
265266
assert cluster.app_wrapper_name == "unit-test-cluster"
266267
assert filecmp.cmp(
267-
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
268+
f"{aw_dir}unit-test-cluster.yaml",
269+
f"{parent}/tests/test-case.yaml",
270+
shallow=True,
268271
)
269272

270273

@@ -290,10 +293,10 @@ def test_cluster_creation_no_mcad(mocker):
290293
config.name = "unit-test-cluster-ray"
291294
config.mcad = False
292295
cluster = Cluster(config)
293-
assert cluster.app_wrapper_yaml == "unit-test-cluster-ray.yaml"
296+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster-ray.yaml"
294297
assert cluster.app_wrapper_name == "unit-test-cluster-ray"
295298
assert filecmp.cmp(
296-
"unit-test-cluster-ray.yaml",
299+
f"{aw_dir}unit-test-cluster-ray.yaml",
297300
f"{parent}/tests/test-case-no-mcad.yamls",
298301
shallow=True,
299302
)
@@ -313,10 +316,12 @@ def test_cluster_creation_priority(mocker):
313316
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
314317
)
315318
cluster = Cluster(config)
316-
assert cluster.app_wrapper_yaml == "prio-test-cluster.yaml"
319+
assert cluster.app_wrapper_yaml == f"{aw_dir}prio-test-cluster.yaml"
317320
assert cluster.app_wrapper_name == "prio-test-cluster"
318321
assert filecmp.cmp(
319-
"prio-test-cluster.yaml", f"{parent}/tests/test-case-prio.yaml", shallow=True
322+
f"{aw_dir}prio-test-cluster.yaml",
323+
f"{parent}/tests/test-case-prio.yaml",
324+
shallow=True,
320325
)
321326

322327

@@ -335,7 +340,7 @@ def test_default_cluster_creation(mocker):
335340
)
336341
cluster = Cluster(default_config)
337342

338-
assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
343+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-default-cluster.yaml"
339344
assert cluster.app_wrapper_name == "unit-test-default-cluster"
340345
assert cluster.config.namespace == "opendatahub"
341346

@@ -365,21 +370,21 @@ def arg_check_apply_effect(group, version, namespace, plural, body, *args):
365370
if plural == "appwrappers":
366371
assert group == "workload.codeflare.dev"
367372
assert version == "v1beta1"
368-
with open("unit-test-cluster.yaml") as f:
373+
with open(f"{aw_dir}unit-test-cluster.yaml") as f:
369374
aw = yaml.load(f, Loader=yaml.FullLoader)
370375
assert body == aw
371376
elif plural == "rayclusters":
372377
assert group == "ray.io"
373378
assert version == "v1alpha1"
374-
with open("unit-test-cluster-ray.yaml") as f:
379+
with open(f"{aw_dir}unit-test-cluster-ray.yaml") as f:
375380
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
376381
for resource in yamls:
377382
if resource["kind"] == "RayCluster":
378383
assert body == resource
379384
elif plural == "routes":
380385
assert group == "route.openshift.io"
381386
assert version == "v1"
382-
with open("unit-test-cluster-ray.yaml") as f:
387+
with open(f"{aw_dir}unit-test-cluster-ray.yaml") as f:
383388
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
384389
for resource in yamls:
385390
if resource["kind"] == "Route":
@@ -2408,7 +2413,7 @@ def parse_j(cmd):
24082413

24092414

24102415
def test_AWManager_creation():
2411-
testaw = AWManager("test.yaml")
2416+
testaw = AWManager(f"{aw_dir}test.yaml")
24122417
assert testaw.name == "test"
24132418
assert testaw.namespace == "ns"
24142419
assert testaw.submitted == False
@@ -2432,7 +2437,7 @@ def arg_check_aw_apply_effect(group, version, namespace, plural, body, *args):
24322437
assert version == "v1beta1"
24332438
assert namespace == "ns"
24342439
assert plural == "appwrappers"
2435-
with open("test.yaml") as f:
2440+
with open(f"{aw_dir}test.yaml") as f:
24362441
aw = yaml.load(f, Loader=yaml.FullLoader)
24372442
assert body == aw
24382443
assert args == tuple()
@@ -2448,7 +2453,7 @@ def arg_check_aw_del_effect(group, version, namespace, plural, name, *args):
24482453

24492454

24502455
def test_AWManager_submit_remove(mocker, capsys):
2451-
testaw = AWManager("test.yaml")
2456+
testaw = AWManager(f"{aw_dir}test.yaml")
24522457
testaw.remove()
24532458
captured = capsys.readouterr()
24542459
assert (
@@ -2876,13 +2881,12 @@ def test_gen_app_wrapper_with_oauth(mocker: MockerFixture):
28762881

28772882
# Make sure to always keep this function last
28782883
def test_cleanup():
2879-
os.remove("unit-test-cluster.yaml")
2880-
os.remove("prio-test-cluster.yaml")
2881-
os.remove("unit-test-default-cluster.yaml")
2882-
os.remove("unit-test-cluster-ray.yaml")
2883-
os.remove("test.yaml")
2884-
os.remove("raytest2.yaml")
2885-
os.remove("quicktest.yaml")
2884+
os.remove(f"{aw_dir}unit-test-cluster.yaml")
2885+
os.remove(f"{aw_dir}prio-test-cluster.yaml")
2886+
os.remove(f"{aw_dir}unit-test-default-cluster.yaml")
2887+
os.remove(f"{aw_dir}test.yaml")
2888+
os.remove(f"{aw_dir}raytest2.yaml")
2889+
os.remove(f"{aw_dir}quicktest.yaml")
28862890
os.remove("tls-cluster-namespace/ca.crt")
28872891
os.remove("tls-cluster-namespace/tls.crt")
28882892
os.remove("tls-cluster-namespace/tls.key")

0 commit comments

Comments
 (0)