-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add Maintenance Config Support #8190
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
HEADER_AZURE_ASYNC_OPERATION = "azure-asyncoperation" | ||
HEADER_LOCATION = "location" | ||
SESSION_RESOURCE = "https://dynamicsessions.io" | ||
MAINTENANCE_CONFIG_DEFAULT_NAME = "default" | ||
|
||
|
||
class GitHubActionPreviewClient(GitHubActionClient): | ||
|
@@ -1382,3 +1383,98 @@ def list(cls, cmd, resource_group_name, environment_name): | |
dotNet_component_list.append(component) | ||
|
||
return dotNet_component_list | ||
|
||
|
||
class MaintenanceConfigPreviewClient(): | ||
api_version = "2024-10-02-preview" | ||
maintenance_config_name = MAINTENANCE_CONFIG_DEFAULT_NAME | ||
|
||
@classmethod | ||
def show(cls, cmd, resource_group_name, environment_name): | ||
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
sub_id = get_subscription_id(cmd.cli_ctx) | ||
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/microsoft.app/managedenvironments/{}/maintenanceConfigurations/{}?api-version={}" | ||
request_url = url_fmt.format( | ||
management_hostname.strip('/'), | ||
sub_id, | ||
resource_group_name, | ||
environment_name, | ||
cls.maintenance_config_name, | ||
cls.api_version) | ||
|
||
r = send_raw_request(cmd.cli_ctx, "GET", request_url) | ||
|
||
return r.json() | ||
|
||
@classmethod | ||
def add(cls, cmd, resource_group_name, environment_name, maintenance_config_envelope, no_wait=False): | ||
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
sub_id = get_subscription_id(cmd.cli_ctx) | ||
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/microsoft.app/managedenvironments/{}/maintenanceConfigurations/{}?api-version={}" | ||
request_url = url_fmt.format( | ||
management_hostname.strip('/'), | ||
sub_id, | ||
resource_group_name, | ||
environment_name, | ||
cls.maintenance_config_name, | ||
cls.api_version) | ||
|
||
r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(maintenance_config_envelope)) | ||
|
||
if no_wait: | ||
return r.json() | ||
elif r.status_code == 201: | ||
operation_url = r.headers.get(HEADER_AZURE_ASYNC_OPERATION) | ||
poll_status(cmd, operation_url) | ||
r = send_raw_request(cmd.cli_ctx, "GET", request_url) | ||
|
||
return r.json() | ||
|
||
@classmethod | ||
def update(cls, cmd, resource_group_name, environment_name, maintenance_config_envelope, no_wait=False): | ||
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
sub_id = get_subscription_id(cmd.cli_ctx) | ||
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/microsoft.app/managedenvironments/{}/maintenanceConfigurations/{}?api-version={}" | ||
request_url = url_fmt.format( | ||
management_hostname.strip('/'), | ||
sub_id, | ||
resource_group_name, | ||
environment_name, | ||
cls.maintenance_config_name, | ||
cls.api_version) | ||
|
||
r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(maintenance_config_envelope)) | ||
|
||
if no_wait: | ||
return | ||
elif r.status_code == 202: | ||
operation_url = r.headers.get(HEADER_LOCATION) | ||
response = poll_results(cmd, operation_url) | ||
if response is None: | ||
raise ResourceNotFoundError("Could not find the maintenance config") | ||
else: | ||
return response | ||
|
||
return r.json() | ||
|
||
@classmethod | ||
def delete(cls, cmd, resource_group_name, environment_name, no_wait=False): | ||
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager | ||
sub_id = get_subscription_id(cmd.cli_ctx) | ||
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/microsoft.app/managedenvironments/{}/maintenanceConfigurations/{}?api-version={}" | ||
request_url = url_fmt.format( | ||
management_hostname.strip('/'), | ||
sub_id, | ||
resource_group_name, | ||
environment_name, | ||
cls.maintenance_config_name, | ||
cls.api_version) | ||
|
||
r = send_raw_request(cmd.cli_ctx, "DELETE", request_url) | ||
|
||
if no_wait: | ||
return # API doesn't return JSON (it returns no content) | ||
elif r.status_code in [200, 201, 202, 204]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 201 polling is not handled and also invalid for delete operations. Refer https://github.com/cloud-and-ai-microsoft/resource-provider-contract/blob/master/v1.0/async-api-reference.md#delete-resource-asynchronously For this api, we only return 200. Still future proofing is good. |
||
if r.status_code == 202: | ||
operation_url = r.headers.get(HEADER_LOCATION) | ||
poll_results(cmd, operation_url) |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2131,3 +2131,42 @@ | |||||
az containerapp job registry set -n my-containerapp-job -g MyResourceGroup \\ | ||||||
--server MyContainerappJobRegistry.azurecr.io --identity system-environment | ||||||
""" | ||||||
|
||||||
# Maintenance Config Commands | ||||||
helps['containerapp env maintenanceconfig add'] = """ | ||||||
type: command | ||||||
short-summary: Add a Maintenance Configuration to a Container App Environment | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May need to update description based PM final decision. Example:
Suggested change
|
||||||
examples: | ||||||
- name: Configure an Env to use a maintenance config | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: To have full name for descriptions. PM can contribute here
Suggested change
|
||||||
text: | | ||||||
az containerapp env maintenanceconfig add --env-name myEnv -g MyResourceGroup \\ | ||||||
--duration 10 --start-hour-utc 11 --weekday Sunday | ||||||
""" | ||||||
|
||||||
helps['containerapp env maintenanceconfig update'] = """ | ||||||
type: command | ||||||
short-summary: Update a Maintenance Configuration in a Container App Environment | ||||||
examples: | ||||||
- name: Configure an Env to use a maintenance config | ||||||
text: | | ||||||
az containerapp env maintenanceconfig update --env-name myEnv -g MyResourceGroup \\ | ||||||
--duration 8 --start-hour-utc 12 --weekday Thursday | ||||||
""" | ||||||
|
||||||
helps['containerapp env maintenanceconfig show'] = """ | ||||||
type: command | ||||||
short-summary: Show a Maintenance Configuration in a Container App Environment | ||||||
examples: | ||||||
- name: Show a maintenance config | ||||||
text: | | ||||||
az containerapp env maintenanceconfig show --env-name myEnv -g MyResourceGroup | ||||||
""" | ||||||
|
||||||
helps['containerapp env maintenanceconfig delete'] = """ | ||||||
type: command | ||||||
short-summary: Delete a Maintenance Configuration in a Container App Environment | ||||||
examples: | ||||||
- name: Delete a Maintenance Config | ||||||
text: | | ||||||
az containerapp env maintenanceconfig add --env-name myEnv -g MyResourceGroup | ||||||
""" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -370,6 +370,16 @@ def load_arguments(self, _): | |||||
c.argument('max_replicas', type=int, help="Maximum number of replicas to run for the Java component.") | ||||||
c.argument('route_yaml', options_list=['--route-yaml', '--yaml'], help="Path to a .yaml file with the configuration of a Spring Cloud Gateway route. For an example, see https://aka.ms/gateway-for-spring-routes-yaml") | ||||||
|
||||||
with self.argument_context('containerapp env maintenanceconfig add') as c: | ||||||
c.argument('weekday', options_list=['--weekday', '-w'], help="The weekday to schedule the maintenance configuration.") | ||||||
p-bouchon marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
c.argument('start_hour_utc', options_list=['--start-hour-utc', '-s'], help="The hour to start the maintenance configuration.") | ||||||
c.argument('duration', options_list=['--duration', '-d'], help="The duration in hours of the maintenance configuration.") | ||||||
|
||||||
with self.argument_context('containerapp env maintenanceconfig update') as c: | ||||||
c.argument('weekday', options_list=['--weekday', '-w'], help="The weekday to schedule the maintenance configuration.") | ||||||
c.argument('start_hour_utc', options_list=['--start-hour-utc', '-s'], help="The hour to start the maintenance configuration.") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
c.argument('duration', options_list=['--duration', '-d'], help="The duration in hours of the maintenance configuration.") | ||||||
p-bouchon marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since, you have it in validation
Suggested change
|
||||||
|
||||||
with self.argument_context('containerapp job logs show') as c: | ||||||
c.argument('follow', help="Print logs in real time if present.", arg_type=get_three_state_flag()) | ||||||
c.argument('tail', help="The number of past logs to print (0-300)", type=int, default=20) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
# pylint: disable=line-too-long, broad-except, logging-format-interpolation | ||
|
||
|
||
from knack.log import get_logger | ||
from typing import Any, Dict | ||
|
||
from azure.cli.core.commands import AzCliCommand | ||
from azure.cli.command_modules.containerapp.base_resource import BaseResource | ||
|
||
from ._models import MaintenanceConfiguration as MaintenanceConfigurationModel | ||
from ._client_factory import handle_raw_exception | ||
|
||
logger = get_logger(__name__) | ||
|
||
|
||
class MaintenanceConfigDecorator(BaseResource): | ||
def __init__(self, cmd: AzCliCommand, client: Any, raw_parameters: Dict, models: str): | ||
super().__init__(cmd, client, raw_parameters, models) | ||
self.maintenance_config_def = MaintenanceConfigurationModel | ||
p-bouchon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def get_argument_environment_name(self): | ||
return self.get_param('env_name') | ||
|
||
def get_argument_resource_group_name(self): | ||
return self.get_param('resource_group_name') | ||
|
||
def get_argument_weekday(self): | ||
return self.get_param('weekday') | ||
|
||
def get_argument_start_hour_utc(self): | ||
return self.get_param('start_hour_utc') | ||
|
||
def get_argument_duration(self): | ||
return self.get_param('duration') | ||
|
||
|
||
class MaintenanceConfigPreviewDecorator(MaintenanceConfigDecorator): | ||
def construct_payload(self): | ||
self.maintenance_config_def["properties"]["scheduledEntries"][0]["startHourUtc"] = self.get_argument_start_hour_utc() | ||
self.maintenance_config_def["properties"]["scheduledEntries"][0]["durationHours"] = self.get_argument_duration() | ||
self.maintenance_config_def["properties"]["scheduledEntries"][0]["weekDay"] = self.get_argument_weekday() | ||
p-bouchon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def add(self): | ||
try: | ||
return self.client.add( | ||
cmd=self.cmd, | ||
resource_group_name=self.get_argument_resource_group_name(), | ||
environment_name=self.get_argument_environment_name(), | ||
maintenance_config_envelope=self.maintenance_config_def, | ||
no_wait=self.get_argument_no_wait()) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
def update(self): | ||
try: | ||
return self.client.update( | ||
cmd=self.cmd, | ||
resource_group_name=self.get_argument_resource_group_name(), | ||
environment_name=self.get_argument_environment_name(), | ||
maintenance_config_envelope=self.maintenance_config_def, | ||
no_wait=self.get_argument_no_wait()) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
def delete(self): | ||
try: | ||
return self.client.delete( | ||
cmd=self.cmd, | ||
resource_group_name=self.get_argument_resource_group_name(), | ||
environment_name=self.get_argument_environment_name(), | ||
no_wait=self.get_argument_no_wait()) | ||
except Exception as e: | ||
handle_raw_exception(e) | ||
|
||
def show(self): | ||
try: | ||
return self.client.show( | ||
cmd=self.cmd, | ||
resource_group_name=self.get_argument_resource_group_name(), | ||
environment_name=self.get_argument_environment_name()) | ||
except Exception as e: | ||
handle_raw_exception(e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JFYI - There is no impact.
PUT
for this resource only returns 200. Refer https://dev.azure.com/msazure/One/_git/AAPT-Antares-Containerapps?path=/src/Microsoft.ContainerApps/Microsoft.ContainerApps.WebApi/Controllers/Version20241002preview/MaintenanceConfigurationApiController.cs&version=GBmain&line=77&lineEnd=77&lineStartColumn=132&lineEndColumn=143&lineStyle=plain&_a=contents