Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Pending
* `az aks nodepool update`: Preserve the existing GPU management mode when `--enable-managed-gpu` is omitted, including when enabling, updating, or disabling the cluster autoscaler.
* `az aks alert-config add`: Reject an empty `--name` before looking up existing configurations instead of reporting that it already exists.
* `az aks nodepool scale`: add `--use-patch-api` to optionally scale a VMSS node pool via the new dedicated PATCH agent pool API (scales to the target count without triggering full reconciliation). The default behavior continues to use the PUT agent pool API.
* Add `az aks operation list` to list historical or active (`--active-only`) operations on a cluster (`--resource-group` and `--name`) or on a node pool (`--nodepool-name`).

22.0.0b8
+++++++++
Expand Down
37 changes: 23 additions & 14 deletions src/aks-preview/azext_aks_preview/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,29 @@ def parser(entry):


def aks_operation_show_table_format(result):
def parser(entry):
percentComplete = ""
if entry["percentComplete"]:
percentComplete = str(entry["percentComplete"]) + "%"
entry["percentComplete"] = percentComplete
parsed = compile_jmes("""{
name: name,
status: status,
startTime: startTime,
endTime: endTime,
percentComplete: percentComplete
}""")
return parsed.search(entry, Options(dict_cls=OrderedDict))
return parser(result)
return _aks_operation_table_format(result)


def aks_operation_list_table_format(results):
"""Format an operation list for display with "-o table"."""
return [_aks_operation_table_format(r) for r in results]


def _aks_operation_table_format(result):
percentComplete = ""
if result.get("percentComplete"):
percentComplete = str(result["percentComplete"]) + "%"
result["percentComplete"] = percentComplete
parsed = compile_jmes("""{
name: name,
status: status,
operationType: operationType,
subOperationType: subOperationType,
startTime: startTime,
endTime: endTime,
percentComplete: percentComplete
}""")
return parsed.search(result, Options(dict_cls=OrderedDict))


def aks_namespace_list_table_format(results):
Expand Down
27 changes: 27 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -3337,6 +3337,33 @@
short-summary: Name of the resource group.
"""

helps['aks operation list'] = """
type: command
short-summary: List operations on a managed Kubernetes cluster or one of its node pools.
parameters:
- name: --name -n
type: string
short-summary: The name of the managed cluster.
- name: --nodepool-name
type: string
short-summary: The name of the nodepool. When specified, operations are listed for the node pool instead of the cluster.
- name: --active-only
type: bool
short-summary: Only list operations that are currently active (not terminal).
- name: --resource-group -g
type: string
short-summary: Name of the resource group.
examples:
- name: List historical operations on a managed cluster.
text: az aks operation list -g myResourceGroup -n myAKSCluster
- name: List active operations on a managed cluster.
text: az aks operation list -g myResourceGroup -n myAKSCluster --active-only
- name: List historical operations on a node pool.
text: az aks operation list -g myResourceGroup -n myAKSCluster --nodepool-name nodepool1
- name: List active operations on a node pool.
text: az aks operation list -g myResourceGroup -n myAKSCluster --nodepool-name nodepool1 --active-only
"""

helps['aks operation-abort'] = """
type: command
short-summary: Abort last running operation on managed cluster.
Expand Down
7 changes: 7 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -2916,6 +2916,13 @@ def load_arguments(self, _):
default="",
)

with self.argument_context("aks operation list") as c:
c.argument(
"active_only",
action="store_true",
help="Only list operations that are currently active (not terminal). "
)

with self.argument_context("aks maintenanceconfiguration") as c:
c.argument("cluster_name", help="The cluster name.")

Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
aks_machine_list_table_format,
aks_machine_show_table_format,
aks_operation_show_table_format,
aks_operation_list_table_format,
aks_list_nodepool_snapshot_table_format,
aks_list_snapshot_table_format,
aks_list_table_format,
Expand Down Expand Up @@ -380,6 +381,9 @@ def load_command_table(self, _):
g.custom_command(
"show-latest", "aks_operation_show_latest", table_transformer=aks_operation_show_table_format
)
g.custom_command(
"list", "aks_operation_list", table_transformer=aks_operation_list_table_format
)

# AKS draft commands
with self.command_group(
Expand Down
20 changes: 20 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3324,6 +3324,26 @@ def aks_operation_show_latest(cmd,
return client.get(resource_group_name, name, "latest")


def aks_operation_list(cmd, # pylint: disable=unused-argument
client,
resource_group_name,
name,
nodepool_name="",
active_only=False):
if not nodepool_name:
operations = client.list(resource_group_name, name)
if active_only:
# There is no cluster-scope API to return only active operations, so filter locally.
# Terminal states are Succeeded/Failed/Canceled; anything else is still in progress.
terminal_states = {"succeeded", "failed", "canceled"}
return [
op for op in operations
if (getattr(op, "status", None) or "").lower() not in terminal_states
]
return operations
return client.list_by_agent_pool(resource_group_name, name, nodepool_name, active_only=active_only)


def aks_operation_abort(cmd, # pylint: disable=unused-argument
client,
resource_group_name,
Expand Down
Loading
Loading