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

Update maintenanceconfiguration commands #5739

Merged
merged 12 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

0.5.123
+++++++
* Update command group `az aks maintenanceconfiguration` to enable the creation of *aksManagedAutoUpgradeSchedule* and *aksManagedNodeOSUpgradeSchedule*.
Copy link
Contributor

Choose a reason for hiding this comment

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

aksManagedAutoUpgradeSchedule and aksManagedNodeOSUpgradeSchedule

Could we describe these two features in detail in the history notes, otherwise their meaning is easily confusing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your feedback, I have updated the details!


0.5.122
+++++++
* Vendor new SDK and bump API version to 2022-11-02-preview.
Expand Down
16 changes: 16 additions & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,19 @@
'tEYNEGZaRElFU79WcEF0cH+ZW0+jJ95xE3thZffRz6QI6yF63m8aC9l9bbdJS2zg\n' \
'Yv8W+lCZi//ODeOBUugr++z9uj+vGk47JDSpV0n4JOun3ALUDJ0gqmcS\n' \
'-----END CERTIFICATE-----'

# consts for maintenance configuration schedule type
CONST_DAILY_MAINTENANCE_SCHEDULE = "Daily"
CONST_WEEKLY_MAINTENANCE_SCHEDULE = "Weekly"
CONST_ABSOLUTEMONTHLY_MAINTENANCE_SCHEDULE = "AbsoluteMonthly"
CONST_RELATIVEMONTHLY_MAINTENANCE_SCHEDULE = "RelativeMonthly"

CONST_WEEKINDEX_FIRST = "First"
CONST_WEEKINDEX_SECOND = "Second"
CONST_WEEKINDEX_THIRD = "Third"
CONST_WEEKINDEX_FOURTH = "Fourth"
CONST_WEEKINDEX_LAST = "Last"

CONST_DEFAULT_CONFIGURATION_NAME = "default"
CONST_AUTOUPGRADE_CONFIGURATION_NAME = "aksManagedAutoUpgradeSchedule"
CONST_NODEOSUPGRADE_CONFIGURATION_NAME = "aksManagedNodeOSUpgradeSchedule"
174 changes: 164 additions & 10 deletions src/aks-preview/azext_aks_preview/_help.py

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@
CONST_DISK_DRIVER_V2,
CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PUBLIC,
CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PRIVATE,
CONST_DAILY_MAINTENANCE_SCHEDULE,
CONST_WEEKLY_MAINTENANCE_SCHEDULE,
CONST_ABSOLUTEMONTHLY_MAINTENANCE_SCHEDULE,
CONST_RELATIVEMONTHLY_MAINTENANCE_SCHEDULE,
CONST_WEEKINDEX_FIRST,
CONST_WEEKINDEX_SECOND,
CONST_WEEKINDEX_THIRD,
CONST_WEEKINDEX_FOURTH,
CONST_WEEKINDEX_LAST,
)
from azext_aks_preview._validators import (
validate_acr,
Expand Down Expand Up @@ -133,6 +142,9 @@
validate_disable_windows_outbound_nat,
validate_allowed_host_ports,
validate_application_security_groups,
validate_utc_offset,
validate_start_date,
validate_start_time,
)

# candidates for enumeration
Expand Down Expand Up @@ -177,6 +189,22 @@
CONST_NONE_UPGRADE_CHANNEL,
]

# consts for maintenance configuration
schedule_types = [
CONST_DAILY_MAINTENANCE_SCHEDULE,
CONST_WEEKLY_MAINTENANCE_SCHEDULE,
CONST_ABSOLUTEMONTHLY_MAINTENANCE_SCHEDULE,
CONST_RELATIVEMONTHLY_MAINTENANCE_SCHEDULE,
]

week_indexes = [
CONST_WEEKINDEX_FIRST,
CONST_WEEKINDEX_SECOND,
CONST_WEEKINDEX_THIRD,
CONST_WEEKINDEX_FOURTH,
CONST_WEEKINDEX_LAST,
]

# consts for credential
credential_formats = [CONST_CREDENTIAL_FORMAT_AZURE, CONST_CREDENTIAL_FORMAT_EXEC]

Expand Down Expand Up @@ -570,6 +598,31 @@ def load_arguments(self, _):
'--weekday'], help='weekday on which maintenance can happen. e.g. Monday', required=False)
c.argument('start_hour', type=int, options_list=[
'--start-hour'], help='maintenance start hour of 1 hour window on the weekday. e.g. 1 means 1:00am - 2:00am', required=False)
c.argument('schedule_type', options_list=['--schedule-type'], arg_type=get_enum_type(schedule_types),
help='Schedule type for non-default maintenance configuration.', required=False)
c.argument('interval_days', options_list=['--interval-days'], type=int,
help='The number of days between each set of occurrences for Daily schedule.', required=False)
c.argument('interval_weeks', options_list=['--interval-weeks'], type=int,
help='The number of weeks between each set of occurrences for Weekly schedule.', required=False)
c.argument('interval_months', options_list=['--interval-months'], type=int,
help='The number of months between each set of occurrences for AbsoluteMonthly or RelativeMonthly schedule.', required=False)
c.argument('day_of_week', options_list=['--day-of-week'],
help='Specifies on which day of the week the maintenance occurs for Weekly or RelativeMonthly schedule.', required=False)
c.argument('day_of_month', options_list=['--day-of-month'],
help='Specifies on which date of the month the maintenance occurs for AbsoluteMonthly schedule.', required=False)
c.argument('week_index', options_list=['--week-index'],
arg_type=get_enum_type(week_indexes),
help='Specifies on which instance of the weekday specified in --day-of-week the maintenance occurs for RelativeMonthly schedule.', required=False)
c.argument('duration_hours', options_list=['--duration'], type=int,
help='The length of maintenance window. The value ranges from 4 to 24 hours.', required=False)
Copy link
Member

