make cluster creation/deletion async by default (#16185)

This commit is contained in:
Raphael Randschau 2023-01-12 10:01:40 -08:00 committed by GitHub
parent 5de93975c6
commit 8d1d592295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 13 deletions

View File

@ -109,7 +109,7 @@ class AWSClusterManager:
region: str = "us-east-1",
external_id: str = None,
edit_before_creation: bool = False,
do_async: bool = False,
do_async: bool = True,
) -> None:
"""request Lightning AI BYOC compute cluster creation.
@ -192,7 +192,7 @@ class AWSClusterManager:
console = Console()
console.print(clusters.as_table())
def delete(self, cluster_id: str, force: bool = False, do_async: bool = False) -> None:
def delete(self, cluster_id: str, force: bool = False, do_async: bool = True) -> None:
if force:
click.echo(
"""

View File

@ -50,13 +50,13 @@ def create() -> None:
help="Edit the cluster specs before submitting them to the API server.",
)
@click.option(
"--async",
"do_async",
"--sync",
"do_sync",
type=bool,
required=False,
default=False,
is_flag=True,
help="This flag makes the CLI return immediately and lets the cluster creation happen in the background.",
help="This flag makes the CLI wait until cluster creation completes.",
)
def create_cluster(
cluster_id: str,
@ -66,7 +66,7 @@ def create_cluster(
provider: str,
edit_before_creation: bool,
enable_performance: bool,
do_async: bool,
do_sync: bool,
**kwargs: Any,
) -> None:
"""Create a Lightning AI BYOC compute cluster with your cloud provider credentials."""
@ -81,7 +81,7 @@ def create_cluster(
external_id=external_id,
edit_before_creation=edit_before_creation,
cost_savings=not enable_performance,
do_async=do_async,
do_async=not do_sync,
)

View File

@ -20,15 +20,15 @@ def delete() -> None:
@delete.command("cluster")
@click.argument("cluster", type=str)
@click.option(
"--async",
"do_async",
"--sync",
"do_sync",
type=bool,
required=False,
default=False,
is_flag=True,
help="This flag makes the CLI return immediately and lets the cluster deletion happen in the background",
help="This flag makes the CLI wait until cluster deletion completes.",
)
def delete_cluster(cluster: str, force: bool = False, do_async: bool = False) -> None:
def delete_cluster(cluster: str, force: bool = False, do_sync: bool = False) -> None:
"""Delete a Lightning AI BYOC cluster and all associated cloud provider resources.
Deleting a cluster also deletes all apps that were started on the cluster.
@ -44,7 +44,7 @@ def delete_cluster(cluster: str, force: bool = False, do_async: bool = False) ->
VPC components, etc. are irreversibly deleted and cannot be recovered!
"""
cluster_manager = AWSClusterManager()
cluster_manager.delete(cluster_id=cluster, force=force, do_async=do_async)
cluster_manager.delete(cluster_id=cluster, force=force, do_async=not do_sync)
def _find_cluster_for_user(app_name: str, cluster_id: Optional[str]) -> str:

View File

@ -88,6 +88,7 @@ def test_create_cluster(create_command: mock.MagicMock):
"dummy",
"--role-arn",
"arn:aws:iam::1234567890:role/lai-byoc",
"--sync",
],
)
@ -124,7 +125,7 @@ def test_list_clusters(list_command: mock.MagicMock):
@mock.patch("lightning_app.cli.cmd_clusters.AWSClusterManager.delete")
def test_delete_cluster(delete: mock.MagicMock):
runner = CliRunner()
runner.invoke(delete_cluster, ["test-7"])
runner.invoke(delete_cluster, ["test-7", "--sync"])
delete.assert_called_once_with(cluster_id="test-7", force=False, do_async=False)