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
7 changes: 7 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 @@ -2456,6 +2456,11 @@
- name: --disable-artifact-streaming
type: bool
short-summary: Disable artifact streaming for VirtualMachineScaleSets managed by a Linux node pool.
- name: --node-vm-size -s
type: string
short-summary: Resize the VMs of a VirtualMachineScaleSets node pool.
long-summary: |
AKS replaces every node in the node pool with a node of the new size. It adds surge nodes of the new size, then cordons, drains and deletes the old nodes, following the node pool's upgrade settings (--max-surge, --max-unavailable, --drain-timeout, --node-soak-duration). The target size must be compatible with the current node pool configuration. Can be combined with --update-cluster-autoscaler, or with --enable-cluster-autoscaler/--disable-cluster-autoscaler when they change the autoscaler state. Not supported for VirtualMachines node pools; use "az aks nodepool manual-scale update" or "az aks nodepool auto-scale update" to change their VM sizes.
examples:
- name: Reconcile the nodepool back to its current state.
text: az aks nodepool update -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster
Expand All @@ -2470,6 +2475,8 @@
az aks nodepool update --resource-group MyResourceGroup \\
--cluster-name MyManagedCluster --name npwin \\
--os-sku Windows2025 --enable-fips-image
- name: Resize the VMs of a VirtualMachineScaleSets node pool to Standard_D4s_v5.
text: az aks nodepool update -g MyResourceGroup -n nodepool1 --cluster-name MyManagedCluster --node-vm-size Standard_D4s_v5
"""

helps["aks nodepool upgrade"] = """
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ def load_arguments(self, _):
c.argument('gpu_driver', arg_type=get_enum_type(gpu_driver_install_modes))
c.argument('enable_artifact_streaming', action='store_true', validator=validate_artifact_streaming)
c.argument('disable_artifact_streaming', action='store_true', validator=validate_artifact_streaming)
c.argument('node_vm_size', options_list=['--node-vm-size', '-s'])

with self.argument_context('aks nodepool upgrade') as c:
c.argument('max_surge', validator=validate_max_surge)
Expand Down
89 changes: 89 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/agentpool_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,52 @@ def get_yes(self) -> bool:
"""
return self.raw_param.get("yes")

def get_node_vm_size_for_update(self) -> Union[str, None]:
"""Obtain and validate the value of node_vm_size for `az aks nodepool update`.

An explicit empty value is rejected instead of being treated as omitted.

:return: string or None
"""
node_vm_size = self.raw_param.get("node_vm_size")
if node_vm_size is None:
return None
if not node_vm_size.strip():
raise InvalidArgumentValueError("--node-vm-size cannot be empty.")
return node_vm_size

def validate_node_vm_size_with_autoscaler_for_update(self) -> None:
"""Reject a resize combined with an autoscaler request that would exit early without updating.

Must be called with the fetched agentpool attached and before the autoscaler properties are updated, since
it compares the request with the node pool's current autoscaler state.

On a VirtualMachineScaleSets pool, --enable-cluster-autoscaler when the autoscaler is already enabled, or
--disable-cluster-autoscaler when it is already disabled, is a no-op that exits early, which would silently
drop --node-vm-size. Other combinations (e.g. resize with --update-cluster-autoscaler, or with an
enable/disable that changes the autoscaler state) are left untouched so existing callers, such as
aks-preview, keep working. VirtualMachines pools are handled by update_auto_scaler_properties_vms and
update_vm_size, which aks-preview overrides with its own VirtualMachines handling.
"""
if self.get_node_vm_size_for_update() is None:
return
if self.agentpool is None or self.get_vm_set_type() != CONST_VIRTUAL_MACHINE_SCALE_SETS:
return
autoscaler_enabled = bool(self.agentpool.enable_auto_scaling)
if self.raw_param.get("enable_cluster_autoscaler") and autoscaler_enabled:
raise MutuallyExclusiveArgumentError(
"Cluster autoscaler is already enabled for this node pool, so --enable-cluster-autoscaler "
"would skip the update and --node-vm-size would not be applied. "
"Remove --enable-cluster-autoscaler, or use --update-cluster-autoscaler to change "
"min-count or max-count."
)
if self.raw_param.get("disable_cluster_autoscaler") and not autoscaler_enabled:
raise MutuallyExclusiveArgumentError(
"Cluster autoscaler is already disabled for this node pool, so --disable-cluster-autoscaler "
"would skip the update and --node-vm-size would not be applied. "
"Remove --disable-cluster-autoscaler."
)


class AKSAgentPoolAddDecorator:
def __init__(
Expand Down Expand Up @@ -3030,6 +3076,44 @@ def update_ssh_access(self, agentpool: AgentPool) -> AgentPool:
agentpool.security_profile.ssh_access = ssh_access
return agentpool

def update_vm_size(self, agentpool: AgentPool) -> AgentPool:
"""Update the VM size of a VirtualMachineScaleSets based AgentPool object.

