Skip to content

fix(utils): make install-kubectl.sh work on macOS#976

Merged
ruizhang0101 merged 3 commits into
vllm-project:mainfrom
HumphreySun98:fix-kubectl-script-macos
Jun 17, 2026
Merged

fix(utils): make install-kubectl.sh work on macOS#976
ruizhang0101 merged 3 commits into
vllm-project:mainfrom
HumphreySun98:fix-kubectl-script-macos

Conversation

@HumphreySun98

Copy link
Copy Markdown
Contributor

Summary

Follow-up to the review on #970 (and same macOS root cause as #931): utils/install-kubectl.sh always downloaded the linux/amd64 kubectl, so on macOS it installs an unexecutable Linux ELF and later kubectl calls fail with an exec-format error. #970 fixed install-minikube-cluster.sh, which calls this script — so without this change the end-to-end flow still breaks on macOS at the kubectl step.

Changes

  • Detect OS (uname -s → linux/darwin) and arch (uname -m → amd64/arm64) and download the matching bin/{linux,darwin}/{amd64,arm64}/kubectl, mirroring the detection added to install-minikube-cluster.sh in fix(utils): make install-minikube-cluster.sh work on macOS #970.
  • Treat an existing kubectl as installed only if it actually runs (kubectl version --client), so a stale Linux binary left on PATH on macOS is replaced instead of skipped (this was the exact #931 failure mode).
  • Use curl -f so an HTTP error aborts the script (via set -e) instead of saving an error page as the binary.

Linux behavior is unchanged: HOST_OS/HOST_ARCH resolve to linux/amd64 on a normal x86_64 Linux host, giving the same URL as before.

Test plan

  • bash -n utils/install-kubectl.sh — passes (shellcheck runs in CI).
  • On Linux x86_64: resolves to bin/linux/amd64/kubectl (identical to the previous hardcoded URL).
  • On macOS arm64: resolves to bin/darwin/arm64/kubectl; a previously-installed Linux binary on PATH no longer short-circuits the install.

AI assistance was used; I have reviewed, run, and can defend every change.

install-kubectl.sh always downloaded the linux/amd64 kubectl, so on macOS
it installed an unexecutable Linux ELF (later kubectl calls fail with an
exec format error). Detect OS (uname -s) and arch (uname -m) and download
the matching bin/{linux,darwin}/{amd64,arm64}/kubectl, mirroring the OS/arch
detection added to install-minikube-cluster.sh in vllm-project#970.

Also: treat an existing kubectl as installed only if it actually runs
(`kubectl version --client`), so a stale Linux binary left on PATH on macOS
is replaced rather than skipped; and use `curl -f` so HTTP errors abort
instead of saving an error page as the binary.

Follow-up to the review on vllm-project#970; relates to vllm-project#931.

Signed-off-by: HumphreySun98 <[email protected]>

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates the utils/install-kubectl.sh script to dynamically detect the host OS and architecture (supporting Linux/Darwin and amd64/arm64) to download the appropriate kubectl binary, and improves the kubectl_exists check to ensure the binary is executable. The reviewer suggested extracting the nested curl command used for fetching the stable version into a separate step with explicit error handling to improve robustness and debuggability.

Comment thread utils/install-kubectl.sh
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
# Install kubectl for the detected platform. -f makes curl fail on HTTP errors
# instead of saving an error page as the binary.
curl -fLO "https://dl.k8s.io/release/$(curl -fL -s https://dl.k8s.io/release/stable.txt)/bin/${HOST_OS}/${HOST_ARCH}/kubectl"

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.

medium

Nesting the curl command to fetch the stable version inside the main download URL makes error handling and debugging difficult if the network request fails.

If the stable version lookup fails (e.g., due to a temporary network issue or DNS failure), the inner curl will fail silently (due to -s), resulting in an empty version string and a cryptic 404 error from the outer curl.

Consider extracting the version lookup into its own step with explicit error handling. This improves robustness and provides a clear error message to the user.

Suggested change
curl -fLO "https://dl.k8s.io/release/$(curl -fL -s https://dl.k8s.io/release/stable.txt)/bin/${HOST_OS}/${HOST_ARCH}/kubectl"
if ! KUBECTL_VERSION="$(curl -fL -s https://dl.k8s.io/release/stable.txt)" || [ -z "$KUBECTL_VERSION" ]; then
echo "ERROR: Failed to fetch the latest stable kubectl version" >&2
exit 1
fi
curl -fLO "https://dl.k8s.io/release/${KUBECTL_VERSION}/bin/${HOST_OS}/${HOST_ARCH}/kubectl"

@ruizhang0101 ruizhang0101 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ruizhang0101 ruizhang0101 merged commit 008e30d into vllm-project:main Jun 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants