Skip to content

Commit

Permalink
feat: add --wait option to deployment terminate
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <[email protected]>
  • Loading branch information
frostming committed Sep 23, 2024
1 parent a66d1bd commit 6ddd848
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
24 changes: 19 additions & 5 deletions src/bentoml/_internal/cloud/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def _init_deployment_files(
for fn in files:
full_path = os.path.join(root, fn)
rel_path = os.path.relpath(full_path, bento_dir)
if not bento_spec.includes(full_path) and rel_path != "bentofile.yaml":
if not bento_spec.includes(rel_path) and rel_path != "bentofile.yaml":
continue
if rel_path == REQUIREMENTS_TXT:
continue
Expand Down Expand Up @@ -735,9 +735,10 @@ def watch(self, bento_dir: str) -> None:
def watch_filter(change: watchfiles.Change, path: str) -> bool:
if not default_filter(change, path):
return False
if os.path.relpath(path, bento_dir) in ("bentofile.yaml", REQUIREMENTS_TXT):
rel_path = os.path.relpath(path, bento_dir)
if rel_path in ("bentofile.yaml", REQUIREMENTS_TXT):
return True
return bento_spec.includes(path)
return bento_spec.includes(rel_path)

console = Console(highlight=False)
bento_info = ensure_bento(
Expand Down Expand Up @@ -1169,19 +1170,32 @@ def get(self, name: str, cluster: str | None = None) -> Deployment:
res = self._client.v2.get_deployment(name, cluster)
return self._generate_deployment_info_(res, res.urls)

def terminate(self, name: str, cluster: str | None = None) -> Deployment:
def terminate(
self, name: str, cluster: str | None = None, wait: bool = False
) -> Deployment:
"""
Terminate a deployment.
Args:
name: The name of the deployment.
cluster: The name of the cluster.
wait: Whether to wait for the deployment to be terminated.
Returns:
The DeploymentInfo object.
"""
res = self._client.v2.terminate_deployment(name, cluster)
return self._generate_deployment_info_(res, res.urls)
deployment = self._generate_deployment_info_(res, res.urls)
if wait:
console = rich.get_console()
status = deployment.get_status(False).status
with console.status(
f"Waiting for deployment to terminate, current_status: [green]{status}[/]"
):
while status != DeploymentStatus.Terminated.value:
time.sleep(1)
status = deployment.get_status(True).status
return deployment

def delete(self, name: str, cluster: str | None = None) -> None:
"""
Expand Down
3 changes: 2 additions & 1 deletion src/bentoml/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,10 @@ def get(
def terminate(
name: str,
cluster: str | None = None,
wait: bool = False,
_cloud_client: BentoCloudClient = Provide[BentoMLContainer.bentocloud_client],
) -> Deployment:
return _cloud_client.deployment.terminate(name=name, cluster=cluster)
return _cloud_client.deployment.terminate(name=name, cluster=cluster, wait=wait)


@inject
Expand Down
5 changes: 3 additions & 2 deletions src/bentoml_cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,11 +692,12 @@ def get( # type: ignore
type=click.STRING,
required=True,
)
@click.option("--wait", is_flag=True, help="Wait for the deployment to be terminated")
def terminate( # type: ignore
name: str, cluster: str | None
name: str, cluster: str | None, wait: bool
) -> None:
"""Terminate a deployment on BentoCloud."""
bentoml.deployment.terminate(name, cluster=cluster)
bentoml.deployment.terminate(name, cluster=cluster, wait=wait)
rich.print(f"Deployment [green]'{name}'[/] terminated successfully.")


Expand Down

0 comments on commit 6ddd848

Please sign in to comment.