Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/azure-cli/azure/cli/command_modules/containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,28 @@
text: |
az containerapp env create -n MyContainerappEnvironment -g MyResourceGroup \\
--location eastus2 --enable-workload-profiles false
- name: Create a workload profiles environment using environment mode.
text: |
az containerapp env create -n MyContainerappEnvironment -g MyResourceGroup \\
--location eastus2 --environment-mode WorkloadProfiles
- name: Create a consumption-only environment using environment mode.
text: |
az containerapp env create -n MyContainerappEnvironment -g MyResourceGroup \\
--location eastus2 --environment-mode ConsumptionOnly
- name: Create an Express environment using environment mode.
text: |
az containerapp env create -n MyContainerappEnvironment -g MyResourceGroup \\
--location eastus2 --environment-mode Express
"""


helps['containerapp env update'] = """
type: command
short-summary: Update a Container Apps environment.
parameters:
- name: --environment-mode
short-summary: Mode of the environment, such as Express, WorkloadProfiles, or ConsumptionOnly.
long-summary: Only the environment mode is changed; existing apps are preserved. The service validates supported mode changes.
examples:
- name: Update an environment's custom domain configuration.
text: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def load_arguments(self, _):
c.argument('zone_redundant', options_list=["--zone-redundant", "-z"], help="Enable zone redundancy on the environment. Cannot be used without --infrastructure-subnet-resource-id. If used with --location, the subnet's location must match")
c.argument('enable_workload_profiles', arg_type=get_three_state_flag(), options_list=["--enable-workload-profiles", "-w"], help="Boolean indicating if the environment is enabled to have workload profiles")

for command in ['containerapp env create', 'containerapp env update']:
with self.argument_context(command) as c:
c.argument('environment_mode', options_list=['--environment-mode'], help="Mode of the environment, such as Express, WorkloadProfiles, or ConsumptionOnly.")

with self.argument_context('containerapp env update') as c:
c.argument('name', name_type, help='Name of the Container Apps environment.')
c.argument('tags', arg_type=tags_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,14 @@ def get_default_workload_profile_name_from_env(cmd, env_def, resource_group):
return env_profiles[0]["name"]


def validate_environment_mode_and_workload_profiles_compatible(environment_mode, workload_profiles_enabled):
if environment_mode is not None and workload_profiles_enabled is not None:
if environment_mode.lower() == 'consumptiononly' and workload_profiles_enabled:
raise ValidationError("Cannot use '--enable-workload-profiles' with '--environment-mode ConsumptionOnly'. Please use '--environment-mode' alone.")
if environment_mode.lower() != 'consumptiononly' and not workload_profiles_enabled:
raise ValidationError("Cannot use '--enable-workload-profiles false' with '--environment-mode {}'. Please use '--environment-mode' alone.".format(environment_mode))


def get_default_workload_profiles(cmd, location):
profiles = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
load_cert_file,
safe_set,
get_default_workload_profiles,
validate_environment_mode_and_workload_profiles_compatible,
_azure_monitor_quickstart, safe_get)
from ._client_factory import handle_raw_exception, handle_non_404_status_code_exception
from .base_resource import BaseResource
Expand Down Expand Up @@ -114,6 +115,14 @@ def get_argument_min_nodes(self):
def get_argument_max_nodes(self):
return self.get_param("max_nodes")

def get_argument_environment_mode(self):
return self.get_param("environment_mode")

def set_up_environment_mode(self):
environment_mode = self.get_argument_environment_mode()
if environment_mode:
safe_set(self.managed_env_def, "properties", "environmentMode", value=environment_mode)

def set_up_peer_to_peer_encryption(self):
is_p2p_encryption_enabled = self.get_argument_p2p_encryption_enabled()
is_mtls_enabled = self.get_argument_mtls_enabled()
Expand All @@ -133,10 +142,22 @@ def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models:
def get_argument_enable_workload_profiles(self):
return self.get_param("enable_workload_profiles")

def get_effective_workload_profiles(self):
environment_mode = self.get_argument_environment_mode()
if environment_mode:
return environment_mode.lower() != "consumptiononly"
return self.get_argument_enable_workload_profiles()

def get_argument_infrastructure_resource_group(self):
return self.get_param("infrastructure_resource_group")

def validate_arguments(self):
safe_params = self.cmd.cli_ctx.data.get('safe_params', [])
workload_profiles = self.get_argument_enable_workload_profiles() if (
'-w' in safe_params or '--enable-workload-profiles' in safe_params) else None
validate_environment_mode_and_workload_profiles_compatible(
self.get_argument_environment_mode(), workload_profiles)

location = self.get_argument_location()
if self.get_argument_zone_redundant():
if not self.get_argument_infrastructure_subnet_resource_id():
Expand Down Expand Up @@ -166,7 +187,10 @@ def validate_arguments(self):
if not self.get_argument_infrastructure_subnet_resource_id():
raise RequiredArgumentMissingError("Cannot use --infrastructure-resource-group/-i without "
"--infrastructure-subnet-resource-id/-s")
if not self.get_argument_enable_workload_profiles():
if not self.get_effective_workload_profiles():
if self.get_argument_environment_mode():
raise RequiredArgumentMissingError("Cannot use --infrastructure-resource-group/-i with "
"--environment-mode ConsumptionOnly")
raise RequiredArgumentMissingError("Cannot use --infrastructure-resource-group/-i without "
"--enable-workload-profiles/-w")

Expand Down Expand Up @@ -197,6 +221,7 @@ def construct_payload(self):
self.managed_env_def["properties"]["zoneRedundant"] = self.get_argument_zone_redundant()

self.set_up_workload_profiles()
self.set_up_environment_mode()

# Custom domains
if self.get_argument_hostname():
Expand All @@ -221,7 +246,7 @@ def construct_payload(self):
self.set_up_infrastructure_resource_group()

def set_up_infrastructure_resource_group(self):
if self.get_argument_enable_workload_profiles() and self.get_argument_infrastructure_subnet_resource_id() is not None:
if self.get_effective_workload_profiles() and self.get_argument_infrastructure_subnet_resource_id() is not None:
self.managed_env_def["properties"]["InfrastructureResourceGroup"] = self.get_argument_infrastructure_resource_group()

def set_up_workload_profiles(self):
Expand All @@ -233,15 +258,19 @@ def set_up_workload_profiles(self):
name=self.get_argument_name())
except Exception as e:
handle_non_404_status_code_exception(e)
if self.get_argument_enable_workload_profiles():
if self.get_effective_workload_profiles():
if existing_environment and safe_get(existing_environment, "properties", "workloadProfiles") is None:
# check if input params include -w/--enable-workload-profiles
if self.cmd.cli_ctx.data.get('safe_params') and ('-w' in self.cmd.cli_ctx.data.get(
'safe_params') or '--enable-workload-profiles' in self.cmd.cli_ctx.data.get('safe_params')):
safe_params = self.cmd.cli_ctx.data.get('safe_params', [])
if self.get_argument_environment_mode() or '-w' in safe_params or '--enable-workload-profiles' in safe_params:
raise ValidationError(
f"Existing environment {self.get_argument_name()} cannot enable workload profiles. If you want to use Consumption and Dedicated environment, please create a new one.")
return

if existing_environment and self.get_argument_environment_mode():
self.managed_env_def["properties"]["workloadProfiles"] = existing_environment["properties"]["workloadProfiles"]
return

self.managed_env_def["properties"]["workloadProfiles"] = get_default_workload_profiles(self.cmd, self.get_argument_location())
else:
if existing_environment and safe_get(existing_environment, "properties", "workloadProfiles") is not None:
Expand Down Expand Up @@ -332,6 +361,7 @@ def construct_payload(self):

# dapr
self.set_up_dapr()
self.set_up_environment_mode()

def set_up_app_log_configuration(self):
logs_destination = self.get_argument_logs_destination()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ def create_managed_environment(cmd,
enable_workload_profiles=True,
mtls_enabled=None,
p2p_encryption_enabled=None,
no_wait=False):
no_wait=False,
environment_mode=None):
raw_parameters = locals()
containerapp_env_create_decorator = ContainerAppEnvCreateDecorator(
cmd=cmd,
Expand Down Expand Up @@ -905,7 +906,8 @@ def update_managed_environment(cmd,
mtls_enabled=None,
p2p_encryption_enabled=None,
dapr_connection_string=None,
no_wait=False):
no_wait=False,
environment_mode=None):
raw_parameters = locals()
containerapp_env_update_decorator = ContainerAppEnvUpdateDecorator(
cmd=cmd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ class ContainerappEnvScenarioTest(ScenarioTest):
def __init__(self, *arg, **kwargs):
super().__init__(*arg, random_config_dir=True, **kwargs)

@live_only()
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
def test_containerapp_env_environment_mode(self, resource_group):
for mode in ['WorkloadProfiles', 'Express']:
env_name = self.create_random_name(prefix='env-mode-', length=24)
self.cmd(
'containerapp env create -g {} -n {} --location eastus2 '
'--environment-mode {} --logs-destination none'.format(resource_group, env_name, mode),
checks=[JMESPathCheck('properties.environmentMode', mode)])
self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name),
checks=[JMESPathCheck('properties.environmentMode', mode)])
self.cmd(
'containerapp env update -g {} -n {} --environment-mode Archived'.format(
resource_group, env_name),
checks=[JMESPathCheck('properties.environmentMode', 'Archived')])
self.cmd('containerapp env delete -g {} -n {} --yes --no-wait'.format(resource_group, env_name))

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="northeurope")
@LogAnalyticsWorkspacePreparer(location="eastus", get_shared_key=True)
Expand Down
Loading
Loading