From 6f5a857185117c487a1dcb3185dfaba3112fa41f Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Mon, 21 Nov 2022 14:45:20 +0800 Subject: [PATCH 1/9] Update History.rst and setup.rst --- src/containerapp/HISTORY.rst | 4 ++++ src/containerapp/setup.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/containerapp/HISTORY.rst b/src/containerapp/HISTORY.rst index 2e08fd80e15..886391caeb7 100644 --- a/src/containerapp/HISTORY.rst +++ b/src/containerapp/HISTORY.rst @@ -3,6 +3,10 @@ Release History =============== +0.3.16 +++++++ +* Remove quota check for 'az containerapp up' and 'az containerapp env create'. + 0.3.15 ++++++ * Add 'az containerapp containerapp ingress ip-restriction' command group to manage IP restrictions on the ingress of a container app. diff --git a/src/containerapp/setup.py b/src/containerapp/setup.py index 5d2676788a6..60a3af6dfdb 100644 --- a/src/containerapp/setup.py +++ b/src/containerapp/setup.py @@ -17,7 +17,7 @@ # TODO: Confirm this is the right version number you want and it matches your # HISTORY.rst entry. -VERSION = '0.3.15' +VERSION = '0.3.16' # The full list of classifiers is available at # https://pypi.python.org/pypi?%3Aaction=list_classifiers From 1365cbb250b0c892d7ca4cf1a4a18f9130a1548c Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Tue, 15 Nov 2022 11:53:43 +0800 Subject: [PATCH 2/9] Remove quota check while creating ManagedEnvironments --- src/containerapp/azext_containerapp/_utils.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 21e58fde668..58e6cecefb1 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1506,24 +1506,7 @@ def is_registry_msi_system(identity): def validate_environment_location(cmd, location): - from ._constants import MAX_ENV_PER_LOCATION - from .custom import list_managed_environments - env_list = list_managed_environments(cmd) - - locations = [loc["location"] for loc in env_list] - locations = list(set(locations)) # remove duplicates - - location_count = {} - for loc in locations: - location_count[loc] = len([e for e in env_list if e["location"] == loc]) # pylint: disable=used-before-assignment - - disallowed_locations = [] - for _, value in enumerate(location_count): - if location_count[value] > MAX_ENV_PER_LOCATION - 1: - disallowed_locations.append(value) - res_locations = list_environment_locations(cmd) - res_locations = [loc for loc in res_locations if loc not in disallowed_locations] allowed_locs = ", ".join(res_locations) @@ -1537,8 +1520,6 @@ def validate_environment_location(cmd, location): if not location: logger.warning("Creating environment on location %s.", res_locations[0]) return res_locations[0] - if location in disallowed_locations: - raise ValidationError("You have more than {} environments in location {}. List of eligible locations: {}.".format(MAX_ENV_PER_LOCATION, location, allowed_locs)) return location else: raise ValidationError("You cannot create any more environments. Environments are limited to {} per location in a subscription. Please specify an existing environment using --environment.".format(MAX_ENV_PER_LOCATION)) From cdc12a9ca78f2c0b4ba0f4ed6464de0091e4a162 Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Tue, 15 Nov 2022 13:51:16 +0800 Subject: [PATCH 3/9] Remove MAX_ENV_PER_LOCATION in Constants.py --- src/containerapp/azext_containerapp/_constants.py | 2 -- src/containerapp/azext_containerapp/_utils.py | 11 ++++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/containerapp/azext_containerapp/_constants.py b/src/containerapp/azext_containerapp/_constants.py index 7324bb5291b..38d57684f45 100644 --- a/src/containerapp/azext_containerapp/_constants.py +++ b/src/containerapp/azext_containerapp/_constants.py @@ -14,8 +14,6 @@ LOG_ANALYTICS_RP = "Microsoft.OperationalInsights" CONTAINER_APPS_RP = "Microsoft.App" -MAX_ENV_PER_LOCATION = 5 - MICROSOFT_SECRET_SETTING_NAME = "microsoft-provider-authentication-secret" FACEBOOK_SECRET_SETTING_NAME = "facebook-provider-authentication-secret" GITHUB_SECRET_SETTING_NAME = "github-provider-authentication-secret" diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 58e6cecefb1..6caca7d971c 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1516,13 +1516,10 @@ def validate_environment_location(cmd, location): except Exception as e: # pylint: disable=broad-except raise ValidationError("You cannot create a Containerapp environment in location {}. List of eligible locations: {}.".format(location, allowed_locs)) from e - if len(res_locations) > 0: - if not location: - logger.warning("Creating environment on location %s.", res_locations[0]) - return res_locations[0] - return location - else: - raise ValidationError("You cannot create any more environments. Environments are limited to {} per location in a subscription. Please specify an existing environment using --environment.".format(MAX_ENV_PER_LOCATION)) + if not location: + logger.warning("Creating environment on location %s.", res_locations[0]) + return res_locations[0] + return location def list_environment_locations(cmd): From e8f5eb0b5e4c7abd0048b0c9b74c434604d5b040 Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Thu, 17 Nov 2022 11:52:05 +0800 Subject: [PATCH 4/9] Update up_utils to adjust az containerapp up --- .../azext_containerapp/_up_utils.py | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index 8830d7f76b3..c22c2cd6c91 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -46,7 +46,8 @@ trigger_workflow, _ensure_location_allowed, register_provider_if_needed, - validate_environment_location + validate_environment_location, + list_environment_locations ) from ._constants import (MAXIMUM_SECRET_LENGTH, @@ -203,19 +204,31 @@ def create_if_needed(self, app_name): ) # TODO use .info() def create(self): - self.location = validate_environment_location(self.cmd, self.location) register_provider_if_needed(self.cmd, LOG_ANALYTICS_RP) - env = create_managed_environment( - self.cmd, - self.name, - location=self.location, - resource_group_name=self.resource_group.name, - logs_key=self.logs_key, - logs_customer_id=self.logs_customer_id, - disable_warnings=True, - ) - self.exists = True - return env + + res_locations = list_environment_locations(self.cmd) + for loc in res_locations: + try: + env = create_managed_environment( + self.cmd, + self.name, + location=self.location, + resource_group_name=self.resource_group.name, + logs_key=self.logs_key, + logs_customer_id=self.logs_customer_id, + disable_warnings=True, + ) + + self.exists = True + self.location = loc + + return env + except Exception as ex: + logger.info( + f"Failed to create ManagedEnvironment in {loc} due to {ex}" + ) + + raise ValidationError("Can not find a region with quota to create ManagedEnvironment") def get_rid(self): rid = self.name From f5437d5fc2ed92f6529e1283d4802ac5b7ae0d0b Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Fri, 18 Nov 2022 10:39:43 +0800 Subject: [PATCH 5/9] Use user input parameter as first priority --- .../azext_containerapp/_up_utils.py | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index c22c2cd6c91..86bfe548308 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -206,10 +206,10 @@ def create_if_needed(self, app_name): def create(self): register_provider_if_needed(self.cmd, LOG_ANALYTICS_RP) - res_locations = list_environment_locations(self.cmd) - for loc in res_locations: - try: - env = create_managed_environment( + self.location = validate_environment_location(self.cmd, self.location) + + if self.location: + env = create_managed_environment( self.cmd, self.name, location=self.location, @@ -218,17 +218,32 @@ def create(self): logs_customer_id=self.logs_customer_id, disable_warnings=True, ) + self.exists = True + + return env + else: + res_locations = list_environment_locations(self.cmd) + for loc in res_locations: + try: + env = create_managed_environment( + self.cmd, + self.name, + location=loc, + resource_group_name=self.resource_group.name, + logs_key=self.logs_key, + logs_customer_id=self.logs_customer_id, + disable_warnings=True, + ) - self.exists = True - self.location = loc + self.exists = True + self.location = loc - return env - except Exception as ex: - logger.info( - f"Failed to create ManagedEnvironment in {loc} due to {ex}" - ) - - raise ValidationError("Can not find a region with quota to create ManagedEnvironment") + return env + except Exception as ex: + logger.info( + f"Failed to create ManagedEnvironment in {loc} due to {ex}" + ) + raise ValidationError("Can not find a region with quota to create ManagedEnvironment") def get_rid(self): rid = self.name From a52bb50788005b7e05a255d571456abeacfbdc83 Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Mon, 21 Nov 2022 14:24:10 +0800 Subject: [PATCH 6/9] Remove location null check while validating environments --- src/containerapp/azext_containerapp/_utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 6caca7d971c..298611915d1 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1516,9 +1516,6 @@ def validate_environment_location(cmd, location): except Exception as e: # pylint: disable=broad-except raise ValidationError("You cannot create a Containerapp environment in location {}. List of eligible locations: {}.".format(location, allowed_locs)) from e - if not location: - logger.warning("Creating environment on location %s.", res_locations[0]) - return res_locations[0] return location From 4841b91e9a8e5ac8a8b4abac9a6de6fb8f0cef15 Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Mon, 21 Nov 2022 15:54:08 +0800 Subject: [PATCH 7/9] Style fix --- .../azext_containerapp/_up_utils.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index 86bfe548308..5304b8f1d0a 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -208,20 +208,20 @@ def create(self): self.location = validate_environment_location(self.cmd, self.location) - if self.location: + if self.location: env = create_managed_environment( - self.cmd, - self.name, - location=self.location, - resource_group_name=self.resource_group.name, - logs_key=self.logs_key, - logs_customer_id=self.logs_customer_id, - disable_warnings=True, - ) - self.exists = True + self.cmd, + self.name, + location=self.location, + resource_group_name=self.resource_group.name, + logs_key=self.logs_key, + logs_customer_id=self.logs_customer_id, + disable_warnings=True, + ) + self.exists = True return env - else: + else: res_locations = list_environment_locations(self.cmd) for loc in res_locations: try: @@ -235,7 +235,7 @@ def create(self): disable_warnings=True, ) - self.exists = True + self.exists = True self.location = loc return env From 80ac0ff7a57edc8f30bf319b11abd71135923714 Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Mon, 21 Nov 2022 16:31:19 +0800 Subject: [PATCH 8/9] Update location return logic --- src/containerapp/azext_containerapp/_up_utils.py | 4 ++-- src/containerapp/azext_containerapp/_utils.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index 5304b8f1d0a..9ac58000a9d 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -206,9 +206,9 @@ def create_if_needed(self, app_name): def create(self): register_provider_if_needed(self.cmd, LOG_ANALYTICS_RP) - self.location = validate_environment_location(self.cmd, self.location) - if self.location: + self.location = validate_environment_location(self.cmd, self.location) + env = create_managed_environment( self.cmd, self.name, diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 298611915d1..96bf1be07ad 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1513,12 +1513,13 @@ def validate_environment_location(cmd, location): if location: try: _ensure_location_allowed(cmd, location, CONTAINER_APPS_RP, "managedEnvironments") + + return location except Exception as e: # pylint: disable=broad-except raise ValidationError("You cannot create a Containerapp environment in location {}. List of eligible locations: {}.".format(location, allowed_locs)) from e - - return location - - + else: + return res_locations[0] + def list_environment_locations(cmd): providers_client = providers_client_factory(cmd.cli_ctx, get_subscription_id(cmd.cli_ctx)) resource_types = getattr(providers_client.get(CONTAINER_APPS_RP), 'resource_types', []) From 0eebe6ed5ad2ec1ba3ff5f5d59b67dfe31862896 Mon Sep 17 00:00:00 2001 From: Zijian Ju Date: Mon, 21 Nov 2022 16:48:50 +0800 Subject: [PATCH 9/9] Style fix --- src/containerapp/azext_containerapp/_up_utils.py | 2 +- src/containerapp/azext_containerapp/_utils.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/containerapp/azext_containerapp/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index 9ac58000a9d..045144a9c80 100644 --- a/src/containerapp/azext_containerapp/_up_utils.py +++ b/src/containerapp/azext_containerapp/_up_utils.py @@ -208,7 +208,7 @@ def create(self): if self.location: self.location = validate_environment_location(self.cmd, self.location) - + env = create_managed_environment( self.cmd, self.name, diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 96bf1be07ad..abf5f02bbfd 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1517,9 +1517,10 @@ def validate_environment_location(cmd, location): return location except Exception as e: # pylint: disable=broad-except raise ValidationError("You cannot create a Containerapp environment in location {}. List of eligible locations: {}.".format(location, allowed_locs)) from e - else: + else: return res_locations[0] - + + def list_environment_locations(cmd): providers_client = providers_client_factory(cmd.cli_ctx, get_subscription_id(cmd.cli_ctx)) resource_types = getattr(providers_client.get(CONTAINER_APPS_RP), 'resource_types', [])