Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,10 @@
}
]
}
- name: Add default maintenance configuration with weekly maintenanceWindow schedule.
text: |
az aks maintenanceconfiguration add -g MyResourceGroup --cluster-name test1 -n default --schedule-type Weekly --day-of-week Monday --interval-weeks 1 --duration 4 --start-time 09:00
The maintenance is allowed on Monday from 09:00 to 13:00 in UTC every week using the maintenanceWindow format.
- name: Add aksManagedNodeOSUpgradeSchedule maintenance configuration with daily schedule.
text: |
az aks maintenanceconfiguration add -g MyResourceGroup --cluster-name test1 -n aksManagedNodeOSUpgradeSchedule --schedule-type Daily --interval-days 2 --duration 12 --utc-offset=-08:00 --start-date 2023-01-16 --start-time 00:00
Expand Down Expand Up @@ -1627,7 +1631,7 @@
short-summary: The start time of 1 hour window which maintenance is allowd. E.g. 1 means it's allowd between 1:00 am and 2:00 am. Applicable to default maintenance configuration only.
- name: --schedule-type
type: string
short-summary: Choose either 'Daily', 'Weekly', 'AbsoluteMonthly' or 'RelativeMonthly' for your maintenance schedule. Only applicable to 'aksManagedAutoUpgradeSchedule' and 'aksManagedNodeOSUpgradeSchedule' maintenance configuration.
short-summary: Choose either 'Daily', 'Weekly', 'AbsoluteMonthly' or 'RelativeMonthly' for your maintenance schedule. For default maintenance configuration, only 'Weekly' is supported.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Help text for --schedule-type is now inconsistent with --start-hour / --weekday help.

This line now says --schedule-type is supported for default config (Weekly only), but the help for --weekday and --start-hour (a few lines above, e.g. line 1626) still says Applicable to default maintenance configuration only. without mentioning that the maintenanceWindow path is now the preferred way to configure default. Consider a short note on those two flags pointing users to --schedule-type Weekly as the modern alternative — otherwise users hitting --help won't discover the new path.

- name: --start-date
type: string
short-summary: The date the maintenance configuration activates. If not specified, the maintenance window will be active right away."
Expand Down Expand Up @@ -1703,6 +1707,10 @@
}
]
}
- name: Update default maintenance configuration with weekly maintenanceWindow schedule.
text: |
az aks maintenanceconfiguration update -g MyResourceGroup --cluster-name test1 -n default --schedule-type Weekly --day-of-week Monday --interval-weeks 1 --duration 4 --start-time 09:00
The maintenance is allowed on Monday from 09:00 to 13:00 in UTC every week using the maintenanceWindow format.
- name: Update aksManagedNodeOSUpgradeSchedule maintenance configuration with daily schedule.
text: |
az aks maintenanceconfiguration update -g MyResourceGroup --cluster-name test1 -n aksManagedNodeOSUpgradeSchedule --schedule-type Daily --interval-days 2 --duration 12 --utc-offset=-08:00 --start-date 2023-01-16 --start-time 00:00
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ def load_arguments(self, _):
c.argument('weekday', help='Weekday on which maintenance can happen. e.g. Monday')
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')
c.argument('schedule_type', arg_type=get_enum_type(schedule_types),
help='Schedule type for non-default maintenance configuration.')
help='Schedule type for maintenance configuration. For default configuration, only Weekly is supported.')
c.argument('interval_days', type=int, help='The number of days between each set of occurrences for Daily schedule.')
c.argument('interval_weeks', type=int, help='The number of weeks between each set of occurrences for Weekly schedule.')
c.argument('interval_months', type=int, help='The number of months between each set of occurrences for AbsoluteMonthly or RelativeMonthly schedule.')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,26 @@ def constructDefaultMaintenanceConfiguration(cmd, raw_parameters):
start_hour = raw_parameters.get("start_hour")
schedule_type = raw_parameters.get("schedule_type")

if weekday is None or start_hour is None:
raise RequiredArgumentMissingError('Please specify --weekday and --start-hour for default maintenance configuration, or use --config-file instead.')
# If schedule_type is provided, use maintenanceWindow format for the default config
if schedule_type is not None:
raise MutuallyExclusiveArgumentError('--schedule-type is not supported for default maintenance configuration.')
if weekday is not None or start_hour is not None:
raise MutuallyExclusiveArgumentError('--weekday and --start-hour cannot be used together with --schedule-type for default maintenance configuration.')
if schedule_type != CONST_WEEKLY_MAINTENANCE_SCHEDULE:
raise InvalidArgumentValueError('--schedule-type for default maintenance configuration must be Weekly.')
interval_weeks = raw_parameters.get("interval_weeks")
if interval_weeks is not None and interval_weeks != 1:
raise InvalidArgumentValueError('--interval-weeks for default maintenance configuration must be 1.')
maintenance_configuration_models = AKSManagedClusterModels(cmd, ResourceType.MGMT_CONTAINERSERVICE).maintenance_configuration_models
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

interval_weeks=None slips past the default-config validation.

The current check only rejects interval_weeks != 1 when it is explicitly provided:

if interval_weeks is not None and interval_weeks != 1:
    raise InvalidArgumentValueError('--interval-weeks for default maintenance configuration must be 1.')

If a user runs az aks maintenanceconfiguration add ... -n default --schedule-type Weekly --day-of-week Monday --duration 4 --start-time 09:00 (omitting --interval-weeks), they fall through to constructWeeklySchedule, which then raises:
Please specify --interval-weeks and --day-of-week when using weekly schedule.

That's a confusing error for the default-config flow where the value is forced to 1 anyway. Suggest one of:

  • Default interval_weeks to 1 here when missing (raw_parameters["interval_weeks"] = 1) before calling constructMaintenanceWindow, so the user doesn't have to pass it; or
  • Make the message explicit: if interval_weeks != 1: raise InvalidArgumentValueError(...) so omission is also caught with the default-config-specific message.

The first option matches the RP contract better (only 1 is valid) and reduces friction.

Result = (
maintenance_configuration_models.MaintenanceConfiguration
)
result = Result()
Comment on lines +71 to +75
result.maintenance_window = constructMaintenanceWindow(cmd, raw_parameters)
return result
Comment on lines +62 to +77

# Legacy timeInWeek format
if weekday is None or start_hour is None:
raise RequiredArgumentMissingError('Please specify --weekday and --start-hour, or --schedule-type Weekly with --day-of-week, --start-time, and --duration for default maintenance configuration, or use --config-file instead.')

maintenance_configuration_models = AKSManagedClusterModels(cmd, ResourceType.MGMT_CONTAINERSERVICE).maintenance_configuration_models
TimeInWeek = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_add_maintenance_configuration_with_invalid_name(self):
aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_default_maintenance_configuration_with_schedule_type(self):
def test_add_default_maintenance_configuration_with_schedule_type_and_weekday(self):
cmd = SimpleNamespace()
raw_parameters = {
"resource_group_name": "test_rg",
Expand All @@ -45,10 +45,54 @@ def test_add_default_maintenance_configuration_with_schedule_type(self):
"schedule_type": "Weekly",
}

err = ("--schedule-type is not supported for default maintenance configuration.")
err = ("--weekday and --start-hour cannot be used together with --schedule-type for default maintenance configuration.")
with self.assertRaises(MutuallyExclusiveArgumentError) as cm:
aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_default_maintenance_configuration_with_invalid_schedule_type(self):
cmd = MockCmd(self.cli_ctx)
raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
"config_name": "default",
"weekday": None,
"start_hour": None,
"schedule_type": "Daily",
"interval_days": 3,
"interval_weeks": None,
"interval_months": None,
"day_of_week": None,
"day_of_month": None,
"week_index": None,
}

err = ("--schedule-type for default maintenance configuration must be Weekly.")
with self.assertRaises(InvalidArgumentValueError) as cm:
aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_default_maintenance_configuration_with_invalid_interval_weeks(self):
cmd = MockCmd(self.cli_ctx)
raw_parameters = {
"resource_group_name": "test_rg",
"cluster_name": "test_cluster",
"config_name": "default",
"weekday": None,
"start_hour": None,
"schedule_type": "Weekly",
"interval_days": None,
"interval_weeks": 3,
"interval_months": None,
"day_of_week": "Monday",
"day_of_month": None,
"week_index": None,
}

err = ("--interval-weeks for default maintenance configuration must be 1.")
with self.assertRaises(InvalidArgumentValueError) as cm:
aks_maintenanceconfiguration_update_internal(cmd, None, raw_parameters)
self.assertEqual(str(cm.exception), err)

def test_add_non_default_schedule_with_weekday(self):
cmd = SimpleNamespace()
Expand Down
Loading