Skip to content

Commit

Permalink
Merge pull request #468 from iamniting/aws
Browse files Browse the repository at this point in the history
hack: cleanup noobaa stale buckets in the aws
  • Loading branch information
openshift-merge-bot[bot] authored Aug 26, 2024
2 parents 71a50ba + c6cedb6 commit cfd16d1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions hack/aws-cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ delete_elb_load_balancer() {
}


# Delete the s3 bucket older than 3 hours
delete_s3_bucket() {
local region=$1
local s3_bucket_name=$2

# Get the creation date of the s3 bucket
creation_date=$(aws s3api list-buckets --region "$region" \
--query "Buckets[?Name=='$s3_bucket_name'].{CreationDate:CreationDate}" --output text)

# If creation_date is empty return
[[ -z "$creation_date" ]] && return

age_hours=$(calculate_age "$creation_date")

# Delete the s3 bucket if older than 3 hours
if [ "$age_hours" -gt 3 ]; then
echo "Deleting the s3 bucket $s3_bucket_name in region $region with creation date $creation_date"
aws s3 rb s3://"$s3_bucket_name" --region "$region" --force
fi
}


for region in us-east-1 us-east-2 us-west-1 us-west-2; do
# List ec2 instances which are running
for instance_id in $(aws ec2 describe-instances --region "$region" \
Expand Down Expand Up @@ -156,4 +178,12 @@ for region in us-east-1 us-east-2 us-west-1 us-west-2; do
# aws ec2 delete-vpc --region "$region" --vpc-id "$vpc_id"
#done

# List s3 buckets starting with nb that belongs to noobaa
for bucket_name in $(aws s3api list-buckets --region "$region" \
--query "Buckets[?starts_with(Name, 'nb')].Name" --output text); do

# Delete the s3 buckets starting with nb
delete_s3_bucket "$region" "$bucket_name"
done

done

0 comments on commit cfd16d1

Please sign in to comment.