Skip to content

[AKS] az aks nodepool update: Add --node-vm-size to resize VirtualMachineScaleSets node pools - #34319

Merged
mansoor sarfraz (msarfraz) merged 5 commits into
Azure:devfrom
wenhug:wenhuang/aks-nodepool-update-vm-size
Nov 9, 2026
Merged

mansoor sarfraz (msarfraz) merged 5 commits into
Azure:devfrom
wenhug:wenhuang/aks-nodepool-update-vm-size

Conversation

@wenhug

@wenhug Alex Huang (wenhug) commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Tests Suppressions
⚠️ None ️✔️ 130/130 ⚠️ 1 added
⚠️AzureCLI-BreakingChangeTest
⚠️acs
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd aks nodepool update cmd aks nodepool update added parameter node_vm_size

This PR adds warning or check suppressions. Fix the underlying warning where possible and justify each remaining suppression in a code comment or the PR description.

1 added suppression
File Line Kind Code
src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_aks_commands.py 17473 pylint except Exception as ex: # pylint: disable=broad-except

Related command
az aks nodepool update

Description
AKS can now resize an existing VirtualMachineScaleSets node pool in place. When a node pool PUT changes vmSize, AKS adds surge nodes of the new size, then cordons, drains and deletes the old nodes, following the node pool's upgrade settings. The service accepts this through stable API versions. This PR adds the option to core az aks nodepool update. It is already available in aks-preview (Azure/azure-cli-extensions#9732).

Changes:

  • Add --node-vm-size/-s to az aks nodepool update.
  • Add AKSAgentPoolUpdateDecorator.update_vm_size and call it from update_agentpool_profile_default:
    • VMSS pools: set vm_size to the requested size. Replacing every node is disruptive, so the command asks for confirmation unless --yes is passed (same pattern as --ssh-access). If the requested size already matches the current size (case-insensitive), nothing changes and there is no prompt.
    • VirtualMachines pools: VM sizes are managed through scale profiles, so --node-vm-size fails with an InvalidArgumentValueError that points to az aks nodepool manual-scale update / auto-scale update.
    • Autoscaler flags: --node-vm-size can be combined with --update-cluster-autoscaler, and with --enable/--disable-cluster-autoscaler when they change the autoscaler state; one PUT carries both changes, as in 2.92.0. The only rejected cases (MutuallyExclusiveArgumentError) are --enable-cluster-autoscaler when the autoscaler is already enabled and --disable-cluster-autoscaler when it is already disabled. Those requests exit early, which would otherwise drop the resize. The check runs in update_agentpool_profile_default after the pool is fetched and before the autoscaler properties are updated.
    • An explicit empty --node-vm-size "" is rejected instead of being treated as omitted.
  • Help text and an example.

az aks update (managed cluster mode) does not take --node-vm-size, so it is unaffected.

Testing Guide

