mirror of https://github.com/k3s-io/k3s
Fix kube-down errors for GCE
parent
2c20c3664c
commit
4c19734b71
|
@ -393,7 +393,7 @@ function create-node-template {
|
||||||
# TODO(mbforbes): To make this really robust, we need to parse the output and
|
# TODO(mbforbes): To make this really robust, we need to parse the output and
|
||||||
# add retries. Just relying on a non-zero exit code doesn't
|
# add retries. Just relying on a non-zero exit code doesn't
|
||||||
# distinguish an ephemeral failed call from a "not-exists".
|
# distinguish an ephemeral failed call from a "not-exists".
|
||||||
if gcloud compute instance-templates describe "$1"; then
|
if gcloud compute instance-templates describe "$1" &>/dev/null; then
|
||||||
echo "Instance template ${1} already exists; continuing." >&2
|
echo "Instance template ${1} already exists; continuing." >&2
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
@ -726,6 +726,7 @@ function kube-down {
|
||||||
|
|
||||||
# The gcloud APIs don't return machine parsable error codes/retry information. Therefore the best we can
|
# The gcloud APIs don't return machine parsable 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 --zone "${ZONE}" describe "${NODE_INSTANCE_PREFIX}-group" &>/dev/null; then
|
||||||
deleteCmdOutput=$(gcloud preview managed-instance-groups --zone "${ZONE}" delete \
|
deleteCmdOutput=$(gcloud preview managed-instance-groups --zone "${ZONE}" delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
|
@ -744,26 +745,33 @@ function kube-down {
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if gcloud compute instance-templates describe "${NODE_INSTANCE_PREFIX}-template" &>/dev/null; then
|
||||||
gcloud compute instance-templates delete \
|
gcloud compute instance-templates delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${NODE_INSTANCE_PREFIX}-template"
|
"${NODE_INSTANCE_PREFIX}-template"
|
||||||
|
fi
|
||||||
|
|
||||||
# First delete the master (if it exists).
|
# First delete the master (if it exists).
|
||||||
|
if gcloud compute instances describe "${MASTER_NAME}" --zone "${ZONE}" &>/dev/null; then
|
||||||
gcloud compute instances delete \
|
gcloud compute instances delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
--delete-disks all \
|
--delete-disks all \
|
||||||
--zone "${ZONE}" \
|
--zone "${ZONE}" \
|
||||||
"${MASTER_NAME}"
|
"${MASTER_NAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
# Delete the master pd (possibly leaked by kube-up if master create failed)
|
# Delete the master pd (possibly leaked by kube-up if master create failed).
|
||||||
|
if gcloud compute disks describe "${MASTER_NAME}"-pd --zone "${ZONE}" &>/dev/null; then
|
||||||
gcloud compute disks delete \
|
gcloud compute disks delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
--zone "${ZONE}" \
|
--zone "${ZONE}" \
|
||||||
"${MASTER_NAME}"-pd
|
"${MASTER_NAME}"-pd
|
||||||
|
fi
|
||||||
|
|
||||||
# Find out what minions are running.
|
# Find out what minions are running.
|
||||||
local -a minions
|
local -a minions
|
||||||
|
@ -784,24 +792,27 @@ function kube-down {
|
||||||
done
|
done
|
||||||
|
|
||||||
# Delete firewall rule for the master.
|
# Delete firewall rule for the master.
|
||||||
|
if gcloud compute firewall-rules describe "${MASTER_NAME}-https" &>/dev/null; then
|
||||||
gcloud compute firewall-rules delete \
|
gcloud compute firewall-rules delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${MASTER_NAME}-https"
|
"${MASTER_NAME}-https"
|
||||||
|
fi
|
||||||
|
|
||||||
# Delete firewall rule for minions.
|
# Delete firewall rule for minions.
|
||||||
|
if gcloud compute firewall-rules describe "${MINION_TAG}-all" &>/dev/null; then
|
||||||
gcloud compute firewall-rules delete \
|
gcloud compute firewall-rules delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${MINION_TAG}-all"
|
"${MINION_TAG}-all"
|
||||||
|
fi
|
||||||
|
|
||||||
# Delete routes.
|
# Delete routes.
|
||||||
local -a routes
|
local -a routes
|
||||||
# Clean up all routes w/ names like "<cluster-name>-<node-GUID>"
|
# Clean up all routes w/ names like "<cluster-name>-minion-<4-char-node-identifier>"
|
||||||
# e.g. "kubernetes-12345678-90ab-cdef-1234-567890abcdef"
|
# e.g. "kubernetes-minion-2pl1"
|
||||||
routes=( $(gcloud compute routes list --project "${PROJECT}" \
|
routes=( $(gcloud compute routes list --project "${PROJECT}" \
|
||||||
--regexp "${INSTANCE_PREFIX}-.{8}-.{4}-.{4}-.{4}-.{12}" | awk 'NR >= 2 { print $1 }') )
|
--regexp "${INSTANCE_PREFIX}-minion-.{4}" | awk 'NR >= 2 { print $1 }') )
|
||||||
routes+=("${MASTER_NAME}")
|
|
||||||
while (( "${#routes[@]}" > 0 )); do
|
while (( "${#routes[@]}" > 0 )); do
|
||||||
echo Deleting routes "${routes[*]::10}"
|
echo Deleting routes "${routes[*]::10}"
|
||||||
gcloud compute routes delete \
|
gcloud compute routes delete \
|
||||||
|
@ -813,11 +824,13 @@ function kube-down {
|
||||||
|
|
||||||
# Delete the master's reserved IP
|
# Delete the master's reserved IP
|
||||||
local REGION=${ZONE%-*}
|
local REGION=${ZONE%-*}
|
||||||
|
if gcloud compute addresses describe "${MASTER_NAME}-ip" --region "${REGION}" &>/dev/null; then
|
||||||
gcloud compute addresses delete \
|
gcloud compute addresses delete \
|
||||||
--project "${PROJECT}" \
|
--project "${PROJECT}" \
|
||||||
--region "${REGION}" \
|
--region "${REGION}" \
|
||||||
--quiet \
|
--quiet \
|
||||||
"${MASTER_NAME}-ip"
|
"${MASTER_NAME}-ip"
|
||||||
|
fi
|
||||||
|
|
||||||
export CONTEXT="${PROJECT}_${INSTANCE_PREFIX}"
|
export CONTEXT="${PROJECT}_${INSTANCE_PREFIX}"
|
||||||
clear-kubeconfig
|
clear-kubeconfig
|
||||||
|
|
Loading…
Reference in New Issue