Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ContainerApp] Added support for Cloud Patching #7571

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

harryli0108
Copy link
Member

@harryli0108 harryli0108 commented May 2, 2024


This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Copy link

azure-client-tools-bot-prd bot commented May 2, 2024

⚠️Azure CLI Extensions Breaking Change Test
⚠️containerapp
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd containerapp patch apply cmd containerapp patch apply added parameter container_app_name
⚠️ 1006 - ParaAdd containerapp patch apply cmd containerapp patch apply added parameter patch_name
⚠️ 1011 - SubgroupAdd containerapp patch configure sub group containerapp patch configure added
⚠️ 1001 - CmdAdd containerapp patch delete cmd containerapp patch delete added
⚠️ 1006 - ParaAdd containerapp patch list cmd containerapp patch list added parameter container_app_name
⚠️ 1001 - CmdAdd containerapp patch show cmd containerapp patch show added

Copy link

Hi @harryli0108,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan
Copy link
Collaborator

yonzhan commented May 2, 2024

ContainerApp

Copy link

github-actions bot commented May 2, 2024

⚠️ Release Suggestions

Module: containerapp

  • Update VERSION to 1.0.0b1 in src/containerapp/setup.py

Notes

  • Stable/preview tag is inherited from last release. If needed, please add stable/preview label to modify it.
  • Major/minor/patch/pre increment of version number is calculated by pull request code changes automatically. If needed, please add major/minor/patch/pre label to adjust it.
  • For more info about extension versioning, please refer to Extension version schema

Copy link

@Moazzem-Hossain-pixel Moazzem-Hossain-pixel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take the necessary steps.

Copy link

@Moazzem-Hossain-pixel Moazzem-Hossain-pixel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help to resolve

