diff --git a/cluster/common.sh b/cluster/common.sh index 94f02bbeba..d2f9909d58 100755 --- a/cluster/common.sh +++ b/cluster/common.sh @@ -963,3 +963,42 @@ function parse-master-env() { KUBELET_CERT_BASE64=$(get-env-val "${master_env}" "KUBELET_CERT") KUBELET_KEY_BASE64=$(get-env-val "${master_env}" "KUBELET_KEY") } + +# Update or verify required gcloud components are installed +# at minimum required version. +# Assumed vars +# KUBE_PROMPT_FOR_UPDATE +function update-or-verify-gcloud() { + local sudo_prefix="" + if [ ! -w $(dirname `which gcloud`) ]; then + sudo_prefix="sudo" + fi + # update and install components as needed + if [[ "${KUBE_PROMPT_FOR_UPDATE}" == "y" ]]; then + ${sudo_prefix} gcloud ${gcloud_prompt:-} components install alpha + ${sudo_prefix} gcloud ${gcloud_prompt:-} components install beta + ${sudo_prefix} gcloud ${gcloud_prompt:-} components update + else + local version=$(${sudo_prefix} gcloud version --format=json) + python -c' +import json,sys +from distutils import version + +minVersion = version.LooseVersion("1.3.0") +required = [ "alpha", "beta", "core" ] +data = json.loads(sys.argv[1]) +rel = data.get("Google Cloud SDK") +if rel != "HEAD" and version.LooseVersion(rel) < minVersion: + print "gcloud version out of date ( < %s )" % minVersion + exit(1) +missing = [] +for c in required: + if not data.get(c): + missing += [c] +if missing: + for c in missing: + print ("missing required gcloud component \"{0}\"".format(c)) + exit(1) + ' """${version}""" + fi +} diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 77bd64f17d..8166db2e0c 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -80,8 +80,7 @@ NODE_TAGS="${NODE_TAG}" ALLOCATE_NODE_CIDRS=true -KUBE_PROMPT_FOR_UPDATE=y -KUBE_SKIP_UPDATE=${KUBE_SKIP_UPDATE-"n"} +KUBE_PROMPT_FOR_UPDATE=${KUBE_PROMPT_FOR_UPDATE:-"n"} # How long (in seconds) to wait for cluster initialization. KUBE_CLUSTER_INITIALIZATION_TIMEOUT=${KUBE_CLUSTER_INITIALIZATION_TIMEOUT:-300} @@ -99,12 +98,10 @@ function verify-prereqs() { local cmd for cmd in gcloud gsutil; do if ! which "${cmd}" >/dev/null; then - local resp + local resp="n" if [[ "${KUBE_PROMPT_FOR_UPDATE}" == "y" ]]; then echo "Can't find ${cmd} in PATH. Do you wish to install the Google Cloud SDK? [Y/n]" read resp - else - resp="y" fi if [[ "${resp}" != "n" && "${resp}" != "N" ]]; then curl https://sdk.cloud.google.com | bash @@ -116,20 +113,7 @@ function verify-prereqs() { fi fi done - if [[ "${KUBE_SKIP_UPDATE}" == "y" ]]; then - return - fi - # update and install components as needed - if [[ "${KUBE_PROMPT_FOR_UPDATE}" != "y" ]]; then - gcloud_prompt="-q" - fi - local sudo_prefix="" - if [ ! -w $(dirname `which gcloud`) ]; then - sudo_prefix="sudo" - fi - ${sudo_prefix} gcloud ${gcloud_prompt:-} components install alpha || true - ${sudo_prefix} gcloud ${gcloud_prompt:-} components install beta || true - ${sudo_prefix} gcloud ${gcloud_prompt:-} components update || true + update-or-verify-gcloud } # Create a temp dir that'll be deleted at the end of this bash session. diff --git a/cluster/gke/util.sh b/cluster/gke/util.sh index f8440d6baf..28d4d5e348 100755 --- a/cluster/gke/util.sh +++ b/cluster/gke/util.sh @@ -18,8 +18,7 @@ # Uses the config file specified in $KUBE_CONFIG_FILE, or defaults to config-default.sh -KUBE_PROMPT_FOR_UPDATE=y -KUBE_SKIP_UPDATE=${KUBE_SKIP_UPDATE-"n"} +KUBE_PROMPT_FOR_UPDATE=${KUBE_PROMPT_FOR_UPDATE:-"n"} KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. source "${KUBE_ROOT}/cluster/gke/${KUBE_CONFIG_FILE:-config-default.sh}" source "${KUBE_ROOT}/cluster/common.sh" @@ -97,8 +96,6 @@ function verify-prereqs() { if [[ "${KUBE_PROMPT_FOR_UPDATE}" == "y" ]]; then echo "Can't find gcloud in PATH. Do you wish to install the Google Cloud SDK? [Y/n]" read resp - else - resp="y" fi if [[ "${resp}" != "n" && "${resp}" != "N" ]]; then curl https://sdk.cloud.google.com | bash @@ -109,21 +106,7 @@ function verify-prereqs() { exit 1 fi fi - if [[ "${KUBE_SKIP_UPDATE}" == "y" ]]; then - return - fi - # update and install components as needed - if [[ "${KUBE_PROMPT_FOR_UPDATE}" != "y" ]]; then - gcloud_prompt="-q" - fi - local sudo_prefix="" - if [ ! -w $(dirname `which gcloud`) ]; then - sudo_prefix="sudo" - fi - ${sudo_prefix} gcloud ${gcloud_prompt:-} components install alpha || true - ${sudo_prefix} gcloud ${gcloud_prompt:-} components install beta || true - ${sudo_prefix} gcloud ${gcloud_prompt:-} components install kubectl|| true - ${sudo_prefix} gcloud ${gcloud_prompt:-} components update || true + update-or-verify-gcloud } # Validate a kubernetes cluster