Repository navigation
feat(crud): add AKSMachineClient scaffolding for AKS Machine API - #1179
Merged
Merged
Conversation
Add the AKSMachineClient subclass with the agentpool half of the
AKS Machine API workflow fully implemented:
- create_machine_agentpool (PUT manualScale=0 agentpool, 200/201/202)
- _wait_for_agentpool_provisioning (poll until Succeeded)
- _get_machine_name_prefix (deterministic 12-char prefix so
cross-repo Kusto dashboards key on a stable machine name)
scale_machine and the per-machine readiness poll are stubbed to
raise NotImplementedError; the scale/batch/readiness helpers land
in a follow-up PR so this change stays small enough to review.
This is the first of a planned multi-PR series; it supersedes
PR #1178 which grew too large for a single review.
Tests: 6 unit tests covering the implemented surface plus a
guard that scale_machine raises NotImplementedError so the
MachineCRUD wire-up can detect the unimplemented path cleanly.
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds scaffolding for a new AKSMachineClient that extends AKSClient to support the AKS Machine API. The scale path is intentionally stubbed in this PR and will be implemented in a follow-up.
Changes:
- Introduces
AKSMachineClientwith cached ARM token auth, a raw RESTmake_requesthelper, fullcreate_machine_agentpoolflow with provisioning poll, and stubs forscale_machine/_wait_for_machine_node_readiness. - Adds the static
_get_machine_name_prefixhelper that collapses multiples of 1000 to akNform. - Adds unit tests covering the agentpool success/failure/timeout paths, the
NotImplementedErrorguard forscale_machine, and prefix generation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| modules/python/clients/aks_machine_client.py | New client subclass implementing agentpool conversion via raw ARM REST and stubbing the scale/readiness path. |
| modules/python/tests/test_aks_machine_client.py | New unit tests for create_machine_agentpool, the NotImplementedError stub, and _get_machine_name_prefix. |
- Stub _get_machine_name_prefix to raise NotImplementedError; implementation lands in PR-2 alongside the scale path that consumes it. - Reuse a per-instance requests.Session in make_request so TCP/TLS handshakes pool across polls and the planned parallel scale path. - Split the timeout budget in create_machine_agentpool: cap the PUT HTTP timeout at _PER_REQUEST_TIMEOUT_CAP (60s) and reserve the remainder for _wait_for_agentpool_provisioning's polling deadline. - Gate the transient-absent provisioningState 'treat as Failed' branch by wall-clock: only after _PROVISIONING_NONE_STATE_LIMIT consecutive polls AND at least half of timeout have elapsed. Avoids false negatives on slower control planes. - pylint setUp tempfile.TemporaryDirectory: disable consider-using-with inline since 'with' doesn't fit the unittest setUp/tearDown lifecycle. - Tests + module docstrings updated to reflect that _get_machine_name_prefix is stubbed; 5 unit tests, all passing.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
- _wait_for_agentpool_provisioning: raise on 4xx GET (404/401/403 won't recover by polling); only 5xx and other transient failures retry until the deadline. (per @liyu-ma) - _wait_for_agentpool_provisioning: simplify the absent-provisioningState branch to a single half-budget wall-clock gate; drop none_count and _PROVISIONING_NONE_STATE_LIMIT. (per @liyu-ma) - create_machine_agentpool: return type -> None (only ever returns or raises; the dead True return was misleading). Test updated to drop the assertTrue on the discarded return value. (per @liyu-ma)
…iled By AKS contract, a 200 GET on an agentpool always includes properties.provisioningState. The previous half-budget grace window existed to absorb a presumed transient None right after PUT acceptance, but that case does not actually occur for a successful (200) GET. If we do see a 200 response without provisioningState, that is a Failed signal and we should stop polling immediately rather than waiting out half of the timeout budget.
Liyu Ma (liyu-ma)
approved these changes
May 15, 2026
Karen Chen (karenychen)
added a commit
that referenced
this pull request
May 19, 2026
## Summary Adds the non-batch scale path to `AKSMachineClient`, building on the scaffolding from #1179. The batch path (`use_batch_api=True`) is intentionally still stubbed with `NotImplementedError` and lands in a follow-up PR so this diff stays focused and reviewable. ## What's in this PR **Fully implemented in this PR:** - `scale_machine` (non-batch branch): snapshots baseline ready node count, submits per-machine PUTs via `_scale_machine_individually`, waits once on the agentpool-level `provisioningState`, then waits for P50/P70/P90/P99/P100 node readiness. Raises `RuntimeError` on partial landing, agentpool timeout, or P100 readiness failure. - `_wait_for_machine_node_readiness`: polls nodes labeled `agentpool=<pool>` and computes percentile envelopes against `baseline_count + expected_count` so only NEW nodes count toward thresholds. Never raises; returns an empty-state envelope on exhaustion. - `_get_machine_name_prefix`: `scale<N>k` for multiples of 1000 ≥ 1000, `scale<N>` otherwise. Stable scheme for cross-repo Kusto dashboards. - `_scale_machine_individually`: `ThreadPoolExecutor` dispatch with `max(1, machine_workers)` clamp. - `_create_single_machine`: single Machine PUT, returns `True` on any 2xx, never raises. Per-machine ARM polling intentionally omitted (AKS RP reports `Succeeded` essentially as soon as the agentpool admits the request). **Stubbed in this PR (lands in a follow-up PR):** - `scale_machine` batch branch (`use_batch_api=True`) - `_scale_machine_batch`, `_create_batch_machines`, `_make_batch_request`, `_array_split`, and the `_BATCH_429_*` retry constants ## Other notes - `scale_machine` return type changed from `-> bool` to `-> None` for consistency with `create_machine_agentpool` (only exceptions signal failure; the return value was always dead). - Adds `_MACHINE_API_VERSION = '2025-06-02-preview'` constant. - Preserves every fix from #1179: `self._session` for connection pooling, `_PER_REQUEST_TIMEOUT_CAP=60` timeout split, immediate 4xx raise in `_wait_for_agentpool_provisioning`, immediate-Failed on missing `provisioningState`, `tempfile.TemporaryDirectory()` in test setUp/tearDown. ## Tests - 12 unit tests pass (up from 5 on main). - New tests cover: - Non-batch scale success (metadata enrichment, all required keys present) - Partial-landing raises `RuntimeError` - `baseline_count` snapshot propagation to `_wait_for_machine_node_readiness` - `_get_machine_name_prefix` value tests for small / multiple-of-1000 / non-multiple-of-1000 counts - `_create_single_machine` accepts 200/201/202 and returns `False` (no raise) on 500 - Regression test asserting the batch path still raises `NotImplementedError` - `pylint` rating: 10.00/10 on both files. ## Follow-up PR A subsequent PR will: - Replace the `NotImplementedError` in the `use_batch_api=True` branch with batch dispatch. - Add `_scale_machine_batch`, `_create_batch_machines`, `_make_batch_request`, `_array_split`, and the `_BATCH_429_*` constants. - Add a batch success-path test.
Pablo Trivino (PabloTriv)
pushed a commit
that referenced
this pull request
Jun 12, 2026
## Summary Adds the non-batch scale path to `AKSMachineClient`, building on the scaffolding from #1179. The batch path (`use_batch_api=True`) is intentionally still stubbed with `NotImplementedError` and lands in a follow-up PR so this diff stays focused and reviewable. ## What's in this PR **Fully implemented in this PR:** - `scale_machine` (non-batch branch): snapshots baseline ready node count, submits per-machine PUTs via `_scale_machine_individually`, waits once on the agentpool-level `provisioningState`, then waits for P50/P70/P90/P99/P100 node readiness. Raises `RuntimeError` on partial landing, agentpool timeout, or P100 readiness failure. - `_wait_for_machine_node_readiness`: polls nodes labeled `agentpool=<pool>` and computes percentile envelopes against `baseline_count + expected_count` so only NEW nodes count toward thresholds. Never raises; returns an empty-state envelope on exhaustion. - `_get_machine_name_prefix`: `scale<N>k` for multiples of 1000 ≥ 1000, `scale<N>` otherwise. Stable scheme for cross-repo Kusto dashboards. - `_scale_machine_individually`: `ThreadPoolExecutor` dispatch with `max(1, machine_workers)` clamp. - `_create_single_machine`: single Machine PUT, returns `True` on any 2xx, never raises. Per-machine ARM polling intentionally omitted (AKS RP reports `Succeeded` essentially as soon as the agentpool admits the request). **Stubbed in this PR (lands in a follow-up PR):** - `scale_machine` batch branch (`use_batch_api=True`) - `_scale_machine_batch`, `_create_batch_machines`, `_make_batch_request`, `_array_split`, and the `_BATCH_429_*` retry constants ## Other notes - `scale_machine` return type changed from `-> bool` to `-> None` for consistency with `create_machine_agentpool` (only exceptions signal failure; the return value was always dead). - Adds `_MACHINE_API_VERSION = '2025-06-02-preview'` constant. - Preserves every fix from #1179: `self._session` for connection pooling, `_PER_REQUEST_TIMEOUT_CAP=60` timeout split, immediate 4xx raise in `_wait_for_agentpool_provisioning`, immediate-Failed on missing `provisioningState`, `tempfile.TemporaryDirectory()` in test setUp/tearDown. ## Tests - 12 unit tests pass (up from 5 on main). - New tests cover: - Non-batch scale success (metadata enrichment, all required keys present) - Partial-landing raises `RuntimeError` - `baseline_count` snapshot propagation to `_wait_for_machine_node_readiness` - `_get_machine_name_prefix` value tests for small / multiple-of-1000 / non-multiple-of-1000 counts - `_create_single_machine` accepts 200/201/202 and returns `False` (no raise) on 500 - Regression test asserting the batch path still raises `NotImplementedError` - `pylint` rating: 10.00/10 on both files. ## Follow-up PR A subsequent PR will: - Replace the `NotImplementedError` in the `use_batch_api=True` branch with batch dispatch. - Add `_scale_machine_batch`, `_create_batch_machines`, `_make_batch_request`, `_array_split`, and the `_BATCH_429_*` constants. - Add a batch success-path test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First of a planned multi-PR series adding an AKS Machine API client (
AKSMachineClient) for the CRUD benchmarking framework. This PR delivers the scaffolding: the agentpool half of the workflow is fully implemented, and the scale/readiness path is stubbed so it can land in a follow-up PR.What's in this PR
Fully implemented (
modules/python/clients/aks_machine_client.py):AKSMachineClientsubclass ofAKSClientwith cached ARM token and a sharedrequests.Sessionfor connection poolingcreate_machine_agentpool— PUT amanualScale=0agentpool (accepts 200/201/202 to handle ARM async semantics); per-request HTTP timeout capped at_PER_REQUEST_TIMEOUT_CAP(60s) so a slow PUT can't consume the polling budget_wait_for_agentpool_provisioning— poll the agentpool untilSucceeded, surfaceFailedimmediately, tolerate transient absentprovisioningStateuntil both the consecutive-poll bound and a half-budget wall-clock grace window have elapsedStubbed in this PR (raise
NotImplementedError, signatures preserved for forward compatibility):scale_machine_wait_for_machine_node_readiness_get_machine_name_prefixNot yet introduced:
_scale_machine_individually,_scale_machine_batch,_create_single_machine,_create_batch_machines,_make_batch_request,_array_split— these land withscale_machinein PR-2.Tests
5 unit tests in
modules/python/tests/test_aks_machine_client.py:create_machine_agentpool— success, PUT failure surfaces, provisioning timeout raisesscale_machineraisesNotImplementedError(guard soMachineCRUDwire-up can detect the unimplemented path cleanly)_get_machine_name_prefixraisesNotImplementedErrorAll 5 pass locally; pylint 10.00/10 against the repo
.pylintrc.Follow-up PR
PR-2 (
scale_machine+ batch/individual scale paths + per-machine readiness polling +_get_machine_name_prefiximplementation) is in flight on a separate branch and will be opened once this one merges.