diff --git a/cluster/gce/util.sh b/cluster/gce/util.sh index efdd7b18f5a..371f9b63f38 100755 --- a/cluster/gce/util.sh +++ b/cluster/gce/util.sh @@ -769,6 +769,11 @@ function kube-down { echo "Bringing down cluster" set +e # Do not stop on error + # Get the name of the managed instance group template before we delete the + # managed instange group. (The name of the managed instnace group template may + # change during a cluster upgrade.) + local template=$(get-template "${PROJECT}" "${ZONE}" "${NODE_INSTANCE_PREFIX}-group") + # The gcloud APIs don't return machine parseable error codes/retry information. Therefore the best we can # do is parse the output and special case particular responses we are interested in. if gcloud preview managed-instance-groups --project "${PROJECT}" --zone "${ZONE}" describe "${NODE_INSTANCE_PREFIX}-group" &>/dev/null; then @@ -792,11 +797,11 @@ function kube-down { fi fi - if gcloud compute instance-templates describe --project "${PROJECT}" "${NODE_INSTANCE_PREFIX}-template" &>/dev/null; then + if gcloud compute instance-templates describe --project "${PROJECT}" "${template}" &>/dev/null; then gcloud compute instance-templates delete \ --project "${PROJECT}" \ --quiet \ - "${NODE_INSTANCE_PREFIX}-template" + "${template}" fi # First delete the master (if it exists). @@ -886,6 +891,22 @@ function kube-down { set -e } +# Gets the instance template for the managed instance group with the provided +# project, zone, and group name. It echos the template name so that the function +# output can be used. +# +# $1: project +# $2: zone +# $3: managed instance group name +function get-template { + # url is set to https://www.googleapis.com/compute/v1/projects/$1/global/instanceTemplates/