Skip to content

Commit

Permalink
Fix Containerapp YAML not reading workloadProfileName (Azure#6194)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bouchon authored Apr 14, 2023
1 parent c385a0e commit d54d48c
Show file tree
Hide file tree
Showing 32 changed files with 48,514 additions and 134,469 deletions.
1 change: 1 addition & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Upcoming
* 'az containerapp update': change --max-replicas limit
* Add CLI support for containerapp ingress sticky-sessions'
* Change quickstart image
* 'az containerapp create': fix yaml not detecting workloadProfileName

0.3.27
++++++
Expand Down
3 changes: 2 additions & 1 deletion src/containerapp/azext_containerapp/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
"properties": {
"environmentId": None,
"configuration": None, # Configuration
"template": None # Template
"template": None, # Template
"workloadProfileName": None
},
"tags": None
}
Expand Down
4 changes: 4 additions & 0 deletions src/containerapp/azext_containerapp/_sdk_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ class ContainerApp(TrackedResource):
:param managed_environment_id: Resource ID of the Container App's
environment.
:type managed_environment_id: str
:param workload_profile_name: Name of the workload profile used
:type workload_profile_name: str
:ivar latest_revision_name: Name of the latest revision of the Container
App.
:vartype latest_revision_name: str
Expand Down Expand Up @@ -996,6 +998,7 @@ class ContainerApp(TrackedResource):
'identity': {'key': 'identity', 'type': 'ManagedServiceIdentity'},
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
'environment_id': {'key': 'properties.environmentId', 'type': 'str'},
'workload_profile_name': {'key': 'properties.workloadProfileName', 'type': 'str'},
'latest_revision_name': {'key': 'properties.latestRevisionName', 'type': 'str'},
'latest_revision_fqdn': {'key': 'properties.latestRevisionFqdn', 'type': 'str'},
'custom_domain_verification_id': {'key': 'properties.customDomainVerificationId', 'type': 'str'},
Expand All @@ -1009,6 +1012,7 @@ def __init__(self, **kwargs):
self.identity = kwargs.get('identity', None)
self.provisioning_state = None
self.environment_id = kwargs.get('environment_id', None)
self.workload_profile_name = kwargs.get('workload_profile_name', None)
self.latest_revision_name = None
self.latest_revision_fqdn = None
self.custom_domain_verification_id = None
Expand Down
5 changes: 3 additions & 2 deletions src/containerapp/azext_containerapp/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1611,8 +1611,9 @@ def get_default_workload_profiles(cmd, location):

def ensure_workload_profile_supported(cmd, env_name, env_rg, workload_profile_name, managed_env_info):
profile_names = [p["name"] for p in safe_get(managed_env_info, "properties", "workloadProfiles", default=[])]
if workload_profile_name not in profile_names:
raise ValidationError(f"Not a valid workload profile name: '{workload_profile_name}'. Run 'az containerapp env workload-profile list -n myEnv -g myResourceGroup' to see options.")
profile_names_lower = [p.lower() for p in profile_names]
if workload_profile_name.lower() not in profile_names_lower:
raise ValidationError(f"Not a valid workload profile name: '{workload_profile_name}'. The valid workload profiles names for this environment are: '{', '.join(profile_names)}'")


def set_ip_restrictions(ip_restrictions, ip_restriction_name, ip_address_range, description, action):
Expand Down
20 changes: 19 additions & 1 deletion src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def process_loaded_yaml(yaml_containerapp):
yaml_containerapp['identity']['userAssignedIdentities'][identity] = {}

nested_properties = ["provisioningState", "managedEnvironmentId", "environmentId", "latestRevisionName", "latestRevisionFqdn",
"customDomainVerificationId", "configuration", "template", "outboundIPAddresses"]
"customDomainVerificationId", "configuration", "template", "outboundIPAddresses", "workloadProfileName"]
for nested_property in nested_properties:
tmp = yaml_containerapp.get(nested_property)
if tmp:
Expand Down Expand Up @@ -267,6 +267,10 @@ def create_containerapp_yaml(cmd, name, resource_group_name, file_name, no_wait=
_remove_additional_attributes(containerapp_def)
_remove_readonly_attributes(containerapp_def)

# Remove extra workloadProfileName introduced in deserialization
if "workloadProfileName" in containerapp_def:
del containerapp_def["workloadProfileName"]

# Validate managed environment
if not containerapp_def["properties"].get('environmentId'):
raise RequiredArgumentMissingError('environmentId is required. This can be retrieved using the `az containerapp env show -g MyResourceGroup -n MyContainerappEnvironment --query id` command. Please see https://aka.ms/azure-container-apps-yaml for a valid containerapps YAML spec.')
Expand Down Expand Up @@ -685,6 +689,20 @@ def update_containerapp_logic(cmd,
if workload_profile_name:
new_containerapp["properties"]["workloadProfileName"] = workload_profile_name

parsed_managed_env = parse_resource_id(containerapp_def["properties"]["managedEnvironmentId"])
managed_env_name = parsed_managed_env['name']
managed_env_rg = parsed_managed_env['resource_group']
managed_env_info = None
try:
managed_env_info = ManagedEnvironmentClient.show(cmd=cmd, resource_group_name=managed_env_rg, name=managed_env_name)
except:
pass

if not managed_env_info:
raise ValidationError("Error parsing the managed environment '{}' from the specified containerapp".format(managed_env_name))

ensure_workload_profile_supported(cmd, managed_env_name, managed_env_rg, workload_profile_name, managed_env_info)

# Containers
if update_map["container"]:
new_containerapp["properties"]["template"] = {} if "template" not in new_containerapp["properties"] else new_containerapp["properties"]["template"]
Expand Down
Loading

0 comments on commit d54d48c

Please sign in to comment.