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 7 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
6 changes: 6 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ 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 support the creation of dedicated maintenance configurations:
* *aksManagedAutoUpgradeSchedule* for scheduled cluster auto-upgrade
* *aksManagedNodeOSUpgradeSchedule* for scheduled node os auto-upgrade

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"
178 changes: 166 additions & 12 deletions src/aks-preview/azext_aks_preview/_help.py

Large diffs are not rendered by default.

54 changes: 48 additions & 6 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 @@ -564,12 +592,26 @@ def load_arguments(self, _):
with self.argument_context(scope) as c:
c.argument('config_name', options_list=[
'--name', '-n'], help='The config name.')
c.argument('config_file', options_list=[
'--config-file'], help='The config json file.', required=False)
c.argument('weekday', options_list=[
'--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('config_file', help='The config json file.', required=False)
c.argument('weekday', help='weekday on which maintenance can happen. e.g. Monday', required=False)
c.argument('start_hour', type=int, 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', arg_type=get_enum_type(schedule_types), required=False,
help='Schedule type for non-default maintenance configuration.')
c.argument('interval_days', type=int, help='The number of days between each set of occurrences for Daily schedule.', required=False)
c.argument('interval_weeks', type=int, help='The number of weeks between each set of occurrences for Weekly schedule.', required=False)
c.argument('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', help='Specifies on which day of the week the maintenance occurs for Weekly or RelativeMonthly schedule.', required=False)
c.argument('day_of_month', help='Specifies on which date of the month the maintenance occurs for AbsoluteMonthly schedule.', required=False)
c.argument('week_index', arg_type=get_enum_type(week_indexes), required=False,
help='Specifies on which instance of the weekday specified in --day-of-week the maintenance occurs for RelativeMonthly schedule.')
c.argument('duration_hours', options_list=['--duration'], type=int, required=False,
help='The length of maintenance window. The value ranges from 4 to 24 hours.')
c.argument('utc_offset', validator=validate_utc_offset, required=False,
help='The UTC offset in format +/-HH:mm. e.g. -08:00 or +05:30.')
c.argument('start_date', validator=validate_start_date, required=False,
help='The date the maintenance window activates. e.g. 2023-01-01.')
c.argument('start_time', validator=validate_start_time, required=False,
help='The start time of the maintenance window. e.g. 09:30.')

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