From 6d201c9c57def812995bfa08a000885127d863fc Mon Sep 17 00:00:00 2001 From: gmarek Date: Wed, 22 Jun 2016 14:09:37 +0200 Subject: [PATCH] kube-down deletes instance templates created by the cluster upgrade --- cluster/common.sh | 2 ++ cluster/gce/util.sh | 18 ++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cluster/common.sh b/cluster/common.sh index 6b677575c2..c5d4ed1e47 100755 --- a/cluster/common.sh +++ b/cluster/common.sh @@ -31,12 +31,14 @@ source "${KUBE_ROOT}/cluster/lib/logging.sh" # NOTE This must match the version_regex in build/common.sh # kube::release::parse_and_validate_release_version() KUBE_RELEASE_VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-(beta|alpha)\\.(0|[1-9][0-9]*))?$" +KUBE_RELEASE_VERSION_DASHED_REGEX="v(0|[1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)(-(beta|alpha)-(0|[1-9][0-9]*))?" # KUBE_CI_VERSION_REGEX matches things like "v1.2.3-alpha.4.56+abcdefg" This # # NOTE This must match the version_regex in build/common.sh # kube::release::parse_and_validate_ci_version() KUBE_CI_VERSION_REGEX="^v(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)-(beta|alpha)\\.(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)\\+[-0-9a-z]*)?$" +KUBE_CI_VERSION_DASHED_REGEX="^v(0|[1-9][0-9]*)-(0|[1-9][0-9]*)-(0|[1-9][0-9]*)-(beta|alpha)-(0|[1-9][0-9]*)(-(0|[1-9][0-9]*)\\+[-0-9a-z]*)?" # Generate kubeconfig data for the created cluster. # Assumed vars: diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index 64a0af42e3..845c5598fb 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -967,7 +967,7 @@ function kube-down { # Get the name of the managed instance group template before we delete the # managed instance group. (The name of the managed instance group template may # change during a cluster upgrade.) - local template=$(get-template "${PROJECT}") + local templates=$(get-template "${PROJECT}") for group in ${INSTANCE_GROUPS[@]:-}; do if gcloud compute instance-groups managed describe "${group}" --project "${PROJECT}" --zone "${ZONE}" &>/dev/null; then @@ -984,12 +984,14 @@ function kube-down { echo -e "Failed to delete instance group(s)." >&2 } - if gcloud compute instance-templates describe --project "${PROJECT}" "${template}" &>/dev/null; then - gcloud compute instance-templates delete \ - --project "${PROJECT}" \ - --quiet \ - "${template}" - fi + for template in ${templates[@]:-}; do + if gcloud compute instance-templates describe --project "${PROJECT}" "${template}" &>/dev/null; then + gcloud compute instance-templates delete \ + --project "${PROJECT}" \ + --quiet \ + "${template}" + fi + done # First delete the master (if it exists). if gcloud compute instances describe "${MASTER_NAME}" --zone "${ZONE}" --project "${PROJECT}" &>/dev/null; then @@ -1097,7 +1099,7 @@ function kube-down { # # $1: project function get-template { - gcloud compute instance-templates list "${NODE_INSTANCE_PREFIX}-template" \ + gcloud compute instance-templates list -r "${NODE_INSTANCE_PREFIX}-template(-(${KUBE_RELEASE_VERSION_DASHED_REGEX}|${KUBE_CI_VERSION_DASHED_REGEX}))?" \ --project="${1}" --format='value(name)' }