az aks nodepool update -g MyResourceGroup --cluster-name MyManagedCluster -n nodepool1 --node-vm-size Standard_D4s_v5
  • Unit tests: test_update_vm_size runs in both standalone and managed-cluster decorator modes. It covers setting a new size with --yes, no-op when the flag is not passed, no-op for the same size, prompt accepted, prompt rejected, VirtualMachines pools, empty values, and the autoscaler check (rejects only the two no-op cases; --update-cluster-autoscaler and state-changing enable/disable are allowed).
  • Full-command test test_aks_agentpool_update_vm_size goes through aks_agentpool_update and checks the outgoing PUT: resize alone; resize + --update-cluster-autoscaler, + --enable (off→on), + --disable (on→off) each send one PUT with the new size and the expected autoscaler settings; --enable when already on and --disable when already off raise before any PUT; an empty value raises before any PUT; omitting the flag keeps the existing size. Removing the up-front check makes the two no-op cases fail.
  • aks-preview compatibility (reviewer request): ran the same aks nodepool update cases through aks-preview's update_agentpool_profile_preview (latest main, 17c8c64) against core 2.92.0 and against this PR. Results are identical except three intended changes: VMSS resize with a no-op --enable/--disable-cluster-autoscaler now errors instead of silently exiting without a PUT, and --node-vm-size "" now errors instead of sending the unchanged size. VMSS resize + --update-cluster-autoscaler, resize + state-changing enable/disable, and the VirtualMachines-pool cases (including the aks-preview help example) all behave the same as 2.92.0.
  • test_agentpool_decorator.py, test_managed_cluster_decorator.py, test_custom.py, test_validators.py, test_helpers.py: 1007 passed, 1 skipped.
  • Live-only scenario test_aks_nodepool_update_vm_size: create a cluster, add a D2s_v5 VMSS pool, resize it to D4s_v5. Passed live on e4d6d49 (westus2, 12 min) using stable API 2026-08-01, with no extensions loaded, no AKS preview feature registration for resize on the subscription, and no toggle overrides. It ran on an AKS dev subscription, not the default CLI test subscription, which I don't have write access to. Right after a node pool is added, AKS can still be running cluster-level operations (addon reconciliation) that reject a new PUT with OperationNotAllowed/EtagMismatch, so the test waits for the pool to reach Succeeded and retries the resize on those two errors. It stays live-only: playback would not exercise the rolling node replacement, so no recording is committed.
  • Manual check on a separate cluster: after the resize, the node pool's VMSS SKU was Standard_D4s_v5, and its only instance was a new VM of that size (the original D2s_v5 instance was gone), so the nodes were replaced rather than the field just being updated.
  • flake8 and pylint on the changed files are clean.

History Notes
[AKS] az aks nodepool update: Add --node-vm-size to resize VirtualMachineScaleSets node pools


This checklist is used to make sure that common guidelines for a pull request are followed.

🤖 Generated with Claude Code

…lMachineScaleSets node pools

Changing the VM size of a VMSS node pool makes AKS replace every node with a
node of the new size, using the node pool's surge and drain settings. The
command asks for confirmation unless --yes is passed, and does nothing when
the requested size matches the current size.

VirtualMachines node pools still change sizes through
`az aks nodepool manual-scale/auto-scale update`. On those pools,
--node-vm-size is accepted only together with --enable-cluster-autoscaler or
--disable-cluster-autoscaler, matching the existing behavior.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 19:18
@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label Nov 2, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution Alex Huang (@wenhug)! We will review the pull request and get back to you soon.

Copilot AI left a comment

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.

🟡 Changes recommended

During autoscaler transitions for VirtualMachines pools with populated scale profiles, --node-vm-size is silently ignored, allowing the command to succeed without applying the requested resize.

1 open issue
What changed in this PR

Adds VM-size changes to core az aks nodepool update, enabling rolling replacement of nodes in existing VirtualMachineScaleSets pools.

Changes:

  • Exposes --node-vm-size / -s with confirmation for size changes and case-insensitive no-op handling.
  • Adds VirtualMachines pool validation, help text, and a resize example.
  • Adds unit coverage in both decorator modes and a live-only resize scenario that has not yet been run.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​acs/​tests/​latest/​test_aks_commands.py Adds a live-only VMSS resize scenario.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​tests/​latest/​test_agentpool_decorator.py Tests resizing, confirmation, no-ops, and VirtualMachines handling.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​custom.py Accepts the VM-size argument in the update handler.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​agentpool_decorator.py Implements size updates, confirmation, and pool-type validation.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​_params.py Registers --node-vm-size and -s.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​_help.py Documents resize behavior and adds an example.

Review effort: Balanced

Comment on lines +3051 to +3054
if not (
self.context.raw_param.get("enable_cluster_autoscaler") or
self.context.raw_param.get("disable_cluster_autoscaler")
):
…peration conflicts

Right after a node pool is added, AKS can report it as Updating and still run
cluster-level operations (e.g. addon reconciliation) that reject a new PUT with
OperationNotAllowed or EtagMismatch. Wait for the pool to reach Succeeded,
retry the resize on those conflicts, and verify the final state with
`aks nodepool show`.

Co-Authored-By: Claude <noreply@anthropic.com>
@yonzhan

Copy link
Copy Markdown
Collaborator

Please fix CI issues

