trim mig template name if it's over the gce validated length limit

This commit is contained in:
Mike Danese 2015-09-28 16:22:13 -07:00
parent 26c51881ca
commit 05355145b9
5 changed files with 39 additions and 40 deletions

View File

@ -144,15 +144,10 @@ function create-master-instance {
# TODO(dawnchen): Check $CONTAINER_RUNTIME to decide which
# cloud_config yaml file should be passed
# TODO(zmerlynn): Make $1 required.
# TODO(zmerlynn): Document required vars (for this and call chain).
# $1 version
# $1: template name (required)
function create-node-instance-template {
local suffix=""
if [[ -n ${1:-} ]]; then
suffix="-${1}"
fi
create-node-template "${NODE_INSTANCE_PREFIX}-template${suffix}" "${scope_flags}" \
local template_name="$1"
create-node-template "$template_name" "${scope_flags}" \
"kube-env=${KUBE_TEMP}/node-kube-env.yaml" \
"user-data=${KUBE_ROOT}/cluster/gce/coreos/node.yaml"
}

View File

@ -155,15 +155,10 @@ function create-master-instance {
--disk "name=${MASTER_NAME}-pd,device-name=master-pd,mode=rw,boot=no,auto-delete=no"
}
# TODO(zmerlynn): Make $1 required.
# TODO(zmerlynn): Document required vars (for this and call chain).
# $1 version
# $1: template name (required)
function create-node-instance-template {
local suffix=""
if [[ -n ${1:-} ]]; then
suffix="-${1}"
fi
create-node-template "${NODE_INSTANCE_PREFIX}-template${suffix}" "${scope_flags}" \
local template_name="$1"
create-node-template "$template_name" "${scope_flags}" \
"startup-script=${KUBE_ROOT}/cluster/gce/configure-vm.sh" \
"kube-env=${KUBE_TEMP}/node-kube-env.yaml"
}

11
cluster/gce/trusty/helper.sh Normal file → Executable file
View File

@ -27,15 +27,10 @@
# create-node-instance-template function to use Ubuntu.
source "${KUBE_ROOT}/cluster/gce/debian/helper.sh"
# TODO(andyzheng0831): Make $1 required.
# TODO(andyzheng0831): Document required vars (for this and call chain).
# $1 version
# $1: template name (required)
function create-node-instance-template {
local suffix=""
if [[ -n ${1:-} ]]; then
suffix="-${1}"
fi
create-node-template "${NODE_INSTANCE_PREFIX}-template${suffix}" "${scope_flags[*]}" \
local template_name="$1"
create-node-template "$template_name" "${scope_flags[*]}" \
"kube-env=${KUBE_TEMP}/node-kube-env.yaml" \
"user-data=${KUBE_ROOT}/cluster/gce/trusty/node.yaml"
}

View File

@ -200,9 +200,10 @@ function prepare-node-upgrade() {
# TODO(zmerlynn): Get configure-vm script from ${version}. (Must plumb this
# through all create-node-instance-template implementations).
create-node-instance-template ${SANITIZED_VERSION}
local template_name=$(get-template-name-from-version ${SANITIZED_VERSION})
create-node-instance-template "${template_name}"
# The following is echo'd so that callers can get the template name.
echo "${NODE_INSTANCE_PREFIX}-template-${SANITIZED_VERSION}"
echo $template_name
echo "== Finished preparing node upgrade (to ${KUBE_VERSION}). ==" >&2
}
@ -220,12 +221,13 @@ function do-node-upgrade() {
if [[ "${exists}" != "0" ]]; then
subgroup="alpha compute"
fi
local template_name=$(get-template-name-from-version ${SANITIZED_VERSION})
gcloud ${subgroup} rolling-updates \
--project="${PROJECT}" \
--zone="${ZONE}" \
start \
--group="${NODE_INSTANCE_PREFIX}-group" \
--template="${NODE_INSTANCE_PREFIX}-template-${SANITIZED_VERSION}" \
--template="${template_name}" \
--instance-startup-timeout=300s \
--max-num-concurrent-instances=1 \
--max-num-failed-instances=0 \

View File

@ -357,6 +357,12 @@ function create-firewall-rule {
done
}
# $1: version (required)
function get-template-name-from-version {
# trim template name to pass gce name validation
echo "${NODE_INSTANCE_PREFIX}-template-${1}" | cut -c 1-63 | sed 's/[\.\+]/-/g;s/-*$//g'
}
# Robustly try to create an instance template.
# $1: The name of the instance template.
# $2: The scopes flag.
@ -364,14 +370,15 @@ function create-firewall-rule {
# $4: The kube-env metadata.
function create-node-template {
detect-project
local template_name="$1"
# First, ensure the template doesn't exist.
# TODO(zmerlynn): To make this really robust, we need to parse the output and
# add retries. Just relying on a non-zero exit code doesn't
# distinguish an ephemeral failed call from a "not-exists".
if gcloud compute instance-templates describe "$1" --project "${PROJECT}" &>/dev/null; then
if gcloud compute instance-templates describe "$template_name" --project "${PROJECT}" &>/dev/null; then
echo "Instance template ${1} already exists; deleting." >&2
if ! gcloud compute instance-templates delete "$1" --project "${PROJECT}" &>/dev/null; then
if ! gcloud compute instance-templates delete "$template_name" --project "${PROJECT}" &>/dev/null; then
echo -e "${color_yellow}Failed to delete existing instance template${color_norm}" >&2
exit 2
fi
@ -384,7 +391,7 @@ function create-node-template {
fi
while true; do
echo "Attempt ${attempt} to create ${1}" >&2
if ! gcloud compute instance-templates create "$1" \
if ! gcloud compute instance-templates create "$template_name" \
--project "${PROJECT}" \
--machine-type "${MINION_SIZE}" \
--boot-disk-type "${MINION_DISK_TYPE}" \
@ -398,10 +405,10 @@ function create-node-template {
--can-ip-forward \
--metadata-from-file "$3","$4" >&2; then
if (( attempt > 5 )); then
echo -e "${color_red}Failed to create instance template $1 ${color_norm}" >&2
echo -e "${color_red}Failed to create instance template $template_name ${color_norm}" >&2
exit 2
fi
echo -e "${color_yellow}Attempt ${attempt} failed to create instance template $1. Retrying.${color_norm}" >&2
echo -e "${color_yellow}Attempt ${attempt} failed to create instance template $template_name. Retrying.${color_norm}" >&2
attempt=$(($attempt+1))
else
break
@ -675,7 +682,10 @@ function kube-up {
fi
write-node-env
create-node-instance-template
local template_name="${NODE_INSTANCE_PREFIX}-template"
create-node-instance-template $template_name
gcloud compute instance-groups managed \
create "${NODE_INSTANCE_PREFIX}-group" \
@ -683,7 +693,7 @@ function kube-up {
--zone "${ZONE}" \
--base-instance-name "${NODE_INSTANCE_PREFIX}" \
--size "${NUM_MINIONS}" \
--template "${NODE_INSTANCE_PREFIX}-template" || true;
--template "$template_name" || true;
gcloud compute instance-groups managed wait-until-stable \
"${NODE_INSTANCE_PREFIX}-group" \
--zone "${ZONE}" \
@ -1046,31 +1056,33 @@ function prepare-push() {
# Ugly hack: Since it is not possible to delete instance-template that is currently
# being used, create a temp one, then delete the old one and recreate it once again.
create-node-instance-template "tmp"
local tmp_template_name="${NODE_INSTANCE_PREFIX}-template-tmp"
create-node-instance-template $tmp_template_name
local template_name="${NODE_INSTANCE_PREFIX}-template"
gcloud compute instance-groups managed \
set-instance-template "${NODE_INSTANCE_PREFIX}-group" \
--template "${NODE_INSTANCE_PREFIX}-template-tmp" \
--template "$tmp_template_name" \
--zone "${ZONE}" \
--project "${PROJECT}" || true;
gcloud compute instance-templates delete \
--project "${PROJECT}" \
--quiet \
"${NODE_INSTANCE_PREFIX}-template" || true
"$template_name" || true
create-node-instance-template
create-node-instance-template "$template_name"
gcloud compute instance-groups managed \
set-instance-template "${NODE_INSTANCE_PREFIX}-group" \
--template "${NODE_INSTANCE_PREFIX}-template" \
--template "$template_name" \
--zone "${ZONE}" \
--project "${PROJECT}" || true;
gcloud compute instance-templates delete \
--project "${PROJECT}" \
--quiet \
"${NODE_INSTANCE_PREFIX}-template-tmp" || true
"$tmp_template_name" || true
fi
}