Skip to content

[AKS] az aks command result: Honor --output while the command is still running - #34499

Open
Sai Kumar Pola (alopsing) wants to merge 2 commits into
Azure:devfrom
alopsing:aks-command-output-in-progress
Open

Sai Kumar Pola (alopsing) wants to merge 2 commits into
Azure:devfrom
alopsing:aks-command-output-in-progress

Conversation

@alopsing

@alopsing Sai Kumar Pola (alopsing) commented Nov 27, 2026 •

Copy link
Copy Markdown

🤖 PR Validation — ️✔️ All clear

Breaking Changes Tests Suppressions
️✔️ None ️✔️ 130/130 ️✔️ None

Related command

az aks command result

Description

Addresses #31157 for az aks command result. See the note on invoke --no-wait below.

While the in-cluster command is still running, az aks command result prints two lines of plain text and returns nothing, so -o json (or any other format) has no effect. Once the command finishes, the same call returns an object and the format applies. A script that polls az aks command result -o json therefore has to handle two different kinds of output.

The earlier discussion on the issue concluded that the code works as written, because the text is printed directly and never reaches the output formatter. I agree with that reading of the code. This PR changes the in-progress path of result so that it follows the rule _print_command_result already applies to finished commands: when the user passes -o/--output, return an object and let the CLI render it.

Changes:

  • az aks command result returns an object for a running command when -o/--output is passed, instead of printing. The object has the same keys as a finished result (id, provisioningState, startedAt, finishedAt, exitCode, logs, reason); the ones not known yet are null. The existing table transformer already handles this shape.
  • If the command finishes between the two requests that result makes, the complete result is returned.
  • The "did the user pass an output format" check moves into _output_format_specified, so both paths share it.
  • Without -o/--output, the printed text is unchanged.

Output of az aks command result -o json for a running command, before:

command id: 70f2846682cf4cd38aa36857d4274570, started at: 2025-03-30T02:28:31Z, status: Running
Please use command "az aks command result -g my-rg -n my-cluster -i 70f2846682cf4cd38aa36857d4274570" to get the future execution result

After:

{
  "exitCode": null,
  "finishedAt": null,
  "id": "70f2846682cf4cd38aa36857d4274570",
  "logs": null,
  "provisioningState": "Running",
  "reason": null,
  "startedAt": "2025-03-30T02:28:31Z"
}

Not changed: az aks command invoke --no-wait

The issue also reports this command. It still prints the command id as text, whatever -o says. invoke is registered with supports_no_wait=True, and the CLI core discards the return value of such a command when --no-wait is set, so there is no object to render. The first commit of this PR got this wrong and would have printed nothing; the second commit restores the text. Honoring -o there needs a change to how the command is registered (declaring --no-wait in the module instead of supports_no_wait). I can do that in this PR or a follow-up if you want it.

One point where I would like your call: a script that passes -o json to result today and reads the printed text for a running command will see JSON instead. I think that is what such a script asked for, but tell me if you want this handled differently.

This PR is independent of #34498 and merges cleanly with it.

Testing Guide

Unit tests added in acs/tests/latest/test_custom.py (TestRunCommand):

  • test_command_result_in_progress_returns_object_for_explicit_output: a running command with --output returns the object.
  • test_command_result_returns_result_finished_between_requests: a command that finishes between the two requests returns the complete result.
  • test_command_result_in_progress_prints_without_explicit_output: a running command without --output prints the text and returns nothing, as before.

Manual check:

az aks command invoke -g <rg> -n <cluster> --command "sleep 120" --no-wait
az aks command result -g <rg> -n <cluster> -i <command id> -o json
# JSON with "provisioningState": "Running"

az aks command result -g <rg> -n <cluster> -i <command id>
# text, unchanged

I ran the new unit tests against the changed functions locally. I have not run the manual check against a live cluster with this build.

History Notes

[AKS] az aks command result: Honor --output while the command is still running


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

…t` while the command is still running

While the in-cluster command was still running (`invoke --no-wait`, or
`result` before the command finished), both commands printed two lines of
plain text and returned nothing, so `-o json` and the other output formats
had no effect. Once the command finished, the same call returned an object.

Return an object in that case too when the user passes -o/--output. It has
the same keys as a finished command result, with the fields that are not
known yet set to null. Without an explicit output format the text is
printed as before.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 04:38
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@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 27, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

Thank you for your contribution Sai Kumar Pola (@alopsing)! 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

Explicit JSON output with --no-wait loses the entire result, including the command ID, and a completion race can discard available exit codes, logs, and failure details.

2 open issues
What changed in this PR

This PR addresses #31157 by returning structured AKS command results while execution is still running, allowing explicit output formats to apply while preserving plain-text output when no format is specified.

Changes:

  • Returns in-progress result objects from the shared helper and both command handlers.
  • Shares explicit output-format detection with completed-result handling.
  • Adds unit tests for structured output and unchanged default text output.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​acs/​tests/​latest/​test_custom.py Adds tests for in-progress results with and without explicit output formatting.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​custom.py Adds structured in-progress results and shared output-format detection.

Review effort: Balanced

…een requests

Address review feedback:

- `az aks command invoke --no-wait` goes back to printing the command id
  as text. The CLI discards the return value of a command when --no-wait
  is set, so returning an object there printed nothing at all with an
  explicit output format. Only `az aks command result` returns an object.
- If the command finishes between the two requests that `az aks command
  result` makes, return the complete result instead of an object with
  the exit code and logs set to null.
@alopsing Sai Kumar Pola (alopsing) changed the title [AKS] Fix #31157: az aks command invoke/result: Honor --output while the command is still running [AKS] az aks command result: Honor --output while the command is still running Nov 27, 2026
@x-engineering-agent
x-engineering-agent Bot requested a review from a team November 27, 2026 04:46
@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

This branch has not been deployed

No deployments
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants