Repository navigation
feat(crud-machine): AKS Machine API client + CRUD layer + CLI #1187
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """ | ||
| Azure AKS Machine CRUD Operations Module. | ||
|
|
||
| This module provides a thin orchestration layer over ``AKSMachineClient`` for the | ||
| AKS Machine API. It mirrors ``crud/azure/node_pool_crud.py``: each public method | ||
| delegates to the underlying client (which already opens an ``OperationContext`` | ||
| and writes the per-operation result file), wraps the call in try/except, and | ||
| returns a boolean so the CLI dispatcher can translate to a process exit code. | ||
|
|
||
| All telemetry (start/end timestamps, duration, success flag, error traceback, | ||
| metadata enrichment) is recorded by ``AKSMachineClient`` itself; this layer | ||
| deliberately adds no result-handling logic of its own. | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| from clients.aks_machine_client import AKSMachineClient | ||
| from utils.logger_config import get_logger, setup_logging | ||
|
|
||
| setup_logging() | ||
| logger = get_logger(__name__) | ||
| get_logger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.ERROR) | ||
| get_logger("azure.identity").setLevel(logging.ERROR) | ||
| get_logger("azure.core.pipeline").setLevel(logging.ERROR) | ||
| get_logger("msal").setLevel(logging.ERROR) | ||
|
|
||
|
|
||
| class MachineCRUD: | ||
| """Thin CRUD wrapper around :class:`AKSMachineClient` for the Machine API. | ||
|
|
||
| Mirrors :class:`crud.azure.node_pool_crud.NodePoolCRUD`: public methods are | ||
| a try/except over the equivalent client method. The client already records | ||
| the operation via ``OperationContext`` so no extra bookkeeping happens here. | ||
| """ | ||
|
|
||
| def __init__(self, resource_group, kube_config_file=None, result_dir=None, | ||
| step_timeout=600): | ||
| self.aks_client = AKSMachineClient( | ||
| resource_group=resource_group, | ||
| kube_config_file=kube_config_file, | ||
| result_dir=result_dir, | ||
| operation_timeout_minutes=max(1, step_timeout // 60), | ||
| ) | ||
| self.cluster_name = self.aks_client.get_cluster_name() | ||
| self.result_dir = result_dir | ||
| self.step_timeout = step_timeout | ||
|
|
||
| def create_machine_agentpool(self, agentpool_name, vm_size): | ||
| """Create a machine-mode agent pool. Returns True on success, False on failure.""" | ||
| try: | ||
| self.aks_client.create_machine_agentpool( | ||
| agentpool_name=agentpool_name, | ||
| vm_size=vm_size, | ||
| cluster_name=self.cluster_name, | ||
| timeout=self.step_timeout, | ||
| ) | ||
| return True | ||
| except Exception as e: | ||
| logger.error(f"create_machine_agentpool failed for {agentpool_name}: {e}") | ||
| return False | ||
|
|
||
| def scale_machine(self, agentpool_name, vm_size, scale_machine_count, | ||
| use_batch_api=False, machine_workers=1, | ||
| readiness_wait_timeout=1200, tags=None): | ||
| """Scale a machine-mode agent pool by ``scale_machine_count`` machines. | ||
|
|
||
| Returns True on success, False on failure. All timing and percentile | ||
| metadata are written by ``AKSMachineClient.scale_machine`` via | ||
| ``OperationContext``. | ||
| """ | ||
| try: | ||
| self.aks_client.scale_machine( | ||
| agentpool_name=agentpool_name, | ||
| vm_size=vm_size, | ||
| scale_machine_count=scale_machine_count, | ||
| cluster_name=self.cluster_name, | ||
| use_batch_api=use_batch_api, | ||
| machine_workers=machine_workers, | ||
| timeout=self.step_timeout, | ||
| readiness_wait_timeout=readiness_wait_timeout, | ||
| tags=tags, | ||
| ) | ||
|
karenychen marked this conversation as resolved.
Resolved
|
||
| return True | ||
| except Exception as e: | ||
| logger.error(f"scale_machine failed for {agentpool_name}: {e}") | ||
| return False | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.