@yonzhan
Yong Zhang (yonzhan) requested a review from a team November 2, 2026 22:18
…utoscaler transitions

When `--enable/--disable-cluster-autoscaler` converts an existing
VirtualMachines scale profile, the new profile copies the existing sizes, so a
requested `--node-vm-size` was silently ignored. Reject the option for
VirtualMachines node pools in all cases and point to
`az aks nodepool manual-scale/auto-scale update` instead.

Co-Authored-By: Claude <noreply@anthropic.com>
@FumingZhang

Copy link
Copy Markdown
Member

Please provide the live-test result and tested SHA, and confirm stable-API resizing works in the default test subscription without preview registration or rollout overrides. The recording alone does not establish flag-free GA availability.

# 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.

@naga-nandyala Naga Nandyala (naga-nandyala) added the Request X Engineering Agent Ask the agent to triage this issue or review this PR label Nov 3, 2026
@x-engineering-agent

x-engineering-agent Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

X Engineering Agent Pull request review: Comments

Alex Huang (@wenhug) One confirmed command-behavior defect requires correction; resize regression coverage remains unverified.

Check Status Detail
Upstream CI Passed Upstream CI passed: 52 checks.
Agent live tests Not run This is a review-only PR.
Regression coverage Unverified For acs: 2 focused test file(s) changed.
Findings 1 high findings 1 medium findings 1 high, 1 medium
Risk Risk 30/100 Medium Medium; owner review recommended

To address

Tick each item as you address it.

  • High VirtualMachines autoscaler no-ops bypass resize rejection

    Details and fix

    The new VMSS-only guard returns for VirtualMachines pools. On a manually scaled VirtualMachines pool, az aks nodepool update ... --node-vm-size Standard_D4s_v5 --disable-cluster-autoscaler --yes then exits successfully without applying the size or reporting that resizing this pool type is unsupported.

    Trace: agentpool_decorator.py:3158 calls update_auto_scaler_properties_vms:3162; its context getter at 2837 raises DecoratorEarlyExitException at 1135-1139, caught by custom.py:3693-3695. Execution never reaches the new rejection at agentpool_decorator.py:3097-3102. The already-enabled autoscaler case also exits early at 1125-1132 when valid min/max counts are supplied. The warning describes only autoscaler state, not the discarded resize.

    Remediation: Reject unsupported VirtualMachines resize requests on the core command path before either autoscaler early exit, preserving extension-specific overrides.

    Verify: Extend src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_agentpool_decorator.py::AKSAgentPoolUpdateDecoratorStandaloneModeTestCase.test_aks_agentpool_update_vm_size with both no-op states through the complete command entry point; assert InvalidArgumentValueError and no SDK submission. Rerun azdev test test_aks_agentpool_update_vm_size.

  • Medium Test semantic-strength reviewer

    Details and fix

    src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_agentpool_decorator.py:4024: New scenario test has no recording in this PR: test_update_vm_size, test_aks_agentpool_update_vm_size, test_update_vm_size.

    Remediation: Run the test live and commit its recording, or mark it live only when it cannot be replayed.

    Verify: Confirm the test passes in playback mode from the committed recording.

    Recording scope clarification: The named decorator tests are unittest.TestCase tests and do not themselves need recordings. The service scenario is test_aks_commands.py:17434-17481, AzureKubernetesServiceScenarioTest.test_aks_nodepool_update_vm_size. It creates a pool at Standard_D2s_v5, requests Standard_D4s_v5, and asserts the update response and final vmSize/provisioningState. These are meaningful assertions, but @live_only() excludes playback and current evidence does not establish a successful run.

    The changed request carries AgentPool.vm_size into begin_create_or_update; service responses must return the requested vmSize and eventually Succeeded. No API version or output schema changes here. Mocked submission assertions at test_agentpool_decorator.py:4519,4533-4534 verify client mapping, not the service resize or SDK round trip.

    Before merge, obtain exact-head live evidence with azdev test test_aks_nodepool_update_vm_size --live. For replayable protection, remove the live-only restriction and record src/azure-cli/azure/cli/command_modules/acs/tests/latest/recordings/test_aks_nodepool_update_vm_size.yaml (absent at this head); verify its resize PUT and response fields, then rerun azdev test test_aks_nodepool_update_vm_size in playback. Otherwise document why replay is unsuitable and provide exact-head live results. This clarifies the recording finding, not an additional finding.

