From e55116f1a626234880ac6af86659396b50c9e366 Mon Sep 17 00:00:00 2001 From: Haroon Feisal <38823870+haroonf@users.noreply.github.com> Date: Mon, 18 Jul 2022 12:10:38 -0700 Subject: [PATCH] Fixed update yaml bug with revision suffix (#136) * Fixed yaml breaking change and bug where revision suffix would return invalid if user is adding a container and the previous revision has a revision suffix. * Fixed revision suffix yaml bug. Co-authored-by: Haroon Feisal --- src/containerapp/azext_containerapp/custom.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/containerapp/azext_containerapp/custom.py b/src/containerapp/azext_containerapp/custom.py index dc340c2f0d8..4156ac049f8 100644 --- a/src/containerapp/azext_containerapp/custom.py +++ b/src/containerapp/azext_containerapp/custom.py @@ -151,10 +151,6 @@ def update_containerapp_yaml(cmd, name, resource_group_name, file_name, from_rev containerapp_def = None - # Change which revision we update from - if from_revision: - logger.warning('Flag --from-revision was passed along with --yaml. This flag will be ignored, and the configuration defined in the yaml will be used instead') - # Deserialize the yaml into a ContainerApp object. Need this since we're not using SDK try: deserializer = create_deserializer() @@ -174,6 +170,12 @@ def update_containerapp_yaml(cmd, name, resource_group_name, file_name, from_rev # After deserializing, some properties may need to be moved under the "properties" attribute. Need this since we're not using SDK containerapp_def = process_loaded_yaml(containerapp_def) + # Change which revision we update from + if from_revision: + r = ContainerAppClient.show_revision(cmd=cmd, resource_group_name=resource_group_name, container_app_name=name, name=from_revision) + _update_revision_env_secretrefs(r["properties"]["template"]["containers"], name) + containerapp_def["properties"]["template"] = r["properties"]["template"] + # Remove "additionalProperties" and read-only attributes that are introduced in the deserialization. Need this since we're not using SDK _remove_additional_attributes(containerapp_def) _remove_readonly_attributes(containerapp_def) @@ -184,6 +186,14 @@ def update_containerapp_yaml(cmd, name, resource_group_name, file_name, from_rev # Clean null values since this is an update containerapp_def = clean_null_values(containerapp_def) + # Fix bug with revisionSuffix when containers are added + if not safe_get(containerapp_def, "properties", "template", "revisionSuffix"): + if "properties" not in containerapp_def: + containerapp_def["properties"] = {} + if "template" not in containerapp_def["properties"]: + containerapp_def["properties"]["template"] = {} + containerapp_def["properties"]["template"]["revisionSuffix"] = None + try: r = ContainerAppClient.update( cmd=cmd, resource_group_name=resource_group_name, name=name, container_app_envelope=containerapp_def, no_wait=no_wait)