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 7ff62b3
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 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,23 +266,20 @@ 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
# Check if the bucket has been deleted
log_and_run aws s3 ls --endpoint-url "$S3_ENDPOINT"
AWS_MAX_ATTEMPTS=$ATTEMPTS
AWS_RETRY_DELAY=$DELAY
# Run head-bucket to check if the bucket has been deleted
BUCKET_HEAD_RESULT="$(log_and_run aws --endpoint-url "$S3_ENDPOINT" s3api head-bucket --bucket "$BUCKET_TO_BE_DELETED" 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
# Log the actual error result for debugging purposes
log_and_run echo "head-bucket result: $BUCKET_HEAD_RESULT"

if [[ "$BUCKET_HEAD_RESULT" != *"Not Found"* ]]; then
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' was not deleted after $ATTEMPTS attempts."
# Check if the result contains the "Not Found" error message
if [[ "$BUCKET_HEAD_RESULT" == *"Not Found"* ]]; then
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' was successfully deleted (Not Found error)."
else
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' was not deleted after $ATTEMPTS attempts. Error: $BUCKET_HEAD_RESULT"
exit 1
fi

log_and_run echo "Bucket deletion verified successfully."

log_and_run echo "All verifications for object-storage-access-secret passed successfully."

0 comments on commit 7ff62b3

Please sign in to comment.