Make get-kube.sh smarter when choosing if it should download

This commit is contained in:
Jeff Grafton 2016-10-25 18:23:59 -07:00
parent 2e503c1a54
commit db3fd62f1d
2 changed files with 44 additions and 18 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2016 The Kubernetes Authors. # Copyright 2016 The Kubernetes Authors.
# #
@ -117,7 +117,7 @@ function download_tarball() {
url="${DOWNLOAD_URL_PREFIX}/${file}" url="${DOWNLOAD_URL_PREFIX}/${file}"
mkdir -p "${download_path}" mkdir -p "${download_path}"
if [[ $(which curl) ]]; then if [[ $(which curl) ]]; then
curl -L "${url}" -o "${download_path}/${file}" curl -L --retry 3 --keepalive-time 2 "${url}" -o "${download_path}/${file}"
elif [[ $(which wget) ]]; then elif [[ $(which wget) ]]; then
wget "${url}" -O "${download_path}/${file}" wget "${url}" -O "${download_path}/${file}"
else else

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
# Copyright 2014 The Kubernetes Authors. # Copyright 2014 The Kubernetes Authors.
# #
@ -113,18 +113,15 @@ fi
function get_latest_version_number { function get_latest_version_number {
local -r latest_url="https://storage.googleapis.com/kubernetes-release/release/stable.txt" local -r latest_url="https://storage.googleapis.com/kubernetes-release/release/stable.txt"
if [[ $(which wget) ]]; then if [[ $(which wget) ]]; then
wget -qO- ${latest_url} wget -qO- "${latest_url}"
elif [[ $(which curl) ]]; then elif [[ $(which curl) ]]; then
curl -Ss ${latest_url} curl -Ssf --retry 3 --keepalive-time 2 "${latest_url}"
else else
echo "Couldn't find curl or wget. Bailing out." >&2 echo "Couldn't find curl or wget. Bailing out." >&2
exit 4 exit 4
fi fi
} }
release=${KUBERNETES_RELEASE:-$(get_latest_version_number)}
release_url="${KUBERNETES_RELEASE_URL}/${release}/kubernetes.tar.gz"
# TODO: remove client checks once kubernetes.tar.gz no longer includes client # TODO: remove client checks once kubernetes.tar.gz no longer includes client
# binaries by default. # binaries by default.
kernel=$(uname -s) kernel=$(uname -s)
@ -165,10 +162,36 @@ case "${machine}" in
esac esac
file=kubernetes.tar.gz file=kubernetes.tar.gz
release=${KUBERNETES_RELEASE:-$(get_latest_version_number)}
release_url="${KUBERNETES_RELEASE_URL}/${release}/${file}"
need_download=true
if [[ -r "${PWD}/${file}" ]]; then
downloaded_version=$(tar -xzOf "${PWD}/${file}" kubernetes/version 2>/dev/null || true)
echo "Found preexisting ${file}, release ${downloaded_version}"
if [[ "${downloaded_version}" == "${release}" ]]; then
echo "Using preexisting kubernetes.tar.gz"
need_download=false
fi
fi
if "${need_download}"; then
echo "Downloading kubernetes release ${release}"
echo " from ${release_url}"
echo " to ${PWD}/${file}"
fi
if [[ -e "${PWD}/kubernetes" ]]; then
# Let's try not to accidentally nuke something that isn't a kubernetes
# release dir.
if [[ ! -f "${PWD}/kubernetes/version" ]]; then
echo "${PWD}/kubernetes exists but does not look like a Kubernetes release."
echo "Aborting!"
exit 5
fi
echo "Will also delete preexisting 'kubernetes' directory."
fi
echo "Downloading kubernetes release ${release}"
echo " from ${release_url}"
echo " to ${PWD}/kubernetes.tar.gz"
if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
echo "Is this ok? [Y]/n" echo "Is this ok? [Y]/n"
read confirm read confirm
@ -178,16 +201,19 @@ if [[ -z "${KUBERNETES_SKIP_CONFIRM-}" ]]; then
fi fi
fi fi
if [[ $(which curl) ]]; then if "${need_download}"; then
curl -L -z ${file} ${release_url} -o ${file} if [[ $(which curl) ]]; then
elif [[ $(which wget) ]]; then curl -L --retry 3 --keepalive-time 2 "${release_url}" -o "${file}"
wget -N ${release_url} elif [[ $(which wget) ]]; then
else wget "${release_url}"
echo "Couldn't find curl or wget. Bailing out." else
exit 1 echo "Couldn't find curl or wget. Bailing out."
exit 1
fi
fi fi
echo "Unpacking kubernetes release ${release}" echo "Unpacking kubernetes release ${release}"
rm -rf "${PWD}/kubernetes"
tar -xzf ${file} tar -xzf ${file}
download_kube_binaries download_kube_binaries