Skip to content

Commit 352c26c

Browse files
committed
Refactoring apply
1 parent a6b6fb1 commit 352c26c

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

Diff for: src/codeflare_sdk/ray/cluster/cluster.py

+16-23
Original file line numberDiff line numberDiff line change
@@ -194,40 +194,33 @@ def apply(self, force=False):
194194
# check if RayCluster CustomResourceDefinition exists if not throw RuntimeError
195195
self._throw_for_no_raycluster()
196196
namespace = self.config.namespace
197-
197+
name = self.config.name
198198
try:
199199
self.config_check()
200200
api_instance = client.CustomObjectsApi(get_api_client())
201201
crds = self.get_dynamic_client().resources
202-
api_instance = crds.get(
203-
api_version="workload.codeflare.dev/v1beta2", kind="AppWrapper"
204-
)
205202
if self.config.appwrapper:
203+
api_version = "workload.codeflare.dev/v1beta2"
204+
api_instance = crds.get(api_version, kind="AppWrapper")
205+
# defaulting body to resource_yaml
206+
body = self.resource_yaml
206207
if self.config.write_to_file:
208+
# if write_to_file is True, load the file from AppWrapper yaml and update body
207209
with open(self.resource_yaml) as f:
208210
aw = yaml.load(f, Loader=yaml.FullLoader)
209-
api_instance.server_side_apply(
210-
group="workload.codeflare.dev",
211-
version="v1beta2",
212-
namespace=namespace,
213-
plural="appwrappers",
214-
body=aw,
215-
)
216-
else:
217-
api_instance.server_side_apply(
218-
group="workload.codeflare.dev",
219-
version="v1beta2",
220-
namespace=namespace,
221-
plural="appwrappers",
222-
body=self.resource_yaml,
223-
)
224-
print(f"AppWrapper: '{self.config.name}' has successfully been created")
211+
body = aw
212+
api_instance.server_side_apply(
213+
group="workload.codeflare.dev",
214+
version="v1beta2",
215+
namespace=namespace,
216+
plural="appwrappers",
217+
body=body,
218+
)
219+
print(f"AppWrapper: '{name}' has successfully been created")
225220
else:
226221
api_instance = crds.get(api_version="ray.io/v1", kind="RayCluster")
227222
self._component_resources_apply(namespace, api_instance)
228-
print(
229-
f"Ray Cluster: '{self.config.name}' has successfully been applied"
230-
)
223+
print(f"Ray Cluster: '{name}' has successfully been applied")
231224
except Exception as e: # pragma: no cover
232225
return _kube_api_error_handling(e)
233226

0 commit comments

Comments
 (0)