Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

better error handling for deployment actions #77

Merged
merged 1 commit into from
Feb 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 50 additions & 28 deletions bentoctl/deployment.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,68 @@
from logging import exception
import shutil

from bentoctl.deployment_config import DeploymentConfig
from bentoctl.operator import get_local_operator_registry
from bentoctl.exceptions import BentoctlException

local_operator_registry = get_local_operator_registry()


def deploy_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployable_path = deployment_resource.operator.deploy(
bento_path=deployment_resource.bento_path,
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
# remove the deployable
if deployable_path is not None:
shutil.rmtree(deployable_path)
try:
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployable_path = deployment_resource.operator.deploy(
bento_path=deployment_resource.bento_path,
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
# remove the deployable
if deployable_path is not None:
shutil.rmtree(deployable_path)
except Exception as e:
raise e if isinstance(e, BentoctlException) else BentoctlException(
f"Failed to deploy deployment. {e}"
)


def update_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployable_path = deployment_resource.operator.update(
bento_path=deployment_resource.bento_path,
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
if deployable_path is not None:
shutil.rmtree(deployable_path)
try:
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployable_path = deployment_resource.operator.update(
bento_path=deployment_resource.bento_path,
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
if deployable_path is not None:
shutil.rmtree(deployable_path)
except Exception as e:
raise e if isinstance(e, BentoctlException) else BentoctlException(
f"Failed to update deployment. {e}"
)


def describe_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
return deployment_resource.operator.describe(
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
try:
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
return deployment_resource.operator.describe(
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
except Exception as e:
raise e if isinstance(e, BentoctlException) else BentoctlException(
f"Failed to describe deployment. {e}"
)


def delete_deployment(deployment_config_path):
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployment_resource.operator.delete(
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
return deployment_resource.deployment_name
try:
deployment_resource = DeploymentConfig.from_file(deployment_config_path)
deployment_resource.operator.delete(
deployment_name=deployment_resource.deployment_name,
deployment_spec=deployment_resource.operator_spec,
)
return deployment_resource.deployment_name
except Exception as e:
raise e if isinstance(e, BentoctlException) else BentoctlException(
f"Failed to delete deployment. {e}"
)