Skip to content

Commit 6b69e33

Browse files
Copilotabdurriq
andcommitted
Add timeout and fallback for kubectl version fetching
Co-authored-by: abdurriq <[email protected]>
1 parent 84af0b3 commit 6b69e33

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/kubectl-helm-minikube/install.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,18 @@ if [ ${KUBECTL_VERSION} != "none" ]; then
154154
# Install the kubectl, verify checksum
155155
echo "Downloading kubectl..."
156156
if [ "${KUBECTL_VERSION}" = "latest" ] || [ "${KUBECTL_VERSION}" = "lts" ] || [ "${KUBECTL_VERSION}" = "current" ] || [ "${KUBECTL_VERSION}" = "stable" ]; then
157-
KUBECTL_VERSION="$(curl -sSL https://dl.k8s.io/release/stable.txt)"
157+
KUBECTL_VERSION="$(curl -fsSL --connect-timeout 10 --max-time 30 https://dl.k8s.io/release/stable.txt 2>/dev/null || echo "")"
158+
if [ -z "${KUBECTL_VERSION}" ]; then
159+
echo "(!) Failed to fetch kubectl stable version, falling back to version discovery via git tags"
160+
find_version_from_git_tags KUBECTL_VERSION https://github.com/kubernetes/kubernetes
161+
fi
158162
else
159163
find_version_from_git_tags KUBECTL_VERSION https://github.com/kubernetes/kubernetes
160164
fi
165+
if [ -z "${KUBECTL_VERSION}" ] || [ "${KUBECTL_VERSION}" = "none" ]; then
166+
echo "(!) Failed to determine kubectl version"
167+
exit 1
168+
fi
161169
if [ "${KUBECTL_VERSION::1}" != 'v' ]; then
162170
KUBECTL_VERSION="v${KUBECTL_VERSION}"
163171
fi

0 commit comments

Comments
 (0)