Skip to content

[aks-preview] Fix executable lookup and kubeconfig conversion - #10606

Open
FumingZhang wants to merge 2 commits into
Azure:mainfrom
FumingZhang:fix/aks-preview-kubeconfig-executable-paths
Open

FumingZhang wants to merge 2 commits into
Azure:mainfrom
FumingZhang:fix/aks-preview-kubeconfig-executable-paths

Conversation

@FumingZhang

@FumingZhang FumingZhang commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

🤖 PR Validation — ⚠️ Review suggested

Breaking Changes Suppressions
️✔️ None ⚠️ 4 added

This PR adds warning or check suppressions. Fix the underlying warning where possible and justify each remaining suppression in a code comment or the PR description.

4 added suppressions
File Line Kind Code
src/aks-preview/azext_aks_preview/tests/latest/test_custom.py 108 skipped test @unittest.skipIf(os.name == "nt", "Requires a POSIX executable script and directory symlinks")
src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py 76 skipped test @unittest.skipIf(os.name == "nt", "Requires directory symlinks")
src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py 94 skipped test @unittest.skipIf(os.name == "nt", "Requires file and directory symlinks")
src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py 114 skipped test @unittest.skipIf(os.name == "nt", "Requires file symlinks")

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

Related command

az aks get-credentials, az aks kollect, az aks kanalyze, az aks bastion tunnel

  • Delegate bare executable lookup to CLI core's get_safe_executable_path; retain explicit-path validation and the final executable alias name, preserving directory-symlink/.. semantics.
  • Convert the selected file with an explicit --kubeconfig, without changing CWD or touching an inherited, unrelated kubeconfig. Skip conversion for --file - and preserve existing warnings.
  • Release 22.0.0b18 with azext.minCliCoreVersion raised from 2.85.0 to 2.93.0, and update the dependency table/history. CLI 2.92 introduced the helper; 2.93 includes the CWD-linked-executable and path-verification safeguards required here.

Validation on Linux with repository sources on PYTHONPATH: 66 tests and 54 subtests passed. The selected regressions failed before the implementation changes.

PYTHONDONTWRITEBYTECODE=1 TMPDIR="$PWD" PYTHONPATH="$PWD/src/aks-preview:/workspace/azure-cli/src/azure-cli:/workspace/azure-cli/src/azure-cli-core:/workspace/azure-cli/src/azure-cli-testsdk" python -m pytest -q --tb=short -p no:cacheprovider src/aks-preview/azext_aks_preview/tests/latest/test_helpers.py::TestWhich src/aks-preview/azext_aks_preview/tests/latest/test_custom.py::TestGetCredentialsExecutablePath src/aks-preview/azext_aks_preview/tests/latest/test_aks_diagnostics.py src/aks-preview/azext_aks_preview/tests/latest/test_aks_bastion.py

Using CI-matching linters in a temporary local environment:

Command Result
.ci-10606-alias-20261120/bin/python -m pylint --rcfile=pylintrc --persistent=no src/aks-preview/azext_aks_preview/_helpers.py Passed, 10.00/10
.ci-10606-alias-20261120/bin/python -m flake8 --append-config=.flake8 src/aks-preview/azext_aks_preview/_helpers.py Passed
python scripts/ci/test_index.py TestIndex.test_format_version TestIndex.test_format_extensions_key TestIndex.test_format_extensions_value TestIndex.test_extension_filenames -q Passed, 4 tests
git diff --cached --check Passed

Wheel build and embedded metadata checks passed: aks_preview-22.0.0b18-py2.py3-none-any.whl contains the 2.93.0 minimum; CLI compatibility checks reject 2.92.0 and accept 2.93.0. Python compilation and changed-line pycodestyle also passed.

Native Windows/macOS and live Azure tests were not run. Existing Git hooks could not activate their expected azdev environment; no hooks were bypassed or changed. The full index checksum/download suite was not run because the index is unchanged. No shared CLI documentation or other PR branches were modified.

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install azdev required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Use the CLI core safe executable resolver for bare tool names while preserving explicit-path validation and directory symlink semantics. Convert only the selected kubeconfig file and skip stdout-only conversion.

Release aks-preview 22.0.0b18 with a minimum CLI core version of 2.93.0. Add focused lookup, output-file and compatibility regressions, and update release/dependency documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@yonzhan

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

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

@FumingZhang
FumingZhang marked this pull request as ready for review November 20, 2026 06:37
Copilot AI balanced review requested due to automatic review settings November 20, 2026 06:37

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

Resolving the final executable symlink changes the invocation basename, which can break command dispatch for an explicit kubectl symlink to a multicall executable.

1 open issue
What changed in this PR

This PR hardens AKS tool lookup and makes az aks get-credentials convert only the selected kubeconfig, without changing the working directory or unrelated files.

Changes:

  • Delegate bare executable lookup to CLI core while retaining explicit-path handling.
  • Pass an explicit kubeconfig to kubelogin, skip conversion for stdout output, and add regression tests.
  • Release 22.0.0b18 with a minimum Azure CLI version of 2.93.0.
File Description
src/​aks-preview/​setup.py Bumps the extension version to 22.0.0b18.
src/​aks-preview/​README.rst Updates the CLI dependency table.
src/​aks-preview/​HISTORY.rst Documents fixes and the new CLI minimum.
src/​aks-preview/​azext_aks_preview/​tests/​latest/​test_helpers.py Tests executable lookup and symlink handling.
src/​aks-preview/​azext_aks_preview/​tests/​latest/​test_custom.py Tests selected-file conversion, stdout output, and warnings.
src/​aks-preview/​azext_aks_preview/​custom.py Targets kubeconfig conversion explicitly and removes CWD changes.
src/​aks-preview/​azext_aks_preview/​azext_metadata.json Requires Azure CLI 2.93.0 or later.
src/​aks-preview/​azext_aks_preview/​_helpers.py Uses CLI core lookup and revises explicit-path resolution.

Review effort: Balanced

if os.path.isfile(bin_path) and os.access(bin_path, os.X_OK):
return bin_path
for executable in binaries:
bin_path = os.path.realpath(executable)
Resolve the parent directory without dereferencing the final executable alias so basename-dispatched tools keep their invocation name. Retain directory-symlink and dot-dot path handling and executable validation.

Cover absolute, relative and symlink-parent explicit paths in the existing resolver tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants