Skip to content

Remove appwrapper yaml #366

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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.app_wrapper_name = self.config.name

def evaluate_dispatch_priority(self):
priority_class = self.config.dispatch_priority
Expand Down Expand Up @@ -147,6 +147,7 @@ def create_app_wrapper(self):
image_pull_secrets=image_pull_secrets,
dispatch_priority=dispatch_priority,
priority_val=priority_val,
write_to_file=self.config.write_to_file,
)

# creates a new cluster with the provided or default spec
Expand All @@ -159,8 +160,8 @@ def up(self):
try:
config_check()
api_instance = client.CustomObjectsApi(api_config_handler())
with open(self.app_wrapper_yaml) as f:
aw = yaml.load(f, Loader=yaml.FullLoader)

aw = self.app_wrapper_yaml
api_instance.create_namespaced_custom_object(
group="workload.codeflare.dev",
version="v1beta1",
Expand Down
1 change: 1 addition & 0 deletions src/codeflare_sdk/cluster/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ class ClusterConfiguration:
local_interactive: bool = False
image_pull_secrets: list = field(default_factory=list)
dispatch_priority: str = None
write_to_file: bool = False
10 changes: 7 additions & 3 deletions src/codeflare_sdk/utils/generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ def generate_appwrapper(
image_pull_secrets: list,
dispatch_priority: str,
priority_val: int,
write_to_file: bool,
):
user_yaml = read_template(template)
appwrapper_name, cluster_name = gen_names(name)
Expand Down Expand Up @@ -433,6 +434,9 @@ def generate_appwrapper(
enable_local_interactive(resources, cluster_name, namespace)
else:
disable_raycluster_tls(resources["resources"])
outfile = appwrapper_name + ".yaml"
write_user_appwrapper(user_yaml, outfile)
return outfile

if write_to_file:
outfile = appwrapper_name + ".yaml"
write_user_appwrapper(user_yaml, outfile)

return user_yaml
17 changes: 14 additions & 3 deletions tests/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,15 @@ def test_config_creation():
assert config.machine_types == ["cpu.small", "gpu.large"]
assert config.image_pull_secrets == ["unit-test-pull-secret"]
assert config.dispatch_priority == None
assert config.write_to_file == True


def test_cluster_creation():
cluster = createClusterWithConfig()
assert cluster.app_wrapper_yaml == "unit-test-cluster.yaml"
# load yaml file and compare with in memory yaml
with open("unit-test-cluster.yaml") as f:
aw = yaml.load(f, Loader=yaml.FullLoader)
assert aw == cluster.app_wrapper_yaml
assert cluster.app_wrapper_name == "unit-test-cluster"
assert filecmp.cmp(
"unit-test-cluster.yaml", f"{parent}/tests/test-case.yaml", shallow=True
Expand All @@ -258,7 +262,10 @@ def test_cluster_creation_priority(mocker):
config.name = "prio-test-cluster"
config.dispatch_priority = "default"
cluster = Cluster(config)
assert cluster.app_wrapper_yaml == "prio-test-cluster.yaml"
# load yaml file and compare with in memory yaml
with open("prio-test-cluster.yaml") as f:
aw = yaml.load(f, Loader=yaml.FullLoader)
assert aw == cluster.app_wrapper_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
Expand All @@ -272,10 +279,14 @@ def test_default_cluster_creation(mocker):
)
default_config = ClusterConfiguration(
name="unit-test-default-cluster",
write_to_file=True,
)
cluster = Cluster(default_config)

assert cluster.app_wrapper_yaml == "unit-test-default-cluster.yaml"
# open yaml file and compare with in memory yaml
with open("unit-test-default-cluster.yaml") as f:
aw = yaml.load(f, Loader=yaml.FullLoader)
assert aw == cluster.app_wrapper_yaml
assert cluster.app_wrapper_name == "unit-test-default-cluster"
assert cluster.config.namespace == "opendatahub"

Expand Down
1 change: 1 addition & 0 deletions tests/unit_test_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def createClusterConfig():
instascale=True,
machine_types=["cpu.small", "gpu.large"],
image_pull_secrets=["unit-test-pull-secret"],
write_to_file=True,
)
return config

Expand Down