Skip to content

Commit 4595f36

Browse files
committed
Applied review feedback
1 parent 2241b6f commit 4595f36

File tree

2 files changed

+68
-55
lines changed

2 files changed

+68
-55
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -224,31 +224,7 @@ def up(self):
224224
body=aw,
225225
)
226226
else:
227-
with open(self.app_wrapper_yaml) as f:
228-
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
229-
for resource in yamls:
230-
if resource["kind"] == "RayCluster":
231-
api_instance.create_namespaced_custom_object(
232-
group="ray.io",
233-
version="v1alpha1",
234-
namespace=namespace,
235-
plural="rayclusters",
236-
body=resource,
237-
)
238-
elif resource["kind"] == "Route":
239-
api_instance.create_namespaced_custom_object(
240-
group="route.openshift.io",
241-
version="v1",
242-
namespace=namespace,
243-
plural="routes",
244-
body=resource,
245-
)
246-
elif resource["kind"] == "Secret":
247-
secret_instance = client.CoreV1Api(api_config_handler())
248-
secret_instance.create_namespaced_secret(
249-
namespace=namespace,
250-
body=resource,
251-
)
227+
self._component_level_up(namespace, api_instance)
252228
except Exception as e: # pragma: no cover
253229
return _kube_api_error_handling(e)
254230

@@ -270,33 +246,7 @@ def down(self):
270246
name=self.app_wrapper_name,
271247
)
272248
else:
273-
with open(self.app_wrapper_yaml) as f:
274-
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
275-
for resource in yamls:
276-
if resource["kind"] == "RayCluster":
277-
api_instance.delete_namespaced_custom_object(
278-
group="ray.io",
279-
version="v1alpha1",
280-
namespace=namespace,
281-
plural="rayclusters",
282-
name=self.app_wrapper_name,
283-
)
284-
elif resource["kind"] == "Route":
285-
name = resource["metadata"]["name"]
286-
api_instance.delete_namespaced_custom_object(
287-
group="route.openshift.io",
288-
version="v1",
289-
namespace=namespace,
290-
plural="routes",
291-
name=name,
292-
)
293-
elif resource["kind"] == "Secret":
294-
name = resource["metadata"]["name"]
295-
secret_instance = client.CoreV1Api(api_config_handler())
296-
secret_instance.delete_namespaced_secret(
297-
namespace=namespace,
298-
name=name,
299-
)
249+
self._component_level_down(namespace, api_instance)
300250
except Exception as e: # pragma: no cover
301251
return _kube_api_error_handling(e)
302252

@@ -350,7 +300,10 @@ def status(
350300

351301
# check the ray cluster status
352302
cluster = _ray_cluster_status(self.config.name, self.config.namespace)
353-
if cluster and not cluster.status == RayClusterStatus.UNKNOWN:
303+
if cluster:
304+
if cluster.status == RayClusterStatus.UNKNOWN:
305+
ready = False
306+
status = CodeFlareClusterStatus.STARTING
354307
if cluster.status == RayClusterStatus.READY:
355308
ready = True
356309
status = CodeFlareClusterStatus.READY
@@ -401,7 +354,7 @@ def wait_ready(self, timeout: Optional[int] = None, dashboard_check: bool = True
401354
time = 0
402355
while not ready:
403356
status, ready = self.status(print_to_console=False)
404-
if self.config.mcad and status == CodeFlareClusterStatus.UNKNOWN:
357+
if status == CodeFlareClusterStatus.UNKNOWN:
405358
print(
406359
"WARNING: Current cluster status is unknown, have you run cluster.up yet?"
407360
)
@@ -548,6 +501,66 @@ def local_client_url(self):
548501
else:
549502
return "None"
550503

504+
def _component_level_up(
505+
self, namespace: str, api_instance: client.CustomObjectsApi
506+
):
507+
with open(self.app_wrapper_yaml) as f:
508+
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
509+
for resource in yamls:
510+
if resource["kind"] == "RayCluster":
511+
api_instance.create_namespaced_custom_object(
512+
group="ray.io",
513+
version="v1alpha1",
514+
namespace=namespace,
515+
plural="rayclusters",
516+
body=resource,
517+
)
518+
elif resource["kind"] == "Route":
519+
api_instance.create_namespaced_custom_object(
520+
group="route.openshift.io",
521+
version="v1",
522+
namespace=namespace,
523+
plural="routes",
524+
body=resource,
525+
)
526+
elif resource["kind"] == "Secret":
527+
secret_instance = client.CoreV1Api(api_config_handler())
528+
secret_instance.create_namespaced_secret(
529+
namespace=namespace,
530+
body=resource,
531+
)
532+
533+
def _component_level_down(
534+
self, namespace: str, api_instance: client.CustomObjectsApi
535+
):
536+
with open(self.app_wrapper_yaml) as f:
537+
yamls = yaml.load_all(f, Loader=yaml.FullLoader)
538+
for resource in yamls:
539+
if resource["kind"] == "RayCluster":
540+
api_instance.delete_namespaced_custom_object(
541+
group="ray.io",
542+
version="v1alpha1",
543+
namespace=namespace,
544+
plural="rayclusters",
545+
name=self.app_wrapper_name,
546+
)
547+
elif resource["kind"] == "Route":
548+
name = resource["metadata"]["name"]
549+
api_instance.delete_namespaced_custom_object(
550+
group="route.openshift.io",
551+
version="v1",
552+
namespace=namespace,
553+
plural="routes",
554+
name=name,
555+
)
556+
elif resource["kind"] == "Secret":
557+
name = resource["metadata"]["name"]
558+
secret_instance = client.CoreV1Api(api_config_handler())
559+
secret_instance.delete_namespaced_secret(
560+
namespace=namespace,
561+
name=name,
562+
)
563+
551564

552565
def list_all_clusters(namespace: str, print_to_console: bool = True):
553566
"""

src/codeflare_sdk/utils/generate_yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def _create_oauth_sidecar_object(
457457
)
458458

459459

460-
def write_components(user_yaml, output_file_name):
460+
def write_components(user_yaml: dict, output_file_name: str):
461461
components = user_yaml.get("spec", "resources")["resources"].get("GenericItems")
462462
open(output_file_name, "w").close()
463463
with open(output_file_name, "a") as outfile:

0 commit comments

Comments
 (0)