Azure / azure-cli-extensions

Public Repository for Extensions of Azure CLI.
https://docs.microsoft.com/en-us/cli/azure
MIT License
383 stars 1.24k forks source link

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

Open JosepSampe opened 1 year ago

JosepSampe commented 1 year ago

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.

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

SaurabhSharma-MSFT commented 1 year ago

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

yonzhan commented 1 year ago

route to CXP team

SaurabhSharma-MSFT commented 1 year ago

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

JosepSampe commented 1 year ago

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 commented 1 year ago

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

SaurabhSharma-MSFT commented 1 year ago

@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.

anthonychu commented 1 year ago

I think this is resolved by #5969

benjaminmillhouse commented 1 year ago

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....

maxiedaniels commented 11 months ago

Any resolution? I can't set ingress via yaml

abij commented 9 months ago

@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
lgmorand commented 8 months ago

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 :)

abij commented 8 months ago

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 🕵️‍♂️.

TiloGit commented 2 months ago

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

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