Skip to content

add: abstraction to remove appwrapper visiblilty from NB console. #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
@@ -71,8 +71,10 @@ def __init__(self, config: ClusterConfiguration):
"""
self.config = config
self.app_wrapper_yaml = self.create_app_wrapper()
self.app_wrapper_name = self.app_wrapper_yaml.split(".")[0]
self._job_submission_client = None
self.app_wrapper_name = self.app_wrapper_yaml.replace(".yaml", "").split("/")[
-1
]

@property
def _client_headers(self):
10 changes: 9 additions & 1 deletion src/codeflare_sdk/utils/generate_yaml.py
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@

import yaml
import sys
import os
import argparse
import uuid
from kubernetes import client, config
@@ -506,8 +507,14 @@ def disable_raycluster_tls(resources):


def write_user_appwrapper(user_yaml, output_file_name):
# Create the directory if it doesn't exist
directory_path = os.path.dirname(output_file_name)
if not os.path.exists(directory_path):
os.makedirs(directory_path)

with open(output_file_name, "w") as outfile:
yaml.dump(user_yaml, outfile, default_flow_style=False)

print(f"Written to: {output_file_name}")


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

outfile = appwrapper_name + ".yaml"
directory_path = os.path.expanduser("~/.codeflare/appwrapper/")
outfile = os.path.join(directory_path, appwrapper_name + ".yaml")
if not mcad:
write_components(user_yaml, outfile)
else:
44 changes: 24 additions & 20 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@
import uuid

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

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

def test_cluster_creation(mocker):
cluster = createClusterWithConfig(mocker)
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster.yaml"
assert cluster.app_wrapper_name == "unit-test-cluster"
assert filecmp.cmp(
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
f"{aw_dir}unit-test-cluster.yaml",
f"{parent}/tests/test-case.yaml",
shallow=True,
)


@@ -270,10 +273,10 @@ def test_cluster_creation_no_mcad(mocker):
config.name = "unit-test-cluster-ray"
config.mcad = False
cluster = Cluster(config)
assert cluster.app_wrapper_yaml == "unit-test-cluster-ray.yaml"
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-cluster-ray.yaml"
assert cluster.app_wrapper_name == "unit-test-cluster-ray"
assert filecmp.cmp(
"unit-test-cluster-ray.yaml",
f"{aw_dir}unit-test-cluster-ray.yaml",
f"{parent}/tests/test-case-no-mcad.yamls",
shallow=True,
)
@@ -293,10 +296,12 @@ def test_cluster_creation_priority(mocker):
return_value={"spec": {"domain": "apps.cluster.awsroute.org"}},
)
cluster = Cluster(config)
assert cluster.app_wrapper_yaml == "prio-test-cluster.yaml"
assert cluster.app_wrapper_yaml == f"{aw_dir}prio-test-cluster.yaml"
assert cluster.app_wrapper_name == "prio-test-cluster"
assert filecmp.cmp(
"prio-test-cluster.yaml", f"{parent}/tests/test-case-prio.yaml", shallow=True
f"{aw_dir}prio-test-cluster.yaml",
f"{parent}/tests/test-case-prio.yaml",
shallow=True,
)


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

assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
assert cluster.app_wrapper_yaml == f"{aw_dir}unit-test-default-cluster.yaml"
assert cluster.app_wrapper_name == "unit-test-default-cluster"
assert cluster.config.namespace == "opendatahub"

@@ -344,21 +349,21 @@ def arg_check_apply_effect(group, version, namespace, plural, body, *args):
if plural == "appwrappers":
assert group == "workload.codeflare.dev"
assert version == "v1beta1"
with open("unit-test-cluster.yaml") as f:
with open(f"{aw_dir}unit-test-cluster.yaml") as f:
aw = yaml.load(f, Loader=yaml.FullLoader)
assert body == aw
elif plural == "rayclusters":
assert group == "ray.io"
assert version == "v1alpha1"
with open("unit-test-cluster-ray.yaml") as f:
with open(f"{aw_dir}unit-test-cluster-ray.yaml") as f:
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
for resource in yamls:
if resource["kind"] == "RayCluster":
assert body == resource
elif plural == "routes":
assert group == "route.openshift.io"
assert version == "v1"
with open("unit-test-cluster-ray.yaml") as f:
with open(f"{aw_dir}unit-test-cluster-ray.yaml") as f:
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
for resource in yamls:
if resource["kind"] == "Route":
@@ -2368,7 +2373,7 @@ def parse_j(cmd):


def test_AWManager_creation():
testaw = AWManager("test.yaml")
testaw = AWManager(f"{aw_dir}test.yaml")
assert testaw.name == "test"
assert testaw.namespace == "ns"
assert testaw.submitted == False
@@ -2392,7 +2397,7 @@ def arg_check_aw_apply_effect(group, version, namespace, plural, body, *args):
assert version == "v1beta1"
assert namespace == "ns"
assert plural == "appwrappers"
with open("test.yaml") as f:
with open(f"{aw_dir}test.yaml") as f:
aw = yaml.load(f, Loader=yaml.FullLoader)
assert body == aw
assert args == tuple()
@@ -2408,7 +2413,7 @@ def arg_check_aw_del_effect(group, version, namespace, plural, name, *args):


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

# Make sure to always keep this function last
def test_cleanup():
os.remove("unit-test-cluster.yaml")
os.remove("prio-test-cluster.yaml")
os.remove("unit-test-default-cluster.yaml")
os.remove("unit-test-cluster-ray.yaml")
os.remove("test.yaml")
os.remove("raytest2.yaml")
os.remove("quicktest.yaml")
os.remove(f"{aw_dir}unit-test-cluster.yaml")
os.remove(f"{aw_dir}prio-test-cluster.yaml")
os.remove(f"{aw_dir}unit-test-default-cluster.yaml")
os.remove(f"{aw_dir}test.yaml")
os.remove(f"{aw_dir}raytest2.yaml")
os.remove(f"{aw_dir}quicktest.yaml")
os.remove("tls-cluster-namespace/ca.crt")
os.remove("tls-cluster-namespace/tls.crt")
os.remove("tls-cluster-namespace/tls.key")