mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #11018 from mbforbes/gceCleanupTemplate
Robustly cleanup MIG template on GCE teardown
This commit is contained in:
commit
56c781f4ce
@ -769,6 +769,11 @@ function kube-down {
|
|||||||
echo "Bringing down cluster"
|
echo "Bringing down cluster"
|
||||||
set +e # Do not stop on error
|
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
|
# 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.
|
# 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
|
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
|
||||||
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 \
|
gcloud compute instance-templates delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${NODE_INSTANCE_PREFIX}-template"
|
"${template}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# First delete the master (if it exists).
|
# First delete the master (if it exists).
|
||||||
@ -886,6 +891,22 @@ function kube-down {
|
|||||||
set -e
|
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/<template>
|
||||||
|
local url=$(gcloud preview managed-instance-groups --project="${1}" --zone="${2}" describe "${3}" | grep instanceTemplate)
|
||||||
|
# template is set to <template> (the pattern strips off all but last slash)
|
||||||
|
local template="${url##*/}"
|
||||||
|
echo "${template}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Checks if there are any present resources related kubernetes cluster.
|
# Checks if there are any present resources related kubernetes cluster.
|
||||||
#
|
#
|
||||||
# Assumed vars:
|
# Assumed vars:
|
||||||
@ -894,7 +915,6 @@ function kube-down {
|
|||||||
# ZONE
|
# ZONE
|
||||||
# Vars set:
|
# Vars set:
|
||||||
# KUBE_RESOURCE_FOUND
|
# KUBE_RESOURCE_FOUND
|
||||||
|
|
||||||
function check-resources {
|
function check-resources {
|
||||||
detect-project
|
detect-project
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user