mirror of https://github.com/k3s-io/k3s
Merge pull request #38730 from ixdy/download-kube-binaries-if-needed
Automatic merge from submit-queue Automatically download missing kube binaries in kube-up/kube-down. **What this PR does / why we need it**: some users extract `kubernetes.tar.gz` and then immediately call `cluster/kube-up.sh` without first calling the new `cluster/get-kube-binaries.sh` script. As a result, the cluster fails to start, but it's not immediately clear why binaries are missing. This PR streamlines this workflow by detecting this condition and prompting the user to download necessary binaries (using `cluster/get-kube-binaries.sh`). **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #38725 cc @arun-gupta @christian-postapull/6/head
commit
46e5f21676
|
@ -20,7 +20,7 @@ set -o errexit
|
|||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
|
||||
|
||||
DEFAULT_KUBECONFIG="${HOME}/.kube/config"
|
||||
|
||||
|
@ -1008,3 +1008,36 @@ if missing:
|
|||
' """${version}"""
|
||||
fi
|
||||
}
|
||||
|
||||
# Check whether required client and server binaries exist, prompting to download
|
||||
# if missing.
|
||||
# If KUBERNETES_SKIP_CONFIRM is set to y, we'll automatically download binaries
|
||||
# without prompting.
|
||||
function verify-kube-binaries() {
|
||||
local missing_binaries=false
|
||||
if ! "${KUBE_ROOT}/cluster/kubectl.sh" version --client >&/dev/null; then
|
||||
echo "!!! kubectl appears to be broken or missing"
|
||||
missing_binaries=true
|
||||
fi
|
||||
if ! $(find-release-tars); then
|
||||
missing_binaries=true
|
||||
fi
|
||||
|
||||
if ! "${missing_binaries}"; then
|
||||
return
|
||||
fi
|
||||
|
||||
get_binaries_script="${KUBE_ROOT}/cluster/get-kube-binaries.sh"
|
||||
local resp="y"
|
||||
if [[ ! "${KUBERNETES_SKIP_CONFIRM:-n}" =~ ^[yY]$ ]]; then
|
||||
echo "Required binaries appear to be missing. Do you wish to download them? [Y/n]"
|
||||
read resp
|
||||
fi
|
||||
if [[ "${resp}" =~ ^[nN]$ ]]; then
|
||||
echo "You must download binaries to continue. You can use "
|
||||
echo " ${get_binaries_script}"
|
||||
echo "to do this for your automatically."
|
||||
exit 1
|
||||
fi
|
||||
"${get_binaries_script}"
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ KUBERNETES_RELEASE_URL="${KUBERNETES_RELEASE_URL:-https://storage.googleapis.com
|
|||
function detect_kube_release() {
|
||||
if [[ ! -e "${KUBE_ROOT}/version" ]]; then
|
||||
echo "Can't determine Kubernetes release." >&2
|
||||
echo "This script should only be run from a prebuilt Kubernetes release." >&2
|
||||
echo "${BASH_SOURCE} should only be run from a prebuilt Kubernetes release." >&2
|
||||
echo "Did you mean to use get-kube.sh instead?" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
@ -162,8 +162,8 @@ detect_client_info
|
|||
CLIENT_TAR="kubernetes-client-${CLIENT_PLATFORM}-${CLIENT_ARCH}.tar.gz"
|
||||
|
||||
echo "Kubernetes release: ${KUBERNETES_RELEASE}"
|
||||
echo "Server: ${SERVER_PLATFORM}/${SERVER_ARCH}"
|
||||
echo "Client: ${CLIENT_PLATFORM}/${CLIENT_ARCH}"
|
||||
echo "Server: ${SERVER_PLATFORM}/${SERVER_ARCH} (to override, set KUBERNETES_SERVER_ARCH)"
|
||||
echo "Client: ${CLIENT_PLATFORM}/${CLIENT_ARCH} (autodetected)"
|
||||
echo
|
||||
|
||||
# TODO: remove this check and default to true when we stop shipping server
|
||||
|
@ -201,7 +201,7 @@ if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
|
|||
read confirm
|
||||
if [[ "${confirm}" =~ ^[nN]$ ]]; then
|
||||
echo "Aborting."
|
||||
exit 0
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ source "${KUBE_ROOT}/cluster/kube-util.sh"
|
|||
echo "Bringing down cluster using provider: $KUBERNETES_PROVIDER"
|
||||
|
||||
verify-prereqs
|
||||
verify-kube-binaries
|
||||
kube-down
|
||||
|
||||
echo "Done"
|
||||
|
|
|
@ -69,6 +69,7 @@ if [[ "${push_to_master}" == "true" ]] && [[ "${push_to_node}" == "true" ]]; the
|
|||
fi
|
||||
|
||||
verify-prereqs
|
||||
verify-kube-binaries
|
||||
KUBE_VERSION=${1-}
|
||||
|
||||
if [[ "${push_to_master}" == "false" ]] && [[ "${push_to_node}" == "false" ]]; then
|
||||
|
|
|
@ -41,6 +41,8 @@ fi
|
|||
|
||||
echo "... calling verify-prereqs" >&2
|
||||
verify-prereqs
|
||||
echo "... calling verify-kube-binaries" >&2
|
||||
verify-kube-binaries
|
||||
|
||||
if [[ "${KUBE_STAGE_IMAGES:-}" == "true" ]]; then
|
||||
echo "... staging images" >&2
|
||||
|
|
Loading…
Reference in New Issue