Skip to content

Commit

Permalink
Added multi-resource YAML support
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxusmusti committed Sep 26, 2023
1 parent 29cd61e commit dc540c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
RayCluster,
RayClusterStatus,
)
from kubernetes import client, config
from kubernetes import client, config, utils
import yaml
import os
import requests
Expand Down Expand Up @@ -165,15 +165,28 @@ 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)
api_instance.create_namespaced_custom_object(
group="workload.codeflare.dev",
version="v1beta1",
namespace=namespace,
plural="appwrappers",
body=aw,
)
if self.config.mcad:
with open(self.app_wrapper_yaml) as f:
aw = yaml.load(f, Loader=yaml.FullLoader)
api_instance.create_namespaced_custom_object(
group="workload.codeflare.dev",
version="v1beta1",
namespace=namespace,
plural="appwrappers",
body=aw,
)
else:
with open(self.app_wrapper_yaml) as f:
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
for resource in yamls:
print(resource["kind"])
# api_instance.create_namespaced_custom_object(
# group="ray.io",
# version="v1alpha1",
# namespace=namespace,
# plural="rayclusters",
# body=aw,
# )
except Exception as e: # pragma: no cover
return _kube_api_error_handling(e)

Expand Down
1 change: 1 addition & 0 deletions src/codeflare_sdk/utils/generate_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ def write_components(user_yaml, output_file_name):
with open(output_file_name, "a") as outfile:
for component in components:
if "generictemplate" in component:
outfile.write("---\n")
yaml.dump(
component["generictemplate"], outfile, default_flow_style=False
)
Expand Down

0 comments on commit dc540c1

Please sign in to comment.