Skip to content

feat(crud): add AKSMachineClient subclass for AKS Machine API - #1178

Closed
Karen Chen (karenychen) wants to merge 2 commits into
mainfrom
pr/crud-machine-1-aks-machine-client
Closed

Karen Chen (karenychen) wants to merge 2 commits into
mainfrom
pr/crud-machine-1-aks-machine-client

Conversation

@karenychen

Copy link
Copy Markdown
Contributor

First slice of the AKS Machine API CRUD perf-test port from ado-telescope to gh-telescope. Adds a new `AKSMachineClient(AKSClient)` subclass with raw REST methods for the AKS Machine API (not yet exposed in the Azure SDK).

Subsequent PRs will add: (2) the CRUD orchestrator `crud/azure/machine_crud.py`, (3) the CLI subcommands in `crud/main.py`, (4) scenario terraform inputs, and (5) the pipeline templates / production pipeline.

What this PR adds

`modules/python/clients/aks_machine_client.py` (new)

  • `class AKSMachineClient(AKSClient)`: subclass that inherits auth, ContainerServiceClient, KubernetesClient, `get_cluster_name`, `get_cluster_data`, and the existing node-pool CRUD methods.
  • `create_machine_agentpool(agentpool_name, vm_size, cluster_name=None, timeout=300) -> bool`: converts an existing agentpool to Machines mode via PUT.
  • `scale_machine(agentpool_name, vm_size, scale_machine_count, ...) -> bool`: adds N machines to a machine-mode agentpool. Supports both per-machine PUTs and the AKS `BatchPutMachine` header pattern.
  • Both methods follow the same convention as `AKSClient.create_node_pool` / `scale_node_pool`: open an `OperationContext`, enrich with `op.add_metadata` along the way, return `True` on success, re-raise on failure so the context records the trace.
  • `_wait_for_machine_node_readiness`: baseline-aware percentile watcher returning ado-parity nested envelope keyed P50/P70/P90/P99/P100, each entry carrying `{target_nodes, elapsed_time_seconds, percentage, success}`.

`modules/python/tests/test_aks_machine_client.py` (new, 9 tests)

  • create/scale success (batch and non-batch paths).
  • PUT failure and agentpool provisioning timeout raise `RuntimeError`.
  • Partial machine landing raises `RuntimeError`.
  • Baseline-count propagation to the readiness watcher.
  • ado-compatible machine-name prefix generator.

Persisted metadata schema

When `scale_machine` runs through `OperationContext`, the persisted operation_info metadata dict includes:
`successful_machines`, `batch_command_execution_times` (when batch), `percentile_node_readiness_times` (nested envelope), `node_readiness_time` (= P100.elapsed_time_seconds), `cluster_info`.

Verification

  • `pylint modules/python/clients/aks_machine_client.py modules/python/tests/test_aks_machine_client.py` -> 10.00/10.
  • `pytest modules/python/tests/test_aks_machine_client.py` -> 9 passed.
  • Full `pytest --cov=. --cov-fail-under=80` from modules/python/ -> 702 passed, 81.24% coverage.

Subsequent PRs in this stack

  1. `feat(crud): add MachineCRUD orchestrator` — thin try/except wrapper, mirrors `NodePoolCRUD`.
  2. `feat(crud): add create-machine + scale-machine CLI subcommands` — extends `crud/main.py` argparse.
  3. `feat(crud-machine): scenario terraform inputs` — `scenarios/perf-eval/k8s-cluster-crud-machine/`.
  4. `feat(crud-machine): pipeline templates + production pipeline` — `steps/engine/machine/k8s/.yml`, `steps/topology/k8s-cluster-crud-machine/.yml`, `pipelines/perf-eval/Autoscale Benchmark/k8s-cluster-crud-machine.yml`.

End-to-end validated on staging pipeline 23 against AKS sub `854c9ddb-...` in westus2.

First slice of the AKS Machine API CRUD perf-test port from ado-telescope
to gh-telescope. Adds a new `AKSMachineClient(AKSClient)` subclass that
adds raw REST methods for the AKS Machine API (not yet exposed in the
Azure SDK). Subsequent PRs will add the CRUD orchestrator
(`crud/azure/machine_crud.py`), the CLI subcommands in `crud/main.py`,
scenario terraform inputs, and the pipeline templates.

## What this PR adds

- `modules/python/clients/aks_machine_client.py`:
  - `class AKSMachineClient(AKSClient)`: subclass to inherit auth,
    ContainerServiceClient, KubernetesClient, `get_cluster_name`,
    `get_cluster_data`, and the existing node-pool CRUD methods.
  - `create_machine_agentpool(agentpool_name, vm_size, cluster_name=None, timeout=300) -> bool`:
    converts an existing agentpool to Machines mode via PUT.
  - `scale_machine(agentpool_name, vm_size, scale_machine_count, ...) -> bool`:
    adds N machines to a machine-mode agentpool, supports both
    per-machine PUTs and the AKS BatchPutMachine header pattern.
  - Both methods wrap their work in `OperationContext` exactly like
    `AKSClient.create_node_pool` / `scale_node_pool`: opens context,
    enriches with `op.add_metadata` along the way, returns True on
    success, re-raises on failure so the context records the trace.
  - `_wait_for_machine_node_readiness`: baseline-aware percentile
    watcher returning ado-parity nested envelope keyed
    P50/P70/P90/P99/P100. Each entry carries
    `{target_nodes, elapsed_time_seconds, percentage, success}`.

- `modules/python/tests/test_aks_machine_client.py`: 9 tests covering
  successful create/scale (batch and non-batch), PUT failure, agentpool
  provisioning timeout, partial machine landing (raises RuntimeError),
  baseline-count propagation to the readiness watcher, and the
  ado-compatible machine-name prefix generator.

## Schema for downstream Kusto consumers

When `scale_machine` runs through `OperationContext`, the persisted
metadata dict includes:
`successful_machines`, `batch_command_execution_times` (when batch),
`percentile_node_readiness_times` (nested envelope),
`node_readiness_time` (= P100.elapsed_time_seconds),
`cluster_info`.

## Verification

- `pylint modules/python/clients/aks_machine_client.py modules/python/tests/test_aks_machine_client.py` -> 10.00/10.
- `pytest modules/python/tests/test_aks_machine_client.py` -> 9 passed.
- Full `modules/python/ pytest --cov=. --cov-fail-under=80` -> 702 passed, 81.24% coverage.

## Subsequent PRs

2. `feat(crud): add MachineCRUD orchestrator`
3. `feat(crud): add create-machine + scale-machine CLI subcommands`
4. `feat(crud-machine): scenario terraform inputs`
5. `feat(crud-machine): pipeline templates + production pipeline`

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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a new AKSMachineClient to support raw REST CRUD operations against the AKS Machine API (not yet in Azure SDK), plus unit tests covering create/scale flows (batch + non-batch) and readiness/baseline behaviors.

Changes:

  • Introduces AKSMachineClient(AKSClient) with token caching, REST helpers, create-machine-agentpool, and scale-machine (batch + concurrent PUT paths).
  • Adds readiness percentile watcher that accounts for baseline ready-node count.
  • Adds a new unit test suite validating success/failure scenarios and metadata enrichment.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
modules/python/clients/aks_machine_client.py New Machine API client with REST plumbing, batch/non-batch scale, and readiness watcher.
modules/python/tests/test_aks_machine_client.py New unit tests validating create/scale behaviors and helper parity.

Changes:
- scale_machine: raise RuntimeError on !agentpool_ok or P100 success=False
  instead of silently returning True
- PUT machine status check: accept 202 Accepted (ARM async semantics)
  in addition to 200/201
- _scale_machine_individually: clamp ThreadPoolExecutor workers to
  max(1, request.machine_workers) to prevent ValueError on <=0
- _scale_machine_individually docstring: clarify per-machine
  provisioningState is intentionally not polled (parity with batch path)
- tests: replace hardcoded /tmp/test_results + os.makedirs with
  tempfile.TemporaryDirectory + tearDown cleanup
- strip provenance/mirroring comments across both files; keep only
  WHY-rationale comments
Karen Chen (karenychen) added a commit that referenced this pull request May 14, 2026
Changes:
- scale_machine: raise RuntimeError on !agentpool_ok or P100 success=False
  instead of silently returning True
- PUT machine status check: accept 202 Accepted (ARM async semantics)
  in addition to 200/201
- _scale_machine_individually: clamp ThreadPoolExecutor workers to
  max(1, request.machine_workers) to prevent ValueError on <=0
- _scale_machine_individually docstring: clarify per-machine
  provisioningState is intentionally not polled (parity with batch path)
- tests: replace hardcoded /tmp/test_results + os.makedirs with
  tempfile.TemporaryDirectory + tearDown cleanup
- strip provenance/mirroring comments across both files; keep only
  WHY-rationale comments
@karenychen

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1179, which splits this work into smaller reviewable pieces.

#1179 contains the scaffolding half of this PR: create_machine_agentpool, _wait_for_agentpool_provisioning, and _get_machine_name_prefix fully implemented, with scale_machine and its batch/readiness helpers stubbed to NotImplementedError. A follow-up PR will reintroduce the scale path with the review fixes already applied (return True only after agentpool + P100 readiness both confirm success, accept ARM 202 on the agentpool PUT, clamp ThreadPoolExecutor workers to max(1, ...), accurate _scale_machine_individually docstring, tempfile.TemporaryDirectory in tests).

Thanks for the review here — all five substantive findings have been preserved and are already merged into the scaffolding branch / queued for PR-2.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants