azure-cli-extensions icon indicating copy to clipboard operation
azure-cli-extensions copied to clipboard

[Container App] 'az containerapp create' fails when 'ingress' is not present in the yaml

Open JosepSampe opened this issue 2 years ago • 13 comments

Describe the bug

ingress parameter under properties - configuration is defaulted to None if not provided in the yaml file. This causes this expression to fail:

https://github.com/Azure/azure-cli-extensions/blob/91447b8387457aa03052c37dd152412967fbe799/src/containerapp/azext_containerapp/custom.py#L294-L297

Command Name az containerapp create Extension Name: containerapp. Version: 0.3.20.

Errors:

The command failed with an unexpected error. Here is the traceback:
argument of type 'NoneType' is not iterable
Traceback (most recent call last):
  File "/opt/az/lib/python3.10/site-packages/knack/cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 663, in execute
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 726, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 718, in _run_job
    return cmd_copy.exception_handler(ex)
  File "/home/josep/.azure/cliextensions/containerapp/azext_containerapp/_client_factory.py", line 28, in _polish_bad_errors
    raise ex
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 697, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/__init__.py", line 333, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.10/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
    return op(**command_args)
  File "/home/josep/.azure/cliextensions/containerapp/azext_containerapp/custom.py", line 363, in create_containerapp
    return create_containerapp_yaml(cmd=cmd, name=name, resource_group_name=resource_group_name, file_name=yaml, no_wait=no_wait)
  File "/home/josep/.azure/cliextensions/containerapp/azext_containerapp/custom.py", line 302, in create_containerapp_yaml
    handle_raw_exception(e)
  File "/home/josep/.azure/cliextensions/containerapp/azext_containerapp/_client_factory.py", line 54, in handle_raw_exception
    raise e
  File "/home/josep/.azure/cliextensions/containerapp/azext_containerapp/custom.py", line 295, in create_containerapp_yaml
    if "configuration" in r["properties"] and r["properties"]["configuration"] and "ingress" in r["properties"]["configuration"] and "fqdn" in r["properties"]["configuration"]["ingress"]:
TypeError: argument of type 'NoneType' is not iterable

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • az containerapp create --name {} --resource-group {} --yaml {}

Expected Behavior

Environment Summary

Linux-5.15.79.1-microsoft-standard-WSL2-x86_64-with-glibc2.35, Ubuntu 22.04.1 LTS
Python 3.10.8
Installer: DEB

azure-cli 2.44.1

Extensions:
containerapp 0.3.20
log-analytics 0.2.2

Dependencies:
msal 1.20.0
azure-mgmt-resource 21.1.0b1

Additional Context

JosepSampe avatar Jan 13 '23 13:01 JosepSampe

@JosepSampe We are looking into it and get back to you for any additional information.

SaurabhSharma-MSFT avatar Jan 13 '23 23:01 SaurabhSharma-MSFT

route to CXP team

yonzhan avatar Jan 14 '23 01:01 yonzhan

@JosepSampe Do you happen to have the yaml file which you are using ?

SaurabhSharma-MSFT avatar Jan 31 '23 18:01 SaurabhSharma-MSFT

Here you go

https://github.com/lithops-cloud/lithops/blob/master/lithops/serverless/backends/azure_containers/config.py#L50-L121

Note that some of the fields are filled in at runtime

JosepSampe avatar Jan 31 '23 18:01 JosepSampe

Also note that now, as a workaroud, I simply removed these lines from my local installation and everything works fine https://github.com/Azure/azure-cli-extensions/blob/91447b8387457aa03052c37dd152412967fbe799/src/containerapp/azext_containerapp/custom.py#L294-L297

JosepSampe avatar Jan 31 '23 18:01 JosepSampe

@JosepSampe I am able to reproduce this issue without ingress and checking internally with the team the rationale behind it.
I will update you as soon as I have an answer. Thanks.

SaurabhSharma-MSFT avatar Feb 01 '23 19:02 SaurabhSharma-MSFT

I think this is resolved by #5969

anthonychu avatar Mar 23 '23 23:03 anthonychu

I think this is resolved by #5969

To whom it may concern... I am still getting an error as of containerapp version 0.3.25 when trying to "disable" ingress via the YAML file.

Confirming I am on 0.3.25 image

I have tried setting the "ingress" block various ways in my YAML, but keep getting a similar error: Bad Request({"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-801b153f799168f14863e8b9e12177ec-f08ea81a3ca3ebab-01","errors":{"$":["The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4."]}})

I have tried:

Leaving the "ingress" property off entirely (commented out)

and setting it like this

ingress:
    external: false

Please let me know if I am missing something....

benjaminmillhouse avatar Mar 31 '23 15:03 benjaminmillhouse

Any resolution? I can't set ingress via yaml

maxiedaniels avatar Dec 15 '23 04:12 maxiedaniels

@maxiedaniels @SaurabhSharma-MSFT

The error suggest there should be a boolean. So I checked the booleans in the Ingress... There is another boolean in ingress allowInsecure and when you have corsPolicy specified include the allowCredentials boolean, when set it does work for me! Can you try this?

# az containerapp create -n alex-test -g rg-alex-apps --yaml "app.yaml"
# This works, with ingress specified!

name: alex-test
api-version: 2023-08-01-preview

properties:
  environmentId: "/subscriptions/<subscription_id>/resourceGroups/rg/providers/Microsoft.App/managedEnvironments/<name>"
  configuration:
    ingress:
      external: true
      allowInsecure: false   # specify all booleans
      targetPort: 80
# Same happens here, boolean(s) need to be specified when cors is included:
#     corsPolicy:
#       allowCredentials: true
#       allowedOrigins:
#         - https://a.test.com


  template:
    containers:
    - image: nginx
      name: nginx

abij avatar Feb 08 '24 09:02 abij

that's crazy @abij . AllowInsecure unblocked me. How did you find this property ? It's not even listed in the documentation: https://learn.microsoft.com/en-us/azure/container-apps/azure-resource-manager-api-spec?tabs=yaml#examples

Eyh ACA Team, one year to fix this small bug :)

lgmorand avatar Feb 23 '24 00:02 lgmorand

I checked the API specs: https://learn.microsoft.com/en-us/rest/api/containerapps/container-apps/create-or-update?view=rest-containerapps-2023-08-01-preview&tabs=HTTP.

Here I found the booleans 🕵️‍♂️.

abij avatar Feb 24 '24 09:02 abij

got me today as well. needed to add these false for

    ingress:
      allowInsecure: false
      external: false      
      exposedPort: 12434
      targetPort: 12434
      transport: Tcp   

TiloGit avatar Sep 12 '24 21:09 TiloGit

Documentation link seems to be broken - https://learn.microsoft.com/en-us/rest/api/resource-manager/containerapps/container-apps/create-or-update?view=rest-resource-manager-containerapps-2024-03-01&tabs=HTTP seems to be the relevant one now. It doesn't say what fields are mandatory and error messages from the AZ CLI are not helpful as they do not say which field is causing the problem - only it's expected type e.g. The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 4.

DanUsername123 avatar Feb 19 '25 12:02 DanUsername123