Review details

Upstream CI

Upstream CI passed: 52 checks. Regression coverage for the required resize scenario remains unverified.

Test validation

  • Agent live test: Not run; this is a review-only PR. Check author-provided test evidence and upstream CI separately.
  • Regression coverage: For acs: 2 focused test file(s) changed. Scenario coverage is unverified; review the issue's required conditions, test setup, and assertions before approval. Changed tests invoke az aks nodepool update, but invocation alone does not verify the required scenario or output. No linked issue was found in the PR timeline; inspect the source issue and its required scenario manually.

Risk assessment

30/100 · Medium

The Medium rating is driven by public CLI behavior, failure-handling behavior.

  • Change scope: 6 changed files, 388 changed lines (+388 / -0), including 4 production files.
  • Affected components: acs
  • Risk drivers: public CLI behavior (+18); failure-handling behavior (+12)
  • Regression evidence: Changed regression tests are included, reducing risk.
  • Confidence: High because changed-line patches were available for every production file.
  • Required review: Owning-squad review is recommended for acs before merge.

Ask the Agent

Tick a box to queue an action. Requires write access to this repository.

  • Re-review this PR
  • Run Agent live tests on this PR

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

@x-engineering-agent x-engineering-agent Bot left a comment

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.

Review comments are inline on the changed lines. See the X Engineering Agent Report.

# update ssh access
agentpool = self.update_ssh_access(agentpool)
# update vm size
agentpool = self.update_vm_size(agentpool)

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

self._ensure_agentpool(agentpool)

node_vm_size = self.context.raw_param.get("node_vm_size")
if not node_vm_size:

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 Empty size is silently ignored

_params.py:1377 registers --node-vm-size/-s without a nonempty validator. custom.py:3675–3686 carries it into raw parameters; agentpool_decorator.py:2690–2695 wraps them without coercion, and base_decorator.py:100–105 preserves ''. The new if not node_vm_size at agentpool_decorator.py:3047–3048 returns the old pool for an explicit empty string, before either the unsupported-pool rejection at 3050 or assignment at 3067. custom.py:3697 then submits the pool through agentpool_decorator.py:3163–3171 with the previous VM size. The new unit test only covers None, not ''.

Remediation: Use a None-only omission check and explicitly reject empty VM-size strings with InvalidArgumentValueError before request submission.

Focused verification: Cover omitted/None, empty string, and a valid size through the command/update controller. Empty input must fail on both VMSS and VirtualMachines pools with no PUT; None must preserve the pool and valid sizes must still map to properties.vmSize.

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

],
)

@live_only()

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.

Medium Recorded scenario is excluded from playback

The new scenario is decorated with @live_only() at line 17434. The import at line 38 resolves through testsdk/init.py:6 and scenario_tests/init.py:15 to scenario_tests/decorators.py:13–16, which applies unittest.skipUnless(ENV_LIVE_TEST). Thus normal playback skips all newly added request/output checks despite the accompanying 2176-line recording. The source has meaningful size/state assertions at 17459,17471,17480–17481, but the recording is not consumed by this decorated scenario in playback.

Remediation: Make the recorded resize scenario playback-eligible, or add a separate playback scenario retaining the same request and final-state assertions; address any actual replay incompatibility rather than leaving the recording unexercised.

Focused verification: After enabling playback coverage, run test_aks_nodepool_update_vm_size in normal playback and confirm it is not skipped. Confirm a regression that leaves either the outgoing or returned vmSize at Standard_D2s_v5 fails the focused scenario. Any live re-recording remains a separately authorized author action.

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

@x-engineering-agent x-engineering-agent Bot added the X Engineering Agent Reviewed Agent reviewed this PR label Nov 3, 2026
…ect empty values

- Reject `--node-vm-size` combined with --enable/--disable/--update-cluster-autoscaler.
  When the autoscaler was already in the requested state, the command exited early
  with only an autoscaler warning and the resize was never sent.
