Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kube-down more robust for GCE provider #2803

Merged
merged 1 commit into from
Dec 11, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 57 additions & 17 deletions cluster/gce/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ function detect-project () {
echo "Project: $PROJECT (autodetected from gcloud config)"
}


# Take the local tar files and upload them to Google Storage. They will then be
# downloaded by the master as part of the start up script for the master.
#
Expand Down Expand Up @@ -435,40 +434,81 @@ EOF
)
}

# Delete a kubernetes cluster
# Delete a kubernetes cluster.
#
# Assumed vars:
# MASTER_NAME
# INSTANCE_PREFIX
# ZONE
# PROJECT
# This function tears down cluster resources 10 at a time to avoid issuing too many
# API calls and exceeding API quota. It is important to bring down the instances before bringing
# down the firewall rules and routes.
function kube-down {
# Detect the project into $PROJECT
detect-project

echo "Bringing down cluster"
gcloud compute firewall-rules delete \

# First delete the master (if it exists).
gcloud compute instances delete \
--project "${PROJECT}" \
--quiet \
"${MASTER_NAME}-https" &

local minion
for minion in "${MINION_NAMES[@]}"; do
gcloud compute firewall-rules delete \
--delete-disks all \
--zone "${ZONE}" \
"${MASTER_NAME}" || true
# Find out what minions are running.
local -a minions
minions=( $(gcloud compute instances list \
--project "${PROJECT}" --zone "${ZONE}" \
--regexp "${INSTANCE_PREFIX}-minion-[0-9]+" \
| awk 'NR >= 2 { print $1 }') )
# If any minions are running, delete them in batches.
while (( "${#minions[@]}" > 0 )); do
echo Deleting nodes "${minions[*]::10}"
gcloud compute instances delete \
--project "${PROJECT}" \
--quiet \
"${minion}-all" &
--delete-disks all \
--zone "${ZONE}" \
"${minions[@]::10}" || true
minions=( "${minions[@]:10}" )
done

gcloud compute routes delete \
# Delete firewall rule for the master.
gcloud compute firewall-rules delete \
--project "${PROJECT}" \
--quiet \
"${MASTER_NAME}-https" || true

# Delete firewall rules for minions.
# TODO(satnam6502): Adjust this if we move to just one big firewall rule.\
local -a firewall_rules
firewall_rules=( $(gcloud compute firewall-rules list --project "${PROJECT}" \
--regexp "${INSTANCE_PREFIX}-minion-[0-9]+-all" \
| awk 'NR >= 2 { print $1 }') )
while (( "${#firewall_rules[@]}" > 0 )); do
echo Deleting firewall rules "${firewall_rules[*]::10}"
gcloud compute firewall-rules delete \
--project "${PROJECT}" \
--quiet \
"${minion}" &
"${firewall_rules[@]::10}" || true
firewall_rules=( "${firewall_rules[@]:10}" )
done

for minion in "${MASTER_NAME}" "${MINION_NAMES[@]}"; do
gcloud compute instances delete \
# Delete routes.
local -a routes
routes=( $(gcloud compute routes list --project "${PROJECT}" \
--regexp "${INSTANCE_PREFIX}-minion-[0-9]+" | awk 'NR >= 2 { print $1 }') )
while (( "${#routes[@]}" > 0 )); do
echo Deleting routes "${routes[*]::10}"
gcloud compute routes delete \
--project "${PROJECT}" \
--quiet \
--delete-disks all \
--zone "${ZONE}" \
"${minion}" &
"${routes[@]::10}" || true
routes=( "${routes[@]:10}" )
done

wait
}

# Update a kubernetes cluster with latest source
Expand Down