Skip to content

Commit

Permalink
Various fixes, traffic weights fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinsID committed Mar 3, 2022
1 parent ab0e033 commit c32dd24
Show file tree
Hide file tree
Showing 11 changed files with 13 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,5 @@
/src/init/ @zhoxing-ms @HuangYT2000

/src/datamigration/ @ashutoshsuman99
/src/azext_containerapp/ @calvinsID

/src/azext_containerapp/ @calvinsID @panchagnula @haroonf
3 changes: 1 addition & 2 deletions src/containerapp/azext_containerapp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ class ContainerappCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_containerapp._client_factory import cf_containerapp
containerapp_custom = CliCommandType(
operations_tmpl='azext_containerapp.custom#{}',
client_factory=cf_containerapp)
client_factory=None)
super(ContainerappCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=containerapp_custom)

Expand Down
19 changes: 1 addition & 18 deletions src/containerapp/azext_containerapp/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


# pylint: disable=inconsistent-return-statements
def ex_handler_factory(creating_plan=False, no_throw=False):
def ex_handler_factory(no_throw=False):
def _polish_bad_errors(ex):
import json
from knack.util import CLIError
Expand All @@ -21,15 +21,6 @@ def _polish_bad_errors(ex):
elif 'Message' in content:
detail = content['Message']

if creating_plan:
if 'Requested features are not supported in region' in detail:
detail = ("Plan with linux worker is not supported in current region. For " +
"supported regions, please refer to https://docs.microsoft.com/"
"azure/app-service-web/app-service-linux-intro")
elif 'Not enough available reserved instance servers to satisfy' in detail:
detail = ("Plan with Linux worker can only be created in a group " +
"which has never contained a Windows worker, and vice versa. " +
"Please use a new resource group. Original error:" + detail)
ex = CLIError(detail)
except Exception: # pylint: disable=broad-except
pass
Expand Down Expand Up @@ -81,11 +72,3 @@ def log_analytics_shared_key_client_factory(cli_ctx):
from azure.mgmt.loganalytics import LogAnalyticsManagementClient

return get_mgmt_service_client(cli_ctx, LogAnalyticsManagementClient).shared_keys

def cf_containerapp(cli_ctx, *_):

from azure.cli.core.commands.client_factory import get_mgmt_service_client
# TODO: Replace CONTOSO with the appropriate label and uncomment
# from azure.mgmt.CONTOSO import CONTOSOManagementClient
# return get_mgmt_service_client(cli_ctx, CONTOSOManagementClient)
return None
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@

