-
Notifications
You must be signed in to change notification settings - Fork 54
Status, Details, and List rayclusters CLI Functions #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ad1abfa
c3ff10c
568bde6
d4d11c6
d5fb325
171392e
e3619de
71b70c0
4d76f96
a2168b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import click | ||
|
||
from codeflare_sdk.cluster.cluster import get_cluster | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""Get the details of a specified resource""" | ||
pass | ||
|
||
|
||
@cli.command() | ||
@click.argument("name", type=str) | ||
@click.option("--namespace", type=str, required=True) | ||
@click.pass_context | ||
def raycluster(ctx, name, namespace): | ||
"""Get the details of a specified RayCluster""" | ||
try: | ||
cluster = get_cluster(name, namespace) | ||
except FileNotFoundError: | ||
click.echo(f"Cluster {name} not found in {namespace} namespace") | ||
return | ||
cluster.details() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import click | ||
from kubernetes import client, config | ||
|
||
from codeflare_sdk.cluster.cluster import ( | ||
list_clusters_all_namespaces, | ||
list_all_clusters, | ||
get_current_namespace, | ||
) | ||
from codeflare_sdk.cli.cli_utils import load_auth | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""List a specified resource""" | ||
pass | ||
|
||
|
||
@cli.command() | ||
@click.option("--namespace", type=str) | ||
@click.option("--all", is_flag=True) | ||
@click.pass_context | ||
def rayclusters(ctx, namespace, all): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll create an alias so the user can do either |
||
"""List all rayclusters in a specified namespace""" | ||
if all and namespace: | ||
click.echo("--all and --namespace are mutually exclusive") | ||
return | ||
if not all and not namespace: | ||
click.echo("You must specify either --namespace or --all") | ||
return | ||
if not all: | ||
list_all_clusters(namespace) | ||
return | ||
list_clusters_all_namespaces() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import click | ||
|
||
from codeflare_sdk.cluster.cluster import get_cluster | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""Get the status of a specified resource""" | ||
pass | ||
|
||
|
||
@cli.command() | ||
@click.argument("name", type=str) | ||
@click.option("--namespace", type=str, required=True) | ||
@click.pass_context | ||
def raycluster(ctx, name, namespace): | ||
"""Get the status of a specified RayCluster""" | ||
try: | ||
cluster = get_cluster(name, namespace) | ||
except FileNotFoundError: | ||
click.echo(f"Cluster {name} not found in {namespace} namespace") | ||
return | ||
cluster.status() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -412,7 +412,17 @@ def list_all_clusters(namespace: str, print_to_console: bool = True): | |
""" | ||
Returns (and prints by default) a list of all clusters in a given namespace. | ||
""" | ||
clusters = _get_ray_clusters(namespace) | ||
clusters = _get_ray_clusters_in_namespace(namespace) | ||
if print_to_console: | ||
pretty_print.print_clusters(clusters) | ||
return clusters | ||
|
||
|
||
def list_clusters_all_namespaces(print_to_console: bool = True): | ||
""" | ||
Returns (and prints by default) a list of all clusters in the Kubernetes cluster. | ||
""" | ||
clusters = _get_all_ray_clusters() | ||
if print_to_console: | ||
pretty_print.print_clusters(clusters) | ||
return clusters | ||
|
@@ -529,7 +539,7 @@ def _ray_cluster_status(name, namespace="default") -> Optional[RayCluster]: | |
return None | ||
|
||
|
||
def _get_ray_clusters(namespace="default") -> List[RayCluster]: | ||
def _get_ray_clusters_in_namespace(namespace="default") -> List[RayCluster]: | ||
list_of_clusters = [] | ||
try: | ||
config_check() | ||
|
@@ -548,6 +558,23 @@ def _get_ray_clusters(namespace="default") -> List[RayCluster]: | |
return list_of_clusters | ||
|
||
|
||
def _get_all_ray_clusters() -> List[RayCluster]: | ||
list_of_clusters = [] | ||
try: | ||
config_check() | ||
api_instance = client.CustomObjectsApi(api_config_handler()) | ||
rcs = api_instance.list_cluster_custom_object( | ||
group="ray.io", | ||
version="v1alpha1", | ||
plural="rayclusters", | ||
) | ||
except Exception as e: | ||
return _kube_api_error_handling(e) | ||
for rc in rcs["items"]: | ||
list_of_clusters.append(_map_to_ray_cluster(rc)) | ||
return list_of_clusters | ||
Comment on lines
+561
to
+575
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add this functionality into the original the idea is that by default, @Maxusmusti WDYT? |
||
|
||
|
||
def _get_app_wrappers( | ||
namespace="default", filter=List[AppWrapperStatus] | ||
) -> List[AppWrapper]: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a little awkward that
delete
command returns a "Written to: xyz.yaml` message. Anyway we can avoid this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#278