@@ -1483,7 +1484,25 @@ def set_workload_profile(cmd, resource_group_name, env_name, workload_profile_na
return update_managed_environment(cmd, env_name, resource_group_name, workload_profile_type=workload_profile_type, workload_profile_name=workload_profile_name, min_nodes=min_nodes, max_nodes=max_nodes)


def patch_list(cmd, resource_group_name=None, managed_env=None, show_all=False):
def patch_list(cmd, resource_group_name=None, managed_env=None, container_app_name=None, show_all=False):
from azure.cli.command_modules.containerapp._utils import format_location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this import statement to the top of this file

@@ -1539,6 +1558,81 @@ def patch_list(cmd, resource_group_name=None, managed_env=None, show_all=False):
return results


def patch_show(cmd, resource_group_name=None, container_app_name=None, patch_name=None):
from azure.cli.command_modules.containerapp._utils import format_location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this import statement to the top and re-use across methods.

if format_location(app["location"]) != format_location("North Central US (Stage)"):
logger.warning("Cloud patching is not supported in the location of the container app.")
return
from ._clients import PatchClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment - Move all imports to the top.



def patch_delete(cmd, resource_group_name=None, container_app_name=None, patch_name=None):
from azure.cli.command_modules.containerapp._utils import format_location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment about moving this import statement to the top

from azure.cli.command_modules.containerapp._utils import format_location
logger.warning("This command is currently only available for container app cloud patches in North Central US (Stage).")
if patch_name is None:
logger.error("Please provide the name of the patch to delete.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw a validation error instead of just logging as an error?

if format_location(app["location"]) != format_location("North Central US (Stage)"):
logger.warning("Cloud patching is not supported in the location of the container app.")
return
from ._clients import PatchClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment about import statement

if app is None:
logger.error("Container app {0} not found in resource group {1}.".format(container_app_name, resource_group_name))
return
if format_location(app["location"]) != format_location("North Central US (Stage)"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use safe_get instead of just app["location"]



def patch_mode_configure(cmd, resource_group_name=None, container_app_name=None, patch_mode=None):
from azure.cli.command_modules.containerapp._utils import format_location
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move import

if patch_mode not in ["Automatic", "Manual", "Disabled"]:
logger.error("Invalid patch mode provided. Please provide 'Automatic', 'Manual', or 'Disabled'.")
return
from ._clients import PatchClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move imort

@@ -1650,6 +1747,28 @@ def patch_apply(cmd, resource_group_name=None, managed_env=None, show_all=False)
patch_apply_handle_input(cmd, patchable_check_results, "y", pack_exec_path)


def use_cloud_patch(cmd, container_app_name, resource_group_name, patch_name):
try:
app = show_containerapp(cmd, container_app_name, resource_group_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this throw a not found exception if container app does not exist? Probably need to handle it separately? by check if not found exception is thrown in a separate method and return None if it is

if app is None:
logger.error("Container app {0} not found in resource group {1}.".format(container_app_name, resource_group_name))
return
if app["location"] == "North Central US (Stage)":
Copy link
Contributor

@snehapar9 snehapar9 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use safe_get() here for getting the app's location and let's use STAGE_LOCATION from the constants file instead of hardcoding it here.

patch_client = PatchClient()
is_patch_success = patch_client.apply(cmd, resource_group_name, container_app_name, patch_name)
if is_patch_success:
print("Patch {0} for container app {1} is queued successfully to be applied.".format(patch_name, container_app_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.warning if we want this to show up on cx console?

if app["location"] == "North Central US (Stage)":
logger.warning("Using cloud patching...")
logger.warning("Cloud patching is only supported in North Central US (Stage) now.")
from ._clients import PatchClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move import.

logger.error("Container app {0} not found in resource group {1}.".format(container_app_name, resource_group_name))
return
if app["location"] == "North Central US (Stage)":
logger.warning("Using cloud patching...")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's combine this into a single line.

patch_client = PatchClient()
is_patch_mode_configured = patch_client.patch_mode_configure(cmd, resource_group_name, container_app_name, patch_mode)
if is_patch_mode_configured:
print("Patch mode for container app {0} is set to {1}.".format(container_app_name, patch_mode))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.warning if we want this to show up on the console.

logger.error("Failed to fetch container app {0} in resource group {1}. Error: {2}".format(container_app_name, resource_group_name, str(e)))
return
if app is None:
logger.error("Container app {0} not found in resource group {1}.".format(container_app_name, resource_group_name))
Copy link
Contributor

@snehapar9 snehapar9 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to Container App

patch_client = PatchClient()
is_patch_deleted = patch_client.delete(cmd, resource_group_name, container_app_name, patch_name)
if is_patch_deleted:
print("Patch {0} for container app {1} is deleted successfully.".format(patch_name, container_app_name))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.warning instead of print

if app is None:
logger.error("Container app {0} not found in resource group {1}.".format(container_app_name, resource_group_name))
return
if format_location(app["location"]) != format_location("North Central US (Stage)"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use safe_get()

logger.error("Please provide the name of the patch to delete.")
return
try:
app = show_containerapp(cmd, container_app_name, resource_group_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could throw a not found exception if container app does not exist.

if app is None:
logger.error("Container app {0} not found in resource group {1}.".format(container_app_name, resource_group_name))
return
if format_location(app["location"]) != format_location("North Central US (Stage)"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use safe_get() to get app's location


helps["containerapp patch configure mode"] = """
type: command
short-summary: Configure the patching mode for a container app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container App instead of container app

@@ -847,6 +871,20 @@
az containerapp patch interactive -g MyResourceGroup --environment MyContainerAppEnv --show-all
"""

helps["containerapp patch configure"] = """
type: group
short-summary: Commands to configure the patching settings for a container app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace container app by Container App

@@ -827,6 +830,27 @@
- name: List patchable and unpatchable container apps by managed environment with the show-all option and apply patch for patchable container apps.
text: |
az containerapp patch apply -g MyResourceGroup --environment MyContainerAppEnv --show-all
- name: Apply a patch for a container app by patch name using Cloud Patching.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container App

@@ -809,6 +809,9 @@
- name: List patchable and unpatchable container apps by managed environment with the show-all option.
text: |
az containerapp patch list -g MyResourceGroup --environment MyContainerAppEnv --show-all
- name: List available patches for a container app.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Container App

Copy link

@MoazzemHossain-bot MoazzemHossain-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls do as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot ContainerApp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants