Skip to content

Commit 7e287f5

Browse files
committed
refactor: make _get_all_rayclusters which handles namespaced and all raycluster listing
1 parent 883066e commit 7e287f5

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

src/codeflare_sdk/cluster/cluster.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def list_all_clusters(namespace: str, print_to_console: bool = True):
412412
"""
413413
Returns (and prints by default) a list of all clusters in a given namespace.
414414
"""
415-
clusters = _get_ray_clusters_in_namespace(namespace)
415+
clusters = _get_all_ray_clusters(namespace)
416416
if print_to_console:
417417
pretty_print.print_clusters(clusters)
418418
return clusters
@@ -539,17 +539,24 @@ def _ray_cluster_status(name, namespace="default") -> Optional[RayCluster]:
539539
return None
540540

541541

542-
def _get_ray_clusters_in_namespace(namespace="default") -> List[RayCluster]:
542+
def _get_all_ray_clusters(namespace: str = None) -> List[RayCluster]:
543543
list_of_clusters = []
544544
try:
545545
config_check()
546546
api_instance = client.CustomObjectsApi(api_config_handler())
547-
rcs = api_instance.list_namespaced_custom_object(
548-
group="ray.io",
549-
version="v1alpha1",
550-
namespace=namespace,
551-
plural="rayclusters",
552-
)
547+
if namespace:
548+
rcs = api_instance.list_namespaced_custom_object(
549+
group="ray.io",
550+
version="v1alpha1",
551+
namespace=namespace,
552+
plural="rayclusters",
553+
)
554+
else:
555+
rcs = api_instance.list_cluster_custom_object(
556+
group="ray.io",
557+
version="v1alpha1",
558+
plural="rayclusters",
559+
)
553560
except Exception as e: # pragma: no cover
554561
return _kube_api_error_handling(e)
555562

@@ -558,23 +565,6 @@ def _get_ray_clusters_in_namespace(namespace="default") -> List[RayCluster]:
558565
return list_of_clusters
559566

560567

561-
def _get_all_ray_clusters() -> List[RayCluster]:
562-
list_of_clusters = []
563-
try:
564-
config_check()
565-
api_instance = client.CustomObjectsApi(api_config_handler())
566-
rcs = api_instance.list_cluster_custom_object(
567-
group="ray.io",
568-
version="v1alpha1",
569-
plural="rayclusters",
570-
)
571-
except Exception as e:
572-
return _kube_api_error_handling(e)
573-
for rc in rcs["items"]:
574-
list_of_clusters.append(_map_to_ray_cluster(rc))
575-
return list_of_clusters
576-
577-
578568
def _get_app_wrappers(
579569
namespace="default", filter=List[AppWrapperStatus]
580570
) -> List[AppWrapper]:

0 commit comments

Comments
 (0)