Choose a reason for hiding this comment

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

It seems that this is the only argument which has some difference between parameter and the option. Then you could omit the options_list for all other arguments.

Also you could omit required=False.

Copy link
Member

Choose a reason for hiding this comment

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

The fix (#5744) is merged. Please rebase from main then I would trigger (or you could rerun the previous one) a live test run for your newly added case. Previous one skipped the tests in aks-preview due to the breaking change in azure-cli/acs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @FumingZhang!

I have rebased to the main branch and re-runed the live test. I also removed all the options_list for all arguments except duration_hours. When I tried to remove required=False, CLI Linter gave me failure saying I'm missing required arguments in help file, so I left them there.

c.argument('utc_offset', options_list=[
'--utc-offset'], validator=validate_utc_offset, help='The UTC offset in format +/-HH:mm. e.g. -08:00 or +05:30.', required=False)
c.argument('start_date', options_list=[
'--start-date'], validator=validate_start_date,
help='The date the maintenance window activates. e.g. 2023-01-01.', required=False)
c.argument('start_time', options_list=['--start-time'],
validator=validate_start_time,
help='The start time of the maintenance window. e.g. 09:30.', required=False)

for scope in ['aks maintenanceconfiguration show', 'aks maintenanceconfiguration delete']:
with self.argument_context(scope) as c:
Expand Down
30 changes: 30 additions & 0 deletions src/aks-preview/azext_aks_preview/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,33 @@ def validate_application_security_groups(namespace):
for asg in asg_ids.split(","):
if not is_valid_resource_id(asg):
raise InvalidArgumentValueError(asg + " is not a valid Azure resource ID.")


def validate_utc_offset(namespace):
"""Validates --utc-offset for aks maintenanceconfiguration add/update commands."""
if namespace.utc_offset is None:
return
utc_offset_regex = re.compile(r'^[+-]\d{2}:\d{2}$')
found = utc_offset_regex.findall(namespace.utc_offset)
if not found:
raise InvalidArgumentValueError('--utc-offset must be in format: "+/-HH:mm". For example, "+05:30" and "-12:00".')


def validate_start_date(namespace):
"""Validates --start-date for aks maintenanceconfiguration add/update commands."""
if namespace.start_date is None:
return
start_dt_regex = re.compile(r'^\d{4}-\d{2}-\d{2}$')
found = start_dt_regex.findall(namespace.start_date)
if not found:
raise InvalidArgumentValueError('--start-date must be in format: "yyyy-MM-dd". For example, "2023-01-01".')


def validate_start_time(namespace):
"""Validates --start-time for aks maintenanceconfiguration add/update commands."""
if namespace.start_time is None:
return
start_time_regex = re.compile(r'^\d{2}:\d{2}$')
found = start_time_regex.findall(namespace.start_time)
if not found:
raise InvalidArgumentValueError('--start-time must be in format "HH:mm". For example, "09:30" and "17:00".')
35 changes: 30 additions & 5 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,27 @@ def aks_maintenanceconfiguration_add(
config_name,
config_file,
weekday,
start_hour
start_hour,
FumingZhang marked this conversation as resolved.
Show resolved Hide resolved
schedule_type,
interval_days,
interval_weeks,
interval_months,
day_of_week,
day_of_month,
week_index,
duration_hours,
utc_offset,
start_date,
start_time
):
configs = client.list_by_managed_cluster(resource_group_name, cluster_name)
for config in configs:
if config.name == config_name:
raise CLIError("Maintenance configuration '{}' already exists, please try a different name, "
"use 'aks maintenanceconfiguration list' to get current list of maitenance configurations".format(config_name))
return aks_maintenanceconfiguration_update_internal(cmd, client, resource_group_name, cluster_name, config_name, config_file, weekday, start_hour)
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
return aks_maintenanceconfiguration_update_internal(cmd, client, raw_parameters)


def aks_maintenanceconfiguration_update(
Expand All @@ -521,7 +534,18 @@ def aks_maintenanceconfiguration_update(
config_name,
config_file,
weekday,
start_hour
start_hour,
schedule_type,
interval_days,
interval_weeks,
interval_months,
day_of_week,
day_of_month,
week_index,
duration_hours,
utc_offset,
start_date,
start_time
):
configs = client.list_by_managed_cluster(resource_group_name, cluster_name)
found = False
Expand All @@ -532,8 +556,9 @@ def aks_maintenanceconfiguration_update(
if not found:
raise CLIError("Maintenance configuration '{}' doesn't exist."
"use 'aks maintenanceconfiguration list' to get current list of maitenance configurations".format(config_name))

return aks_maintenanceconfiguration_update_internal(cmd, client, resource_group_name, cluster_name, config_name, config_file, weekday, start_hour)
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
return aks_maintenanceconfiguration_update_internal(cmd, client, raw_parameters)


# pylint: disable=too-many-locals
Expand Down
Loading