Skip to content
Permalink
Browse files

add namespace and all namespace flag for dpeloyment cli (#269)

* add namespace and all namespace flag for dpeloyment cli

* remove extra param that pass into get_deployment_sub_command
  • Loading branch information...
yubozhao committed Aug 16, 2019
1 parent ca6b3d1 commit 34fce3fffea15039c6914e23f691bf39182a46a7
Showing with 39 additions and 11 deletions.
  1. +2 −2 bentoml/cli/__init__.py
  2. +37 −9 bentoml/cli/deployment.py
@@ -294,11 +294,11 @@ def create_bentoml_cli():
# are used as part of BentoML cli commands only.
add_legacy_deployment_commands(_cli)

deployment_sub_command = get_deployment_sub_command(_cli)
deployment_sub_command = get_deployment_sub_command()
config_sub_command = get_configuration_sub_command()
_cli.add_command(config_sub_command)
_cli.add_command(deployment_sub_command)

return _cli


@@ -43,6 +43,7 @@
from bentoml.utils import pb_to_yaml
from bentoml.utils.usage_stats import track_cli
from bentoml.exceptions import BentoMLDeploymentException, BentoMLException
from bentoml.deployment.store import ALL_NAMESPACE_TAG

SERVERLESS_PLATFORMS = ["aws-lambda", "aws-lambda-py2", "gcp-function"]

@@ -278,7 +279,7 @@ def parse_bento_tag(tag):
return items[0], items[1]


def get_deployment_sub_command(cli):
def get_deployment_sub_command():
@click.group()
def deploy():
pass
@@ -337,12 +338,15 @@ def deploy():
@click.option('--service-name', help="Name for service. For platform: Kubernetes")
@click.option('--service-type', help="Service Type. For platform: Kubernetes")
@click.option('--output', type=click.Choice(['json', 'yaml']), default='json')
@click.option('--namespace', type=click.STRING)
@click.option('--all-namespace', type=click.BOOL)
def apply(
bento,
deployment_name,
platform,
output,
namespace=None,
all_namespace=None,
labels=None,
annotations=None,
region=None,
@@ -389,6 +393,9 @@ def apply(
"Custom deployment configuration isn't supported in the current version"
)

if all_namespace:
namespace = ALL_NAMESPACE_TAG

result = get_yatai_service().ApplyDeployment(
ApplyDeploymentRequest(
deployment=Deployment(
@@ -418,10 +425,14 @@ def apply(

@deploy.command()
@click.option("--name", type=click.STRING, help="Deployment name", required=True)
def delete(name):
@click.option('--namespace', type=click.STRING)
@click.option('--all-namespace', type=click.BOOL)
def delete(name, namespace=None, all_namespace=None):
track_cli('deploy-delete')
if all_namespace:
namespace = ALL_NAMESPACE_TAG
result = get_yatai_service().DeleteDeployment(
DeleteDeploymentRequest(deployment_name=name)
DeleteDeploymentRequest(deployment_name=name, namespace=namespace)
)
if result.status.status_code != Status.OK:
_echo(
@@ -438,10 +449,14 @@ def delete(name):
@deploy.command()
@click.option("--name", type=click.STRING, help="Deployment name", required=True)
@click.option('--output', type=click.Choice(['json', 'yaml']), default='json')
def get(name, output):
@click.option('--namespace', type=click.STRING)
@click.option('--all-namespace', type=click.BOOL)
def get(name, output, namespace=None, all_namespace=None):
track_cli('deploy-get')
if all_namespace:
namespace = ALL_NAMESPACE_TAG
result = get_yatai_service().GetDeployment(
GetDeploymentRequest(deployment_name=name)
GetDeploymentRequest(deployment_name=name, namespace=namespace)
)
if result.status.status_code != Status.OK:
_echo(
@@ -458,10 +473,14 @@ def get(name, output):
@deploy.command()
@click.option("--name", type=click.STRING, help="Deployment name", required=True)
@click.option('--output', type=click.Choice(['json', 'yaml']), default='json')
def describe(name, output=None):
@click.option('--namespace', type=click.STRING)
@click.option('--all-namespace', type=click.BOOL)
def describe(name, output=None, namespace=None, all_namespace=None):
track_cli('deploy-describe')
if all_namespace:
namespace = ALL_NAMESPACE_TAG
result = get_yatai_service().DescribeDeployment(
DescribeDeploymentRequest(deployment_name=name)
DescribeDeploymentRequest(deployment_name=name, namespace=namespace)
)
if result.status.status_code != Status.OK:
_echo(
@@ -486,11 +505,20 @@ def describe(name, output=None):
"--labels", type=click.STRING, help="List deployments with the giving labels"
)
@click.option('--output', type=click.Choice(['json', 'yaml']), default='json')
def list(output, limit=None, filter=None, labels=None):
@click.option('--namespace', type=click.STRING)
@click.option('--all-namespace', type=click.BOOL)
def list(
output, limit=None, filter=None, labels=None, namespace=None, all_namespace=None
):
track_cli('deploy-list')
if all_namespace:
namespace = ALL_NAMESPACE_TAG
result = get_yatai_service().ListDeployments(
ListDeploymentsRequest(
limit=limit, filter=filter, labels=parse_key_value_pairs(labels)
limit=limit,
filter=filter,
labels=parse_key_value_pairs(labels),
namespace=namespace,
)
)
if result.status.status_code != Status.OK:

0 comments on commit 34fce3f

Please sign in to comment.
You can’t perform that action at this time.