Skip to content

Commit

Permalink
[Containerapp] az containerapp update: Fix issue for minReplicas in…
Browse files Browse the repository at this point in the history
… `--yaml` or `--min-replicas` is not set when the value is `0` (Azure#27948)
  • Loading branch information
Greedygre authored and albertofori committed Dec 14, 2023
1 parent fb7b6ed commit e340ed2
Show file tree
Hide file tree
Showing 9 changed files with 7,558 additions and 2,570 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ def clean_null_values(d):
return {
k: v
for k, v in ((k, clean_null_values(v)) for k, v in d.items())
if v or isinstance(v, list)
if v is not None or isinstance(v, list)
}
if isinstance(d, list):
return [v for v in map(clean_null_values, d) if v]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def update_containerapp_logic(cmd,
e["value"] = ""

update_map = {}
update_map['scale'] = min_replicas or max_replicas or scale_rule_name
update_map['scale'] = min_replicas is not None or max_replicas is not None or scale_rule_name
update_map['container'] = image or container_name or set_env_vars is not None or remove_env_vars is not None or replace_env_vars is not None or remove_all_env_vars or cpu or memory or startup_command is not None or args is not None or secret_volume_mount is not None
update_map['ingress'] = ingress or target_port
update_map['registry'] = registry_server or registry_user or registry_pass
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,31 @@ def test_containerapp_scale_revision_copy(self, resource_group):
JMESPathCheck("name", env_name),
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="westeurope")
def test_containerapp_replica_commands(self, resource_group):
self.cmd(f'configure --defaults location={TEST_LOCATION}')

app_name = self.create_random_name(prefix='aca', length=24)
replica_count = 3

env = prepare_containerapp_env_for_app_e2e_tests(self)

self.cmd(f'containerapp create -g {resource_group} -n {app_name} --environment {env} --ingress external --target-port 80 --min-replicas {replica_count}', checks=[
JMESPathCheck("properties.provisioningState", "Succeeded"),
JMESPathCheck("properties.template.scale.minReplicas", 3)
]).get_output_in_json()

self.cmd(f'containerapp replica list -g {resource_group} -n {app_name}', checks=[
JMESPathCheck('length(@)', replica_count),
])
self.cmd(f'containerapp update -g {resource_group} -n {app_name} --min-replicas 0', checks=[
JMESPathCheck("properties.provisioningState", "Succeeded"),
JMESPathCheck("properties.template.scale.minReplicas", 0)
])

self.cmd(f'containerapp delete -g {resource_group} -n {app_name} --yes')

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="westeurope")
def test_containerapp_create_with_yaml(self, resource_group):
Expand Down Expand Up @@ -1315,7 +1340,7 @@ def test_containerapp_create_with_yaml(self, resource_group):
cpu: 0.5
memory: 1Gi
scale:
minReplicas: 1
minReplicas: 0
maxReplicas: 3
rules: []
"""
Expand All @@ -1332,7 +1357,7 @@ def test_containerapp_create_with_yaml(self, resource_group):
JMESPathCheck("properties.environmentId", containerapp_env["id"]),
JMESPathCheck("properties.template.revisionSuffix", "myrevision2"),
JMESPathCheck("properties.template.containers[0].name", "nginx"),
JMESPathCheck("properties.template.scale.minReplicas", 1),
JMESPathCheck("properties.template.scale.minReplicas", 0),
JMESPathCheck("properties.template.scale.maxReplicas", 3),
JMESPathCheck("properties.template.scale.rules", None)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ def test_container_acr_env_var(self, resource_group):
])

# Update Container App with ACR
update_string = 'containerapp update -g {} -n {} --min-replicas 0 --max-replicas 1 --set-env-vars testenv=testing'.format(
update_string = 'containerapp update -g {} -n {} --min-replicas 1 --max-replicas 1 --set-env-vars testenv=testing'.format(
resource_group, containerapp_name)
self.cmd(update_string, checks=[
JMESPathCheck('name', containerapp_name),
JMESPathCheck('properties.configuration.registries[0].server', registry_server),
JMESPathCheck('properties.configuration.registries[0].username', registry_username),
JMESPathCheck('length(properties.configuration.secrets)', 1),
JMESPathCheck('properties.template.scale.minReplicas', '0'),
JMESPathCheck('properties.template.scale.minReplicas', '1'),
JMESPathCheck('properties.template.scale.maxReplicas', '1'),
JMESPathCheck('length(properties.template.containers[0].env)', 1),
JMESPathCheck('properties.template.containers[0].env[0].name', "testenv"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ def test_containerappjob_eventtriggered_create_with_yaml(self, resource_group, l
replicaCompletionCount: 1
parallelism: 1
scale:
minExecutions: 0
maxExecutions: 10
minExecutions: 1
maxExecutions: 11
rules:
- name: github-runner-test
type: github-runner
Expand Down Expand Up @@ -527,8 +527,8 @@ def test_containerappjob_eventtriggered_create_with_yaml(self, resource_group, l
JMESPathCheck('properties.template.containers[0].resources.memory', "1Gi"),
JMESPathCheck('properties.configuration.eventTriggerConfig.replicaCompletionCount', 1),
JMESPathCheck('properties.configuration.eventTriggerConfig.parallelism', 1),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.minExecutions', 0),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.maxExecutions', 10),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.minExecutions', 1),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.maxExecutions', 11),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.rules[0].type', "github-runner"),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.rules[0].metadata.runnerScope', "repo"),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.rules[0].auth[0].secretRef',
Expand Down Expand Up @@ -556,7 +556,7 @@ def test_containerappjob_eventtriggered_create_with_yaml(self, resource_group, l
replicaCompletionCount: 2
parallelism: 2
scale:
minExecutions: 5
minExecutions: 0
maxExecutions: 95
rules:
- name: github-runner-testv2
Expand Down Expand Up @@ -588,7 +588,7 @@ def test_containerappjob_eventtriggered_create_with_yaml(self, resource_group, l
JMESPathCheck('properties.template.containers[0].image', "mcr.microsoft.com/k8se/quickstart-jobs:latest"),
JMESPathCheck('properties.configuration.eventTriggerConfig.replicaCompletionCount', 2),
JMESPathCheck('properties.configuration.eventTriggerConfig.parallelism', 2),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.minExecutions', 5),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.minExecutions', 0),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.maxExecutions', 95),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.rules[0].name', "github-runner-testv2"),
JMESPathCheck('properties.configuration.eventTriggerConfig.scale.rules[0].metadata.runnerScope', "repo"),
Expand Down

0 comments on commit e340ed2

Please sign in to comment.