- Reject an explicit empty `--node-vm-size`, which was silently treated as omitted.
- Validate up front in update_agentpool_profile_default, before any step that can exit
  early, and add full-command tests through aks_agentpool_update.
- Remove the accidentally committed live recording; the scenario stays live-only.

Co-Authored-By: Claude <noreply@anthropic.com>
@wenhug

Copy link
Copy Markdown
Contributor Author

Thanks for checking. Live result: test_aks_nodepool_update_vm_size passed on e4d6d49 (current head) in westus2, 12 min. Create a cluster → add a D2s_v5 VMSS pool → az aks nodepool update --node-vm-size Standard_D4s_v5 --yes → pool is Succeeded with vmSize D4s_v5. Requests used the stable API 2026-08-01. The subscription has no AKS resize preview feature registered, no extensions were loaded, and no toggles were overridden; the RP resize toggles default to on. Separately, I checked a resized pool: the VMSS SKU changed and the only instance was a new VM of the target size.

One caveat: I ran it on an AKS dev subscription, not the default CLI test subscription, because I don't have write access there. The committed recording was removed. It was added by mistake, and playback wouldn't exercise the rolling replacement, so the scenario stays live-only. Happy to have it run in your live pipeline if that helps.

@wenhug

Copy link
Copy Markdown
Contributor Author

Addressed in e4d6d49:

  1. Autoscaler no-op discarding the resize: --node-vm-size is now rejected with --enable/--disable/--update-cluster-autoscaler, validated at the start of update_agentpool_profile_default before any early exit. A full-command test through aks_agentpool_update covers both already-satisfied autoscaler states and asserts no PUT is sent. Removing the up-front check makes it fail.
  2. Empty size: --node-vm-size "" now raises InvalidArgumentValueError on both VMSS and VirtualMachines pools, before any PUT.
  3. Playback: the recording was committed by mistake and has been removed. The scenario is intentionally live-only, since playback can't exercise the rolling node replacement. Live result is in the PR description.

@yonzhan

Copy link
Copy Markdown
Collaborator

Adding mansoor sarfraz (@msarfraz) to help review

# fetch the Agentpool object
agentpool = self.fetch_agentpool(agentpools)
# validate --node-vm-size before any step that may exit early (e.g. autoscaler already enabled)
self.context.get_node_vm_size_for_update()

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.

Please ensure the new core behavior preserves existing aks-preview usage. I locally reproduced a VMSS resize + --update-cluster-autoscaler request reaching PUT with the previous head, but failing with MutuallyExclusiveArgumentError here. Please address this in core or coordinate an aks-preview adaptation, and add a controller-level compatibility test against both the latest released CLI (2.92.0) and this PR head.

…d be skipped

e4d6d49 rejected `--node-vm-size` together with any
--enable/--disable/--update-cluster-autoscaler flag. aks-preview reuses the core
update flow, so that broke combinations it accepted before, e.g. a VMSS resize
with --update-cluster-autoscaler.

Only reject the two cases that actually drop the resize: --enable-cluster-autoscaler
when the autoscaler is already enabled, and --disable-cluster-autoscaler when it is
already disabled. Both exit early before the resize is applied. Every other
combination sends one PUT with the new size and the autoscaler change, matching
2.92.0. The check runs in update_agentpool_profile_default after fetching the pool
and before the autoscaler properties are updated, so it sees the pool's current
autoscaler state.

Co-Authored-By: Claude <noreply@anthropic.com>

@FumingZhang FumingZhang left a comment

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.

lgtm

@live_only()
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='westus2')
def test_aks_nodepool_update_vm_size(self, resource_group, resource_group_location):

@FumingZhang FumingZhang Nov 6, 2026 •

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.

Queued live test to validate the change, test passed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-observability-squad AKS az aks/acs/openshift Auto-Assign Auto assign by bot customer-reported Issues that are reported by GitHub users external to the Azure organization. Request X Engineering Agent Ask the agent to triage this issue or review this PR X Engineering Agent Reviewed Agent reviewed this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants