Skip to content
Merged
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
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,9 @@
- name: --max-surge
type: string
short-summary: Extra nodes used to speed upgrade. When specified, it represents the number or percent used, eg. 5 or 33%
- name: --max-unavailable
type: string
short-summary: The maximum number or percentage of nodes that can be simultaneously unavailable during upgrade. When specified, it represents the number or percent used, eg. 1 or 5%
- name: --drain-timeout
type: int
short-summary: When nodes are drain how many minutes to wait for all pods to be evicted
Expand Down Expand Up @@ -1790,6 +1793,9 @@
- name: --max-surge
type: string
short-summary: Extra nodes used to speed upgrade. When specified, it represents the number or percent used, eg. 5 or 33%
- name: --max-unavailable
type: string
short-summary: The maximum number or percentage of nodes that can be simultaneously unavailable during upgrade. When specified, it represents the number or percent used, eg. 1 or 5%
- name: --drain-timeout
type: int
short-summary: When nodes are drain how many minutes to wait for all pods to be evicted
Expand Down Expand Up @@ -1865,6 +1871,9 @@
- name: --max-surge
type: string
short-summary: Extra nodes used to speed upgrade. When specified, it represents the number or percent used, eg. 5 or 33% (mutually exclusive with "--node-image-only". See "az aks nodepool update --max-surge" to update max surge before upgrading with "--node-image-only")
- name: --max-unavailable
type: string
short-summary: The maximum number or percentage of nodes that can be simultaneously unavailable during upgrade. When specified, it represents the number or percent used, eg. 1 or 5%
- name: --drain-timeout
type: int
short-summary: When nodes are drain how long to wait for all pods to be evicted
Expand Down
5 changes: 4 additions & 1 deletion src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
validate_linux_host_name, validate_load_balancer_idle_timeout,
validate_load_balancer_outbound_ip_prefixes,
validate_load_balancer_outbound_ips, validate_load_balancer_outbound_ports,
validate_load_balancer_sku, validate_max_surge,
validate_load_balancer_sku, validate_max_surge, validate_max_unavailable,
validate_nat_gateway_idle_timeout,
validate_nat_gateway_managed_outbound_ip_count, validate_network_policy,
validate_nodepool_id, validate_nodepool_labels, validate_nodepool_name,
Expand Down Expand Up @@ -831,6 +831,7 @@ def load_arguments(self, _):
c.argument('node_osdisk_type', arg_type=get_enum_type(node_os_disk_types))
c.argument('node_osdisk_size', type=int)
c.argument('max_surge', validator=validate_max_surge)
c.argument("max_unavailable", validator=validate_max_unavailable)
c.argument('drain_timeout', type=int)
c.argument('node_soak_duration', type=int)
c.argument("undrainable_node_behavior", default='Schedule')
Expand Down Expand Up @@ -872,6 +873,7 @@ def load_arguments(self, _):
c.argument('tags', tags_type)
c.argument('node_taints', validator=validate_nodepool_taints)
c.argument('max_surge', validator=validate_max_surge)
c.argument("max_unavailable", validator=validate_max_unavailable)
c.argument('drain_timeout', type=int)
c.argument('node_soak_duration', type=int)
c.argument("undrainable_node_behavior")
Expand All @@ -891,6 +893,7 @@ def load_arguments(self, _):

with self.argument_context('aks nodepool upgrade') as c:
c.argument('max_surge', validator=validate_max_surge)
c.argument("max_unavailable", validator=validate_max_unavailable)
c.argument('drain_timeout', type=int)
c.argument('node_soak_duration', type=int)
c.argument("undrainable_node_behavior")
Expand Down
15 changes: 15 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,21 @@ def validate_max_surge(namespace):
raise CLIError("--max-surge should be an int or percentage")


def validate_max_unavailable(namespace):
"""validates parameters max unavailable are positive integers or percents."""
if namespace.max_unavailable is None:
return
int_or_percent = namespace.max_unavailable
if int_or_percent.endswith('%'):
int_or_percent = int_or_percent.rstrip('%')

