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

Add shell script for deleting hypershift workshop student clusters #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions scripts/hcp_destroy_cluster_loop.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash

REGION="us-west-2"
BASE_DOMAIN="aws.validatedpatterns.io"
ROLE_ARN="arn:aws:iam::296267305927:role/hypershift_cli_role"
STS_CREDS="$HOME/sts-creds/sts-creds.json"

for i in {1..10}; do
CLUSTER="studentcluster-$i"

echo "Refreshing STS credentials..."
aws sts get-session-token --output json > "$STS_CREDS"

if [ $? -ne 0 ]; then
echo "Failed to refresh STS credentials. Aborting..."
exit 1
fi

echo "Destroying cluster: $CLUSTER in region: $REGION"

trap "echo 'Aborting script...'; exit 1" SIGINT

RETRIES=3
while [ $RETRIES -gt 0 ]; do
hcp destroy cluster aws --destroy-cloud-resources \
--name "$CLUSTER" \
--infra-id "$CLUSTER" \
--region="$REGION" \
--sts-creds "$STS_CREDS" \
--base-domain "$BASE_DOMAIN" \
--role-arn "$ROLE_ARN"

if [ $? -eq 0 ]; then
echo "Successfully destroyed $CLUSTER"
break
else
echo "Failed to destroy $CLUSTER, retrying... ($((RETRIES-1)) attempts left)"
((RETRIES--))
fi
done

if [ $RETRIES -eq 0 ]; then
echo "Failed to destroy $CLUSTER after multiple attempts. Moving to the next cluster..."
fi
done