From 7ff62b31272d4f8bc89da66c3fc1784179183771 Mon Sep 17 00:00:00 2001 From: Anurag Mittal Date: Fri, 13 Dec 2024 13:34:46 +0100 Subject: [PATCH] [fixup 5] add retry and delay to aws cli for bucket to be deleted --- .github/scripts/e2e_tests.sh | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/.github/scripts/e2e_tests.sh b/.github/scripts/e2e_tests.sh index 47fd6941..e0e5b89a 100755 --- a/.github/scripts/e2e_tests.sh +++ b/.github/scripts/e2e_tests.sh @@ -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() { @@ -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) @@ -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."