-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GCE startup: Regional release .tar.gz support #22234
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,33 +115,43 @@ function detect-project () { | |
fi | ||
} | ||
|
||
function already-staged() { | ||
local -r file=$1 | ||
local -r newsum=$2 | ||
|
||
[[ -e "${file}.uploaded.sha1" ]] || return 1 | ||
|
||
local oldsum | ||
oldsum=$(cat "${file}.uploaded.sha1") | ||
|
||
[[ "${oldsum}" == "${newsum}" ]] | ||
} | ||
|
||
# Copy a release tar, if we don't already think it's staged in GCS | ||
function copy-if-not-staged() { | ||
# Copy a release tar and its accompanying hash. | ||
function copy-to-staging() { | ||
local -r staging_path=$1 | ||
local -r gs_url=$2 | ||
local -r tar=$3 | ||
local -r hash=$4 | ||
|
||
if already-staged "${tar}" "${hash}"; then | ||
echo "+++ $(basename ${tar}) already staged ('rm ${tar}.uploaded.sha1' to force)" | ||
else | ||
echo "${hash}" > "${tar}.sha1" | ||
gsutil -m -q -h "Cache-Control:private, max-age=0" cp "${tar}" "${tar}.sha1" "${staging_path}" | ||
gsutil -m acl ch -g all:R "${gs_url}" "${gs_url}.sha1" >/dev/null 2>&1 | ||
echo "${hash}" > "${tar}.uploaded.sha1" | ||
echo "+++ $(basename ${tar}) uploaded (sha1 = ${hash})" | ||
echo "${hash}" > "${tar}.sha1" | ||
gsutil -m -q -h "Cache-Control:private, max-age=0" cp "${tar}" "${tar}.sha1" "${staging_path}" | ||
gsutil -m acl ch -g all:R "${gs_url}" "${gs_url}.sha1" >/dev/null 2>&1 | ||
echo "+++ $(basename ${tar}) uploaded (sha1 = ${hash})" | ||
} | ||
|
||
# Given the cluster zone, return the list of regional GCS release | ||
# bucket suffixes for the release in preference order. GCS doesn't | ||
# give us an API for this, so we hardcode it. | ||
# | ||
# Assumed vars: | ||
# REGIONAL_RELEASE | ||
# ZONE | ||
# Vars set: | ||
# PREFERRED_REGION | ||
function set-preferred-region() { | ||
case ${ZONE} in | ||
asia-*) | ||
PREFERRED_REGION=("asia" "us" "eu") | ||
;; | ||
europe-*) | ||
PREFERRED_REGION=("eu" "us" "asia") | ||
;; | ||
*) | ||
PREFERRED_REGION=("us" "eu" "asia") | ||
;; | ||
esac | ||
|
||
if [[ "${RELEASE_REGION_FALLBACK}" != "true" ]]; then | ||
PREFERRED_REGION=( "${PREFERRED_REGION[0]}" ) | ||
fi | ||
} | ||
|
||
|
@@ -155,6 +165,7 @@ function copy-if-not-staged() { | |
# SERVER_BINARY_TAR | ||
# SALT_TAR | ||
# KUBE_MANIFESTS_TAR | ||
# ZONE | ||
# Vars set: | ||
# SERVER_BINARY_TAR_URL | ||
# SERVER_BINARY_TAR_HASH | ||
|
@@ -181,35 +192,59 @@ function upload-server-tars() { | |
# that's probably good enough for now :P | ||
project_hash=${project_hash:0:10} | ||
|
||
local -r staging_bucket="gs://kubernetes-staging-${project_hash}" | ||
set-preferred-region | ||
|
||
# Ensure the bucket is created | ||
if ! gsutil ls "$staging_bucket" > /dev/null 2>&1 ; then | ||
echo "Creating $staging_bucket" | ||
gsutil mb "${staging_bucket}" | ||
SERVER_BINARY_TAR_HASH=$(sha1sum-file "${SERVER_BINARY_TAR}") | ||
SALT_TAR_HASH=$(sha1sum-file "${SALT_TAR}") | ||
if [[ "${OS_DISTRIBUTION}" == "trusty" || "${OS_DISTRIBUTION}" == "coreos" ]]; then | ||
KUBE_MANIFESTS_TAR_HASH=$(sha1sum-file "${KUBE_MANIFESTS_TAR}") | ||
fi | ||
|
||
local -r staging_path="${staging_bucket}/${INSTANCE_PREFIX}-devel" | ||
local server_binary_tar_urls=() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see this being appended to but never used. Am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're missing lines 240-248. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why I didn't see those when doing a Ctrl-F... |
||
local salt_tar_urls=() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
local kube_manifest_tar_urls=() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and this one doesn't seem used at all. |
||
|
||
SERVER_BINARY_TAR_HASH=$(sha1sum-file "${SERVER_BINARY_TAR}") | ||
SALT_TAR_HASH=$(sha1sum-file "${SALT_TAR}") | ||
for region in "${PREFERRED_REGION[@]}"; do | ||
suffix="-${region}" | ||
if [[ "${suffix}" == "-us" ]]; then | ||
suffix="" | ||
fi | ||
local staging_bucket="gs://kubernetes-staging-${project_hash}${suffix}" | ||
|
||
echo "+++ Staging server tars to Google Storage: ${staging_path}" | ||
local server_binary_gs_url="${staging_path}/${SERVER_BINARY_TAR##*/}" | ||
local salt_gs_url="${staging_path}/${SALT_TAR##*/}" | ||
copy-if-not-staged "${staging_path}" "${server_binary_gs_url}" "${SERVER_BINARY_TAR}" "${SERVER_BINARY_TAR_HASH}" | ||
copy-if-not-staged "${staging_path}" "${salt_gs_url}" "${SALT_TAR}" "${SALT_TAR_HASH}" | ||
# Ensure the buckets are created | ||
if ! gsutil ls "${staging_bucket}" > /dev/null 2>&1 ; then | ||
echo "Creating ${staging_bucket}" | ||
gsutil mb -l "${region}" "${staging_bucket}" | ||
fi | ||
|
||
# Convert from gs:// URL to an https:// URL | ||
SERVER_BINARY_TAR_URL="${server_binary_gs_url/gs:\/\//https://storage.googleapis.com/}" | ||
SALT_TAR_URL="${salt_gs_url/gs:\/\//https://storage.googleapis.com/}" | ||
local staging_path="${staging_bucket}/${INSTANCE_PREFIX}-devel" | ||
|
||
echo "+++ Staging server tars to Google Storage: ${staging_path}" | ||
local server_binary_gs_url="${staging_path}/${SERVER_BINARY_TAR##*/}" | ||
local salt_gs_url="${staging_path}/${SALT_TAR##*/}" | ||
copy-to-staging "${staging_path}" "${server_binary_gs_url}" "${SERVER_BINARY_TAR}" "${SERVER_BINARY_TAR_HASH}" | ||
copy-to-staging "${staging_path}" "${salt_gs_url}" "${SALT_TAR}" "${SALT_TAR_HASH}" | ||
|
||
if [[ "${OS_DISTRIBUTION}" == "trusty" || "${OS_DISTRIBUTION}" == "coreos" ]]; then | ||
local kube_manifests_gs_url="${staging_path}/${KUBE_MANIFESTS_TAR##*/}" | ||
KUBE_MANIFESTS_TAR_HASH=$(sha1sum-file "${KUBE_MANIFESTS_TAR}") | ||
copy-if-not-staged "${staging_path}" "${kube_manifests_gs_url}" "${KUBE_MANIFESTS_TAR}" "${KUBE_MANIFESTS_TAR_HASH}" | ||
# Convert from gs:// URL to an https:// URL | ||
KUBE_MANIFESTS_TAR_URL="${kube_manifests_gs_url/gs:\/\//https://storage.googleapis.com/}" | ||
server_binary_tar_urls+=("${server_binary_gs_url/gs:\/\//https://storage.googleapis.com/}") | ||
salt_tar_urls+=("${salt_gs_url/gs:\/\//https://storage.googleapis.com/}") | ||
|
||
if [[ "${OS_DISTRIBUTION}" == "trusty" || "${OS_DISTRIBUTION}" == "coreos" ]]; then | ||
local kube_manifests_gs_url="${staging_path}/${KUBE_MANIFESTS_TAR##*/}" | ||
copy-to-staging "${staging_path}" "${kube_manifests_gs_url}" "${KUBE_MANIFESTS_TAR}" "${KUBE_MANIFESTS_TAR_HASH}" | ||
# Convert from gs:// URL to an https:// URL | ||
kube_manifests_tar_urls+=("${kube_manifests_gs_url/gs:\/\//https://storage.googleapis.com/}") | ||
fi | ||
done | ||
|
||
if [[ "${OS_DISTRIBUTION}" == "trusty" || "${OS_DISTRIBUTION}" == "coreos" ]]; then | ||
# TODO: Support fallback .tar.gz settings on CoreOS/Trusty | ||
SERVER_BINARY_TAR_URL="${server_binary_tar_urls[0]}" | ||
SALT_TAR_URL="${salt_tar_urls[0]}" | ||
KUBE_MANIFESTS_TAR_URL="${kube_manifests_tar_urls[0]}" | ||
else | ||
SERVER_BINARY_TAR_URL=$(join_csv "${server_binary_tar_urls[@]}") | ||
SALT_TAR_URL=$(join_csv "${salt_tar_urls[@]}") | ||
fi | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is the for loop wrapped in a while loop? It seems like this function will run forever now rather than "bust"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can rename it if you want, but the old function actually had the had same behavior. The old behavior is essentially to block inside the
curl
for some period of time doing retries (6, to be precise), then come up for air andecho
so you'd see something in the logs - otherwise it wasn't clear what was failing. I kept the retry behavior because it's relatively sane - it'll pound on one geo for a minute or two and then fall to another in a round-robin. There are more complicated options we can consider at some point, like trying one download of the first URL first, then trying them all with retries in parallel (sort of like how IPv4 to IPv6 is handled).But it's actually always been infinite. There's nothing to do if we can't get the release or the Salt tar down.