Skip to content

Commit

Permalink
[fixup 5] add retry and delay to aws cli for bucket to be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 13, 2024
1 parent 13941ba commit f6e5c90
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions .github/scripts/e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ SECRET_NAME="object-storage-access-secret"
NAMESPACE="default"
ADMIN_ACCESS_KEY_ID=D4IT2AWSB588GO5J9T00
ADMIN_SECRET_ACCESS_KEY=UEEu8tYlsOGGrgf4DAiSZD6apVNPUWqRiPG0nTB6
ATTEMPTS=12 # Total AWS CLI attempts (2 minutes / 10 seconds per attempt)
DELAY=10 # Delay between AWS CLI requests attempts in seconds


# Error handling function
error_handler() {
Expand Down Expand Up @@ -101,10 +104,6 @@ sleep 5

log_and_run echo "Verifying bucket creation..."


ATTEMPTS=12 # Total attempts (2 minutes / 10 seconds per attempt)
DELAY=10 # Delay between attempts in seconds

for ((i=1; i<=$ATTEMPTS; i++)); do
log_and_run aws --endpoint-url "$S3_ENDPOINT" s3 ls
BUCKET_FOUND=$(aws --endpoint-url "$S3_ENDPOINT" s3api list-buckets --query "Buckets[?starts_with(Name, '$BUCKET_CLASS_NAME')].Name" --output text)
Expand Down Expand Up @@ -267,19 +266,12 @@ log_and_run kubectl delete -f cosi-examples/bucketclaim-deletion-policy.yaml

log_and_run echo "Verifying bucket deletion with name '$BUCKET_TO_BE_DELETED'..."

for ((i=1; i<=$ATTEMPTS; i++)); do
BUCKET_HEAD_RESULT=$(aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_TO_BE_DELETED" 2>&1 || true)

if [[ "$BUCKET_HEAD_RESULT" == *"Not Found"* ]]; then
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' not found. Bucket deletion successful."
break
fi
BUCKET_HEAD_RESULT=$(aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_TO_BE_DELETED" --retry-mode standard --max-attempts $ATTEMPTS --delay $DELAY 2>&1 || true)

log_and_run echo "Attempt $i: Bucket with name '$BUCKET_TO_BE_DELETED' still exists. Retrying in $DELAY seconds..."
sleep $DELAY
done

if [[ "$BUCKET_HEAD_RESULT" != *"Not Found"* ]]; then
# Check if the bucket has been deleted
if [[ "$BUCKET_HEAD_RESULT" == *"Not Found"* ]]; then
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' not found. Bucket deletion successful."
else
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' was not deleted after $ATTEMPTS attempts."
exit 1
fi
Expand Down

0 comments on commit f6e5c90

Please sign in to comment.