helps['containerapp env delete'] = """
type: command
short-summary: Deletes a Containerapp Environment.
short-summary: Delete a Containerapp Environment.
examples:
- name: Delete Containerapp Environment.
text: az containerapp env delete -g MyResourceGroup -n MyContainerappEnvironment
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def load_arguments(self, _):
c.argument('ingress', validator=validate_ingress, options_list=['--ingress'], default=None, arg_type=get_enum_type(['internal', 'external']), help="Ingress type that allows either internal or external traffic to the Containerapp.")
c.argument('target_port', type=int, validator=validate_target_port, options_list=['--target-port'], help="The application port used for ingress traffic.")
c.argument('transport', arg_type=get_enum_type(['auto', 'http', 'http2']), help="The transport protocol used for ingress traffic.")
c.argument('traffic_weights', nargs='*', options_list=['--traffic-weight'], help="A list of revision weight(s) for the Containerapp. Space-separated values in 'revision_name=weight' format.")
c.argument('traffic_weights', nargs='*', options_list=['--traffic-weight'], help="A list of revision weight(s) for the Containerapp. Space-separated values in 'revision_name=weight' format. For latest revision, use 'latest=weight'")

with self.argument_context('containerapp scale') as c:
c.argument('min_replicas', type=int, options_list=['--min-replicas'], help="The minimum number of containerapp replicas.")
Expand Down
9 changes: 2 additions & 7 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ def _is_valid_weight(weight):
return False


def _add_or_update_traffic_Weights(containerapp_def, list_weights):
if "traffic" not in containerapp_def["properties"]["configuration"]["ingress"]:
def _update_traffic_Weights(containerapp_def, list_weights):
if "traffic" not in containerapp_def["properties"]["configuration"]["ingress"] or list_weights and len(list_weights):
containerapp_def["properties"]["configuration"]["ingress"]["traffic"] = []

for new_weight in list_weights:
Expand All @@ -419,11 +419,6 @@ def _add_or_update_traffic_Weights(containerapp_def, list_weights):
if not _is_valid_weight(key_val[1]):
raise ValidationError('Traffic weights must be integers between 0 and 100')

for existing_weight in containerapp_def["properties"]["configuration"]["ingress"]["traffic"]:
if existing_weight["revisionName"].lower() == new_weight[0].lower():
is_existing = True
existing_weight["weight"] = int(key_val[1])

if not is_existing:
containerapp_def["properties"]["configuration"]["ingress"]["traffic"].append({
"revisionName": key_val[0],
Expand Down
15 changes: 0 additions & 15 deletions src/containerapp/azext_containerapp/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,6 @@
from azure.cli.core.azclierror import (ValidationError, RequiredArgumentMissingError)


def example_name_or_id_validator(cmd, namespace):
# Example of a storage account name or ID validator.
# See: https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters
from azure.cli.core.commands.client_factory import get_subscription_id
from msrestazure.tools import is_valid_resource_id, resource_id
if namespace.storage_account:
if not is_valid_resource_id(namespace.RESOURCE):
namespace.storage_account = resource_id(
subscription=get_subscription_id(cmd.cli_ctx),
resource_group=namespace.resource_group_name,
namespace='Microsoft.Storage',
type='storageAccounts',
name=namespace.storage_account
)

def _is_number(s):
try:
float(s)
Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"azext.isPreview": true,
"azext.minCliCoreVersion": "2.0.67"
}
}
2 changes: 1 addition & 1 deletion src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# pylint: disable=line-too-long
from azure.cli.core.commands import CliCommandType
from msrestazure.tools import is_valid_resource_id, parse_resource_id
from azext_containerapp._client_factory import cf_containerapp, ex_handler_factory
from azext_containerapp._client_factory import ex_handler_factory


def transform_containerapp_output(app):
Expand Down
8 changes: 2 additions & 6 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
parse_secret_flags, store_as_secret_and_return_secret_ref, parse_list_of_strings, parse_env_var_flags,
_generate_log_analytics_if_not_provided, _get_existing_secrets, _convert_object_from_snake_to_camel_case,
_object_to_dict, _add_or_update_secrets, _remove_additional_attributes, _remove_readonly_attributes,
_add_or_update_env_vars, _add_or_update_tags, update_nested_dictionary, _add_or_update_traffic_Weights,
_add_or_update_env_vars, _add_or_update_tags, update_nested_dictionary, _update_traffic_Weights,
_get_app_from_revision)

logger = get_logger(__name__)
Expand Down Expand Up @@ -627,15 +627,11 @@ def update_containerapp(cmd,
if target_port is not None:
containerapp_def["properties"]["configuration"]["ingress"]["targetPort"] = target_port

config = containerapp_def["properties"]["configuration"]["ingress"]
if (config["targetPort"] is not None and config["external"] is None) or (config["targetPort"] is None and config["external"] is not None):
raise ValidationError("Usage error: must specify --target-port with --ingress")

if transport is not None:
containerapp_def["properties"]["configuration"]["ingress"]["transport"] = transport

if traffic_weights is not None:
containerapp_def["properties"]["configuration"]["ingress"]["traffic"] = _add_or_update_traffic_Weights(containerapp_def, traffic_weights)
_update_traffic_Weights(containerapp_def, traffic_weights)

_get_existing_secrets(cmd, resource_group_name, name, containerapp_def)

Expand Down
2 changes: 1 addition & 1 deletion src/containerapp/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
packages=find_packages(),
install_requires=DEPENDENCIES,
package_data={'azext_containerapp': ['azext_metadata.json']},
)
)

0 comments on commit c32dd24

Please sign in to comment.