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/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/_up_utils.py b/src/containerapp/azext_containerapp/_up_utils.py index 8830d7f76b3..045144a9c80 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,46 @@ 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 + + if self.location: + self.location = validate_environment_location(self.cmd, 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 + + 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 + + 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 diff --git a/src/containerapp/azext_containerapp/_utils.py b/src/containerapp/azext_containerapp/_utils.py index 21e58fde668..abf5f02bbfd 100644 --- a/src/containerapp/azext_containerapp/_utils.py +++ b/src/containerapp/azext_containerapp/_utils.py @@ -1506,42 +1506,19 @@ 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) 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 - - if len(res_locations) > 0: - 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)) + return res_locations[0] def list_environment_locations(cmd): 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