Skip to content

[AKS] Fix #34496: az aks command invoke: Return the in-cluster command's exit code - #34498

Open
Sai Kumar Pola (alopsing) wants to merge 1 commit into
Azure:devfrom
alopsing:aks-command-invoke-exit-code
Open

Sai Kumar Pola (alopsing) wants to merge 1 commit into
Azure:devfrom
alopsing:aks-command-invoke-exit-code

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 invoke, az aks command result

Description

Fixes #34496.

az aks command invoke prints the exit code of the command that ran inside the cluster (... with exitcode=1) but always exits 0 itself. A script or CI job that runs, for example, az aks command invoke ... --command "kubectl apply -f x.yaml" cannot tell that the command failed without parsing the output.

This PR changes _print_command_result, which both invoke and result use:

  • When the run command succeeded but the in-cluster command exited non-zero, exit with that same code.
  • When the run command itself failed (provisioning state Failed), exit 1 after printing the reason.
  • Nothing changes when the in-cluster command exits 0, when the command is still running, or when -o/--output is passed explicitly (the result object is returned as before).

Two points where I would like your call:

  1. This changes the exit status of an existing command, so a script that relied on exit 0 after a failed in-cluster command will now see a failure. I think that is the intended behavior, but if you would rather gate it behind a flag, I can do that.
  2. I used sys.exit(code) so the in-cluster code is passed through unchanged. If you prefer an azclierror type (which would lose the specific code), I can switch.

Testing Guide

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

  • test_print_command_result_succeeded: exit code 0 returns normally.
  • test_print_command_result_exits_with_inner_exit_code: in-cluster exit code 3 exits 3.
  • test_print_command_result_exits_when_run_command_failed: provisioning state Failed exits 1.
  • test_print_command_result_in_progress: a running command returns normally.
  • test_print_command_result_returns_object_for_explicit_output: -o json still returns the object.

Manual check:

az aks command invoke -g <rg> -n <cluster> --command "exit 3"; echo $?
# before: 0    after: 3

az aks command invoke -g <rg> -n <cluster> --command "kubectl get ns"; echo $?
# before: 0    after: 0

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

History Notes

[AKS] az aks command invoke: Return the in-cluster command's exit code so that failures are visible to scripts
[AKS] az aks command result: Return the in-cluster command's exit code so that failures are visible to scripts


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

… command's exit code

`az aks command invoke` and `az aks command result` printed the exit code
of the command that ran in the cluster, but always exited 0 themselves.
Scripts and CI pipelines could not detect a failed command without parsing
the output.

Exit with the in-cluster command's exit code when it is non-zero, and exit
1 when the run command itself fails (provisioning state "Failed").
Behavior with an explicit -o/--output is unchanged: the result object is
still returned.
Copilot AI balanced review requested due to automatic review settings November 27, 2026 04:26
@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.

🔵 Needs a closer look

A maintainer must decide whether changing the default exit statuses of both AKS commands requires an opt-in flag or breaking-change treatment because existing scripts may be affected.

No open issues 🎉

What changed in this PR

Fixes #34496 by making az aks command invoke and az aks command result report failures through their process exit status, allowing scripts and CI jobs to detect them without parsing output.

Changes:

  • Propagates nonzero in-cluster exit codes and exits with status 1 when provisioning fails.
  • Preserves existing behavior for successful commands, commands still running, and explicit output formats.
  • Adds unit tests for failure propagation and unchanged behavior.
File Description
src/​azure-cli/​azure/​cli/​command_modules/​acs/​tests/​latest/​test_custom.py Adds five tests covering exit statuses and preserved result handling.
src/​azure-cli/​azure/​cli/​command_modules/​acs/​custom.py Updates the shared result printer to exit nonzero on command failures.

Review effort: Balanced

@alopsing

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@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.

az aks command invoke exits 0 when the command run in the cluster fails

5 participants