Skip to content

Commit

Permalink
Automatically download missing kube binaries in kube-up/kube-down.
Browse files Browse the repository at this point in the history
  • Loading branch information
ixdy committed Dec 16, 2016
1 parent 54fc6bd commit c20197f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
35 changes: 34 additions & 1 deletion cluster/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -968,3 +968,36 @@ function parse-master-env() {
KUBELET_CERT_BASE64=$(get-env-val "${master_env}" "KUBELET_CERT")
KUBELET_KEY_BASE64=$(get-env-val "${master_env}" "KUBELET_KEY")
}

# 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}"
}
8 changes: 4 additions & 4 deletions cluster/get-kube-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,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
Expand Down Expand Up @@ -158,8 +158,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
Expand Down Expand Up @@ -197,7 +197,7 @@ if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
read confirm
if [[ "${confirm}" =~ ^[nN]$ ]]; then
echo "Aborting."
exit 0
exit 1
fi
fi

Expand Down
1 change: 1 addition & 0 deletions cluster/kube-down.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 1 addition & 0 deletions cluster/kube-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cluster/kube-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c20197f

Please sign in to comment.