try:
if int(int_or_percent) < 0:
raise InvalidArgumentValueError("--max-unavailable must be positive")
except ValueError:
raise InvalidArgumentValueError("--max-unavailable should be an int or percentage")


def validate_assign_identity(namespace):
if namespace.assign_identity is not None:
if namespace.assign_identity == '':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,25 @@ def get_max_surge(self):
# this parameter does not need validation
return max_surge

def get_max_unavailable(self):
"""Obtain the value of max_unavailable.
:return: string
"""
# read the original value passed by the command
max_unavailable = self.raw_param.get("max_unavailable")
# In create mode, try to read the property value corresponding to the parameter from the `agentpool` object
if self.decorator_mode == DecoratorMode.CREATE:
if (
self.agentpool and
self.agentpool.upgrade_settings and
self.agentpool.upgrade_settings.max_unavailable is not None
):
max_unavailable = self.agentpool.upgrade_settings.max_unavailable

# this parameter does not need dynamic completion
# this parameter does not need validation
return max_unavailable

def get_drain_timeout(self):
"""Obtain the value of drain_timeout.

Expand Down Expand Up @@ -1833,6 +1852,10 @@ def set_up_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:
if max_surge:
upgrade_settings.max_surge = max_surge

max_unavailable = self.context.get_max_unavailable()
if max_unavailable:
upgrade_settings.max_unavailable = max_unavailable

drain_timeout = self.context.get_drain_timeout()
if drain_timeout:
upgrade_settings.drain_timeout_in_minutes = drain_timeout
Expand Down Expand Up @@ -2224,6 +2247,10 @@ def update_upgrade_settings(self, agentpool: AgentPool) -> AgentPool:
# why not always set this? so we don't wipe out a preview feaure in upgrade settigns like NodeSoakDuration?
agentpool.upgrade_settings = upgrade_settings

max_unavailable = self.context.get_max_unavailable()
if max_unavailable:
upgrade_settings.max_unavailable = max_unavailable

drain_timeout = self.context.get_drain_timeout()
if drain_timeout:
upgrade_settings.drain_timeout_in_minutes = drain_timeout
Expand Down
10 changes: 7 additions & 3 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2408,6 +2408,7 @@ def aks_agentpool_add(
node_osdisk_type=None,
node_osdisk_size=None,
max_surge=None,
max_unavailable=None,
drain_timeout=None,
node_soak_duration=None,
undrainable_node_behavior=None,
Expand Down Expand Up @@ -2477,6 +2478,7 @@ def aks_agentpool_update(
tags=None,
node_taints=None,
max_surge=None,
max_unavailable=None,
drain_timeout=None,
node_soak_duration=None,
undrainable_node_behavior=None,
Expand Down Expand Up @@ -2530,6 +2532,7 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name,
kubernetes_version='',
node_image_only=False,
max_surge=None,
max_unavailable=None,
drain_timeout=None,
node_soak_duration=None,
undrainable_node_behavior=None,
Expand All @@ -2552,11 +2555,12 @@ def aks_agentpool_upgrade(cmd, client, resource_group_name, cluster_name,
)

# Note: we exclude this option because node image upgrade can't accept nodepool put fields like max surge
if (max_surge or drain_timeout or node_soak_duration or undrainable_node_behavior) and node_image_only:
hasUpgradeSetting = max_surge or drain_timeout or node_soak_duration or undrainable_node_behavior or max_unavailable
if hasUpgradeSetting and node_image_only:
raise MutuallyExclusiveArgumentError(
'Conflicting flags. Unable to specify max-surge/drain-timeout/node-soak-duration with node-image-only.'
'Conflicting flags. Unable to specify max-surge/drain-timeout/node-soak-duration/max-unavailable with node-image-only.'
'If you want to use max-surge/drain-timeout/node-soak-duration with a node image upgrade, please first '
'update max-surge/drain-timeout/node-soak-duration using "az aks nodepool update --max-surge/--drain-timeout/--node-soak-duration".'
'update max-surge/drain-timeout/node-soak-duration/max-unavailable using "az aks nodepool update --max-surge/--drain-timeout/--node-soak-duration/--max-unavailable".'
)

if node_image_only:
Expand Down
Loading