Repository navigation
[AKS] az aks nodepool update: Add --node-vm-size to resize VirtualMachineScaleSets node pools
#34319
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
[AKS] az aks nodepool update: Add --node-vm-size to resize VirtualMachineScaleSets node pools
#34319
Changes from all commits
7dc9ebb
92bd394
019171c
e4d6d49
ce69ed1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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__( | ||
|
|
@@ -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) | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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.
|
||
| # update local DNS profile | ||
| agentpool = self.update_localdns_profile(agentpool) | ||
| # update gpu profile | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Combining
--node-vm-sizewith 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.