Changing the VM size triggers a rolling replacement: AKS surges nodes with the new size, then cordons,
drains and deletes the old nodes according to the node pool's upgrade settings.

VirtualMachines node pools manage VM sizes through their scale profiles, so --node-vm-size is rejected
for them instead of being silently ignored. Combinations with no-op autoscaler requests are rejected
earlier by AKSAgentPoolContext.validate_node_vm_size_with_autoscaler_for_update.

:return: the AgentPool object
"""
self._ensure_agentpool(agentpool)

node_vm_size = self.context.get_node_vm_size_for_update()
if node_vm_size is None:
return agentpool

if self.context.get_vm_set_type() == CONST_VIRTUAL_MACHINES:
raise InvalidArgumentValueError(
"--node-vm-size is not supported for VirtualMachines node pools. "
'Please use "az aks nodepool manual-scale update" or "az aks nodepool auto-scale update" '
"to change the VM size of a VirtualMachines node pool."
)

# already set to the same value, directly return
if agentpool.vm_size and agentpool.vm_size.lower() == node_vm_size.lower():
return agentpool

msg = (
f"You're going to resize agentpool {agentpool.name} from '{agentpool.vm_size}' to '{node_vm_size}'. "
"All nodes in the node pool will be replaced with nodes of the new size. Proceed?"
)
if not self.context.get_yes() and not prompt_y_n(msg, default="n"):
raise DecoratorEarlyExitException()
agentpool.vm_size = node_vm_size
return agentpool

def update_gpu_profile(self, agentpool: AgentPool) -> AgentPool:
self._ensure_agentpool(agentpool)

Expand Down Expand Up @@ -3069,6 +3153,9 @@ def update_agentpool_profile_default(self, agentpools: List[AgentPool] = None) -
"""
# fetch the Agentpool object
agentpool = self.fetch_agentpool(agentpools)
# reject a resize combined with a no-op autoscaler request, before update_auto_scaler_properties changes the
# autoscaler state or exits early (e.g. autoscaler already enabled) and drops the resize
self.context.validate_node_vm_size_with_autoscaler_for_update()
# update auto scaler properties
agentpool = self.update_auto_scaler_properties(agentpool)
# update auto scaler properties for vms pool
Expand All @@ -3091,6 +3178,8 @@ def update_agentpool_profile_default(self, agentpools: List[AgentPool] = None) -
agentpool = self.update_secure_boot(agentpool)
# update ssh access
agentpool = self.update_ssh_access(agentpool)
# update vm size
agentpool = self.update_vm_size(agentpool)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Combining --node-vm-size with an already-satisfied autoscaler flag returns success without resizing: the autoscaler step exits before the resize hook (reproduced: zero PUTs). Please continue the resize or reject the combination, and add handler-level tests for both autoscaler states.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

High Autoscaler no-op discards the resize

The new resize invocation is after update_auto_scaler_properties. For a VMSS pool with enable_auto_scaling false, a call accepting node_vm_size='Standard_D4s_v5', disable_cluster_autoscaler=True and yes=True takes custom.py:3675,3678,3683–3692 -> agentpool_decorator.py:3099,3110 -> 2739,2757 -> 951,1031–1035. DecoratorEarlyExitException is caught by custom.py:3693–3695, which returns before update_agentpool at 3697. Neither the size update nor the PUT occurs. The warning only says the autoscaler is already disabled. The equivalent already-enabled branch is agentpool_decorator.py:1016–1022 when enabling with valid min/max counts. This newly accepted resize input exposes the existing early-exit path.

Remediation: Preserve pending resize work when autoscaler state is already satisfied, or explicitly reject the combined request instead of returning success with only an autoscaler warning. Merely moving the resize mutation before the early exit would not ensure a PUT.

Focused verification: Add command-level mocked tests through aks_agentpool_update, using a D2s_v5 VMSS pool with autoscaling already disabled and a D4s_v5 resize plus --disable-cluster-autoscaler; also cover already-enabled with valid min/max counts. Assert a D4s_v5 request, or a clear unsupported-combination error and no request. Preserve deliberate resize-confirmation cancellation.

X Engineering Agent · Reviewer · React with +1 or -1 to train the reviewer

# update local DNS profile
agentpool = self.update_localdns_profile(agentpool)
# update gpu profile
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,7 @@ def aks_agentpool_update(
# ssh access
ssh_access=None,
yes=False,
node_vm_size=None,
):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down
Loading
Loading