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-posta
pull/6/head
Kubernetes Submit Queue 2016-12-16 10:07:22 -08:00 committed by GitHub
commit 46e5f21676
5 changed files with 42 additions and 5 deletions

View File

@ -20,7 +20,7 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. KUBE_ROOT=$(cd $(dirname "${BASH_SOURCE}")/.. && pwd)
DEFAULT_KUBECONFIG="${HOME}/.kube/config" DEFAULT_KUBECONFIG="${HOME}/.kube/config"
@ -1008,3 +1008,36 @@ if missing:
' """${version}""" ' """${version}"""
fi 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}"
}

View File

@ -46,7 +46,7 @@ KUBERNETES_RELEASE_URL="${KUBERNETES_RELEASE_URL:-https://storage.googleapis.com
function detect_kube_release() { function detect_kube_release() {
if [[ ! -e "${KUBE_ROOT}/version" ]]; then if [[ ! -e "${KUBE_ROOT}/version" ]]; then
echo "Can't determine Kubernetes release." >&2 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 echo "Did you mean to use get-kube.sh instead?" >&2
exit 1 exit 1
fi fi
@ -162,8 +162,8 @@ detect_client_info
CLIENT_TAR="kubernetes-client-${CLIENT_PLATFORM}-${CLIENT_ARCH}.tar.gz" CLIENT_TAR="kubernetes-client-${CLIENT_PLATFORM}-${CLIENT_ARCH}.tar.gz"
echo "Kubernetes release: ${KUBERNETES_RELEASE}" echo "Kubernetes release: ${KUBERNETES_RELEASE}"
echo "Server: ${SERVER_PLATFORM}/${SERVER_ARCH}" echo "Server: ${SERVER_PLATFORM}/${SERVER_ARCH} (to override, set KUBERNETES_SERVER_ARCH)"
echo "Client: ${CLIENT_PLATFORM}/${CLIENT_ARCH}" echo "Client: ${CLIENT_PLATFORM}/${CLIENT_ARCH} (autodetected)"
echo echo
# TODO: remove this check and default to true when we stop shipping server # 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 read confirm
if [[ "${confirm}" =~ ^[nN]$ ]]; then if [[ "${confirm}" =~ ^[nN]$ ]]; then
echo "Aborting." echo "Aborting."
exit 0 exit 1
fi fi
fi fi

View File

@ -31,6 +31,7 @@ source "${KUBE_ROOT}/cluster/kube-util.sh"
echo "Bringing down cluster using provider: $KUBERNETES_PROVIDER" echo "Bringing down cluster using provider: $KUBERNETES_PROVIDER"
verify-prereqs verify-prereqs
verify-kube-binaries
kube-down kube-down
echo "Done" echo "Done"

View File

@ -69,6 +69,7 @@ if [[ "${push_to_master}" == "true" ]] && [[ "${push_to_node}" == "true" ]]; the
fi fi
verify-prereqs verify-prereqs
verify-kube-binaries
KUBE_VERSION=${1-} KUBE_VERSION=${1-}
if [[ "${push_to_master}" == "false" ]] && [[ "${push_to_node}" == "false" ]]; then if [[ "${push_to_master}" == "false" ]] && [[ "${push_to_node}" == "false" ]]; then

View File

@ -41,6 +41,8 @@ fi
echo "... calling verify-prereqs" >&2 echo "... calling verify-prereqs" >&2
verify-prereqs verify-prereqs
echo "... calling verify-kube-binaries" >&2
verify-kube-binaries
if [[ "${KUBE_STAGE_IMAGES:-}" == "true" ]]; then if [[ "${KUBE_STAGE_IMAGES:-}" == "true" ]]; then
echo "... staging images" >&2 echo "... staging images" >&2