Skip to content

Commit 2f91786

Browse files
committed
add: abstraction to remove appwrapper yaml visibility from the NB console.
1 parent 3f856a7 commit 2f91786

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

Diff for: 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):

Diff for: 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:

Diff for: tests/unit_test.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import uuid
2323

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

2728
from kubernetes import client, config
@@ -254,10 +255,12 @@ def test_config_creation():
254255

255256
def test_cluster_creation(mocker):
256257
cluster = createClusterWithConfig(mocker)
257-
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
258+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster.yaml"
258259
assert cluster.app_wrapper_name == "unit-test-cluster"
259260
assert filecmp.cmp(
260-
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
261+
f"{aw_dir}unit-test-cluster.yaml",
262+
f"{parent}/tests/test-case.yaml",
263+
shallow=True,
261264
)
262265

263266

@@ -270,10 +273,10 @@ def test_cluster_creation_no_mcad(mocker):
270273
config.name = "unit-test-cluster-ray"
271274
config.mcad = False
272275
cluster = Cluster(config)
273-
assert cluster.app_wrapper_yaml == "unit-test-cluster-ray.yaml"
276+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster-ray.yaml"
274277
assert cluster.app_wrapper_name == "unit-test-cluster-ray"
275278
assert filecmp.cmp(
276-
"unit-test-cluster-ray.yaml",
279+
f"{aw_dir}unit-test-cluster-ray.yaml",
277280
f"{parent}/tests/test-case-no-mcad.yamls",
278281
shallow=True,
279282
)
@@ -293,10 +296,12 @@ def test_cluster_creation_priority(mocker):
293296
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
294297
)
295298
cluster = Cluster(config)
296-
assert cluster.app_wrapper_yaml == "prio-test-cluster.yaml"
299+
assert cluster.app_wrapper_yaml == f"{aw_dir}prio-test-cluster.yaml"
297300
assert cluster.app_wrapper_name == "prio-test-cluster"
298301
assert filecmp.cmp(
299-
"prio-test-cluster.yaml", f"{parent}/tests/test-case-prio.yaml", shallow=True
302+
f"{aw_dir}prio-test-cluster.yaml",
303+
f"{parent}/tests/test-case-prio.yaml",
304+
shallow=True,
300305
)
301306

302307

@@ -314,7 +319,7 @@ def test_default_cluster_creation(mocker):
314319
)
315320
cluster = Cluster(default_config)
316321

317-
assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
322+
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-default-cluster.yaml"
318323
assert cluster.app_wrapper_name == "unit-test-default-cluster"
319324
assert cluster.config.namespace == "opendatahub"
320325

@@ -344,21 +349,21 @@ def arg_check_apply_effect(group, version, namespace, plural, body, *args):
344349
if plural == "appwrappers":
345350
assert group == "workload.codeflare.dev"
346351
assert version == "v1beta1"
347-
with open("unit-test-cluster.yaml") as f:
352+
with open(f"{aw_dir}unit-test-cluster.yaml") as f:
348353
aw = yaml.load(f, Loader=yaml.FullLoader)
349354
assert body == aw
350355
elif plural == "rayclusters":
351356
assert group == "ray.io"
352357
assert version == "v1alpha1"
353-
with open("unit-test-cluster-ray.yaml") as f:
358+
with open(f"{aw_dir}unit-test-cluster-ray.yaml") as f:
354359
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
355360
for resource in yamls:
356361
if resource["kind"] == "RayCluster":
357362
assert body == resource
358363
elif plural == "routes":
359364
assert group == "route.openshift.io"
360365
assert version == "v1"
361-
with open("unit-test-cluster-ray.yaml") as f:
366+
with open(f"{aw_dir}unit-test-cluster-ray.yaml") as f:
362367
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
363368
for resource in yamls:
364369
if resource["kind"] == "Route":
@@ -2368,7 +2373,7 @@ def parse_j(cmd):
23682373

23692374

23702375
def test_AWManager_creation():
2371-
testaw = AWManager("test.yaml")
2376+
testaw = AWManager(f"{aw_dir}test.yaml")
23722377
assert testaw.name == "test"
23732378
assert testaw.namespace == "ns"
23742379
assert testaw.submitted == False
@@ -2392,7 +2397,7 @@ def arg_check_aw_apply_effect(group, version, namespace, plural, body, *args):
23922397
assert version == "v1beta1"
23932398
assert namespace == "ns"
23942399
assert plural == "appwrappers"
2395-
with open("test.yaml") as f:
2400+
with open(f"{aw_dir}test.yaml") as f:
23962401
aw = yaml.load(f, Loader=yaml.FullLoader)
23972402
assert body == aw
23982403
assert args == tuple()
@@ -2408,7 +2413,7 @@ def arg_check_aw_del_effect(group, version, namespace, plural, name, *args):
24082413

24092414

24102415
def test_AWManager_submit_remove(mocker, capsys):
2411-
testaw = AWManager("test.yaml")
2416+
testaw = AWManager(f"{aw_dir}test.yaml")
24122417
testaw.remove()
24132418
captured = capsys.readouterr()
24142419
assert (
@@ -2665,13 +2670,12 @@ def test_gen_app_wrapper_with_oauth(mocker: MockerFixture):
26652670

26662671
# Make sure to always keep this function last
26672672
def test_cleanup():
2668-
os.remove("unit-test-cluster.yaml")
2669-
os.remove("prio-test-cluster.yaml")
2670-
os.remove("unit-test-default-cluster.yaml")
2671-
os.remove("unit-test-cluster-ray.yaml")
2672-
os.remove("test.yaml")
2673-
os.remove("raytest2.yaml")
2674-
os.remove("quicktest.yaml")
2673+
os.remove(f"{aw_dir}unit-test-cluster.yaml")
2674+
os.remove(f"{aw_dir}prio-test-cluster.yaml")
2675+
os.remove(f"{aw_dir}unit-test-default-cluster.yaml")
2676+
os.remove(f"{aw_dir}test.yaml")
2677+
os.remove(f"{aw_dir}raytest2.yaml")
2678+
os.remove(f"{aw_dir}quicktest.yaml")
26752679
os.remove("tls-cluster-namespace/ca.crt")
26762680
os.remove("tls-cluster-namespace/tls.crt")
26772681
os.remove("tls-cluster-namespace/tls.key")

0 commit comments

Comments
 (0)