From cbee65a6d2b969997ec5c9defcca7096b7dee092 Mon Sep 17 00:00:00 2001 From: Jeff Grafton Date: Tue, 13 Dec 2016 14:59:13 -0800 Subject: [PATCH] Automatically download missing kube binaries in kube-up/kube-down. --- cluster/common.sh | 35 ++++++++++++++++++++++++++++++++++- cluster/get-kube-binaries.sh | 8 ++++---- cluster/kube-down.sh | 1 + cluster/kube-push.sh | 1 + cluster/kube-up.sh | 2 ++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/cluster/common.sh b/cluster/common.sh index 69e04fc612..16548a12d3 100755 --- a/cluster/common.sh +++ b/cluster/common.sh @@ -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}" +} diff --git a/cluster/get-kube-binaries.sh b/cluster/get-kube-binaries.sh index e7d792df0c..20e1c13d8f 100755 --- a/cluster/get-kube-binaries.sh +++ b/cluster/get-kube-binaries.sh @@ -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 diff --git a/cluster/kube-down.sh b/cluster/kube-down.sh index 42f4a31baf..2f89e6096c 100755 --- a/cluster/kube-down.sh +++ b/cluster/kube-down.sh @@ -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" diff --git a/cluster/kube-push.sh b/cluster/kube-push.sh index dd7d2039ff..aa84f902fa 100755 --- a/cluster/kube-push.sh +++ b/cluster/kube-push.sh @@ -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 diff --git a/cluster/kube-up.sh b/cluster/kube-up.sh index 6515741921..a6eb618888 100755 --- a/cluster/kube-up.sh +++ b/cluster/kube-up.sh @@ -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