diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 91f807d314c..f27704c86b6 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -223,4 +223,5 @@ /src/init/ @zhoxing-ms @HuangYT2000 /src/datamigration/ @ashutoshsuman99 -/src/azext_containerapp/ @calvinsID + +/src/azext_containerapp/ @calvinsID @panchagnula @haroonf diff --git a/src/containerapp/azext_containerapp/__init__.py b/src/containerapp/azext_containerapp/__init__.py index e19af22d9e8..f772766731c 100644 --- a/src/containerapp/azext_containerapp/__init__.py +++ b/src/containerapp/azext_containerapp/__init__.py @@ -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) diff --git a/src/containerapp/azext_containerapp/_client_factory.py b/src/containerapp/azext_containerapp/_client_factory.py index cc9da7661ec..f998486c63e 100644 --- a/src/containerapp/azext_containerapp/_client_factory.py +++ b/src/containerapp/azext_containerapp/_client_factory.py @@ -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 @@ -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 @@ -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 diff --git a/src/containerapp/azext_containerapp/_help.py b/src/containerapp/azext_containerapp/_help.py index b32ac7f7b90..ac9638014c7 100644 --- a/src/containerapp/azext_containerapp/_help.py +++ b/src/containerapp/azext_containerapp/_help.py @@ -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 diff --git a/src/containerapp/azext_containerapp/_params.py b/src/containerapp/azext_containerapp/_params.py index 52453298085..c38c32711c4 100644 --- a/src/containerapp/azext_containerapp/_params.py +++ b/src/containerapp/azext_containerapp/_params.py @@ -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.") diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 63006d1aae4..d0c5c996650 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -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: @@ -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], diff --git a/src/containerapp/azext_containerapp/_validators.py b/src/containerapp/azext_containerapp/_validators.py index 4b3286fa687..23ed260e360 100644 --- a/src/containerapp/azext_containerapp/_validators.py +++ b/src/containerapp/azext_containerapp/_validators.py @@ -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) diff --git a/src/containerapp/azext_containerapp/azext_metadata.json b/src/containerapp/azext_containerapp/azext_metadata.json index 55c81bf3328..001f223de90 100644 --- a/src/containerapp/azext_containerapp/azext_metadata.json +++ b/src/containerapp/azext_containerapp/azext_metadata.json @@ -1,4 +1,4 @@ { "azext.isPreview": true, "azext.minCliCoreVersion": "2.0.67" -} \ No newline at end of file +} diff --git a/src/containerapp/azext_containerapp/commands.py b/src/containerapp/azext_containerapp/commands.py index 20d7c332c0d..8fd840ccabd 100644 --- a/src/containerapp/azext_containerapp/commands.py +++ b/src/containerapp/azext_containerapp/commands.py @@ -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): diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index 00add15382d..005bb52d9af 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -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__) @@ -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) diff --git a/src/containerapp/setup.py b/src/containerapp/setup.py index b9f57ada671..be4cd26f637 100644 --- a/src/containerapp/setup.py +++ b/src/containerapp/setup.py @@ -57,4 +57,4 @@ packages=find_packages(), install_requires=DEPENDENCIES, package_data={'azext_containerapp': ['azext_metadata.json']}, -) \ No newline at end of file +)