Skip to content

Commit 6fbbc55

Browse files
committed
chore: clean up delete
1 parent 9cb487e commit 6fbbc55

File tree

1 file changed

+19
-79
lines changed

1 file changed

+19
-79
lines changed

tests/uat/aws/delete-eks-cluster.sh

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,87 +20,27 @@ source "${SCRIPT_DIR}/../common.sh"
2020

2121
CLUSTER_NAME="${CLUSTER_NAME:-nvsentinel-uat}"
2222
AWS_REGION="${AWS_REGION:-us-east-1}"
23-
GPU_AVAILABILITY_ZONE="${GPU_AVAILABILITY_ZONE:-e}"
2423

25-
delete_gpu_nodegroup() {
26-
log "Deleting GPU node group..."
2724

28-
if ! eksctl delete nodegroup \
29-
--cluster="$CLUSTER_NAME" \
30-
--name="gpu-nodes" \
31-
--region="$AWS_REGION" \
32-
--wait 2>/dev/null; then
33-
log "GPU node group not found or already deleted"
34-
else
35-
log "GPU node group deleted ✓"
36-
fi
37-
}
25+
# Get stacks in reverse dependency order
26+
log "Deleting CloudFormation stacks for $CLUSTER_NAME ..."
27+
stacks=$(aws cloudformation list-stacks \
28+
--region "$AWS_REGION" \
29+
--query "StackSummaries[?starts_with(StackName, 'eksctl-${CLUSTER_NAME}') && StackStatus!='DELETE_COMPLETE'].StackName" \
30+
--output text)
3831

39-
delete_gpu_subnet() {
40-
log "Checking for GPU subnet..."
41-
42-
local vpc_id
43-
vpc_id=$(aws eks describe-cluster \
44-
--name "$CLUSTER_NAME" \
45-
--region "$AWS_REGION" \
46-
--query 'cluster.resourcesVpcConfig.vpcId' \
47-
--output text 2>/dev/null || echo "")
48-
49-
if [[ -z "$vpc_id" || "$vpc_id" == "None" ]]; then
50-
log "Could not get VPC ID, skipping GPU subnet deletion"
51-
return 0
52-
fi
53-
54-
local az="${AWS_REGION}${GPU_AVAILABILITY_ZONE}"
55-
56-
local gpu_subnet_id
57-
gpu_subnet_id=$(aws ec2 describe-subnets \
58-
--filters "Name=vpc-id,Values=$vpc_id" \
59-
"Name=availability-zone,Values=$az" \
60-
"Name=tag:kubernetes.io/cluster/${CLUSTER_NAME},Values=owned" \
61-
--query 'Subnets[0].SubnetId' \
62-
--output text \
63-
--region "$AWS_REGION" 2>/dev/null || echo "None")
64-
65-
if [[ "$gpu_subnet_id" == "None" || -z "$gpu_subnet_id" ]]; then
66-
log "No GPU subnet found, skipping"
67-
return 0
68-
fi
69-
70-
log "Deleting GPU subnet: $gpu_subnet_id"
71-
if ! aws ec2 delete-subnet \
72-
--subnet-id "$gpu_subnet_id" \
73-
--region "$AWS_REGION" 2>/dev/null; then
74-
log "WARNING: Failed to delete GPU subnet, it may have dependencies"
75-
else
76-
log "GPU subnet deleted ✓"
77-
fi
78-
}
32+
# If no stacks found, exit
33+
if [ -z "$stacks" ]; then
34+
log "No CloudFormation stacks found for $CLUSTER_NAME."
35+
exit 0
36+
fi
7937

80-
delete_cluster() {
81-
log "Deleting EKS cluster: $CLUSTER_NAME in region $AWS_REGION..."
82-
83-
if ! eksctl delete cluster --name "$CLUSTER_NAME" --region "$AWS_REGION" --wait; then
84-
log "WARNING: eksctl delete failed. The cluster may be partially deleted."
85-
log "Check AWS Console for remaining resources:"
86-
log " - CloudFormation stacks: https://console.aws.amazon.com/cloudformation"
87-
log " - EKS clusters: https://console.aws.amazon.com/eks"
88-
log " - EC2 instances: https://console.aws.amazon.com/ec2"
89-
return 1
90-
fi
91-
92-
log "EKS cluster deleted successfully ✓"
93-
}
94-
95-
main() {
96-
log "Starting EKS cluster deletion for NVSentinel UAT..."
97-
98-
delete_gpu_nodegroup
99-
delete_gpu_subnet
100-
delete_cluster
101-
102-
103-
log "EKS cluster deleted successfully ✓"
104-
}
38+
# Delete stacks
39+
for stack in $stacks; do
40+
log "Deleting stack: $stack (force delete)"
41+
aws cloudformation delete-stack \
42+
--region "$AWS_REGION" \
43+
--stack-name "$stack" || log "WARNING: Failed to initiate deletion of $stack"
44+
done
10545

106-
main "$@"
46+
log "All stack deletions initiated (AWS will continue in background)"

0 commit comments

Comments
 (0)