Skip to content

Commit 805f0cf

Browse files
committed
Applied review feedback
1 parent 946fabc commit 805f0cf

File tree

2 files changed

+68
-55
lines changed

2 files changed

+68
-55
lines changed

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

+67-54
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,7 @@ def up(self):
176176
body=aw,
177177
)
178178
else:
179-
with open(self.app_wrapper_yaml) as f:
180-
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
181-
for resource in yamls:
182-
if resource["kind"] == "RayCluster":
183-
api_instance.create_namespaced_custom_object(
184-
group="ray.io",
185-
version="v1alpha1",
186-
namespace=namespace,
187-
plural="rayclusters",
188-
body=resource,
189-
)
190-
elif resource["kind"] == "Route":
191-
api_instance.create_namespaced_custom_object(
192-
group="route.openshift.io",
193-
version="v1",
194-
namespace=namespace,
195-
plural="routes",
196-
body=resource,
197-
)
198-
elif resource["kind"] == "Secret":
199-
secret_instance = client.CoreV1Api(api_config_handler())
200-
secret_instance.create_namespaced_secret(
201-
namespace=namespace,
202-
body=resource,
203-
)
179+
self._component_level_up(namespace, api_instance)
204180
except Exception as e: # pragma: no cover
205181
return _kube_api_error_handling(e)
206182

@@ -222,33 +198,7 @@ def down(self):
222198
name=self.app_wrapper_name,
223199
)
224200
else:
225-
with open(self.app_wrapper_yaml) as f:
226-
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
227-
for resource in yamls:
228-
if resource["kind"] == "RayCluster":
229-
api_instance.delete_namespaced_custom_object(
230-
group="ray.io",
231-
version="v1alpha1",
232-
namespace=namespace,
233-
plural="rayclusters",
234-
name=self.app_wrapper_name,
235-
)
236-
elif resource["kind"] == "Route":
237-
name = resource["metadata"]["name"]
238-
api_instance.delete_namespaced_custom_object(
239-
group="route.openshift.io",
240-
version="v1",
241-
namespace=namespace,
242-
plural="routes",
243-
name=name,
244-
)
245-
elif resource["kind"] == "Secret":
246-
name = resource["metadata"]["name"]
247-
secret_instance = client.CoreV1Api(api_config_handler())
248-
secret_instance.delete_namespaced_secret(
249-
namespace=namespace,
250-
name=name,
251-
)
201+
self._component_level_down(namespace, api_instance)
252202
except Exception as e: # pragma: no cover
253203
return _kube_api_error_handling(e)
254204

@@ -297,7 +247,10 @@ def status(
297247

298248
# check the ray cluster status
299249
cluster = _ray_cluster_status(self.config.name, self.config.namespace)
300-
if cluster and not cluster.status == RayClusterStatus.UNKNOWN:
250+
if cluster:
251+
if cluster.status == RayClusterStatus.UNKNOWN:
252+
ready = False
253+
status = CodeFlareClusterStatus.STARTING
301254
if cluster.status == RayClusterStatus.READY:
302255
ready = True
303256
status = CodeFlareClusterStatus.READY
@@ -339,7 +292,7 @@ def wait_ready(self, timeout: Optional[int] = None, dashboard_check: bool = True
339292
time = 0
340293
while not ready:
341294
status, ready = self.status(print_to_console=False)
342-
if self.config.mcad and status == CodeFlareClusterStatus.UNKNOWN:
295+
if status == CodeFlareClusterStatus.UNKNOWN:
343296
print(
344297
"WARNING: Current cluster status is unknown, have you run cluster.up yet?"
345298
)
@@ -486,6 +439,66 @@ def local_client_url(self):
486439
else:
487440
return "None"
488441

442+
def _component_level_up(
443+
self, namespace: str, api_instance: client.CustomObjectsApi
444+
):
445+
with open(self.app_wrapper_yaml) as f:
446+
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
447+
for resource in yamls:
448+
if resource["kind"] == "RayCluster":
449+
api_instance.create_namespaced_custom_object(
450+
group="ray.io",
451+
version="v1alpha1",
452+
namespace=namespace,
453+
plural="rayclusters",
454+
body=resource,
455+
)
456+
elif resource["kind"] == "Route":
457+
api_instance.create_namespaced_custom_object(
458+
group="route.openshift.io",
459+
version="v1",
460+
namespace=namespace,
461+
plural="routes",
462+
body=resource,
463+
)
464+
elif resource["kind"] == "Secret":
465+
secret_instance = client.CoreV1Api(api_config_handler())
466+
secret_instance.create_namespaced_secret(
467+
namespace=namespace,
468+
body=resource,
469+
)
470+
471+
def _component_level_down(
472+
self, namespace: str, api_instance: client.CustomObjectsApi
473+
):
474+
with open(self.app_wrapper_yaml) as f:
475+
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
476+
for resource in yamls:
477+
if resource["kind"] == "RayCluster":
478+
api_instance.delete_namespaced_custom_object(
479+
group="ray.io",
480+
version="v1alpha1",
481+
namespace=namespace,
482+
plural="rayclusters",
483+
name=self.app_wrapper_name,
484+
)
485+
elif resource["kind"] == "Route":
486+
name = resource["metadata"]["name"]
487+
api_instance.delete_namespaced_custom_object(
488+
group="route.openshift.io",
489+
version="v1",
490+
namespace=namespace,
491+
plural="routes",
492+
name=name,
493+
)
494+
elif resource["kind"] == "Secret":
495+
name = resource["metadata"]["name"]
496+
secret_instance = client.CoreV1Api(api_config_handler())
497+
secret_instance.delete_namespaced_secret(
498+
namespace=namespace,
499+
name=name,
500+
)
501+
489502

490503
def list_all_clusters(namespace: str, print_to_console: bool = True):
491504
"""

Diff for: src/codeflare_sdk/utils/generate_yaml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ def write_user_appwrapper(user_yaml, output_file_name):
369369
print(f"Written to: {output_file_name}")
370370

371371

372-
def write_components(user_yaml, output_file_name):
372+
def write_components(user_yaml: dict, output_file_name: str):
373373
components = user_yaml.get("spec", "resources")["resources"].get("GenericItems")
374374
open(output_file_name, "w").close()
375375
with open(output_file_name, "a") as outfile:

0 commit comments

Comments
 (0)