Skip to content

Commit

Permalink
COSI-32: add-e2e-tests-for-delete-bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
anurag4DSB committed Dec 11, 2024
1 parent 056509d commit 537fc6c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/scripts/cleanup_cosi_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ log_and_run kubectl delete -f cosi-examples/bucketaccessclass.yaml --all || { ec
log_and_run echo "Deleting Bucket Class and Bucket Claim..."
log_and_run kubectl delete -f cosi-examples/bucketclass.yaml || { echo "Bucket Class not found." | tee -a "$LOG_FILE"; }
log_and_run kubectl delete -f cosi-examples/bucketclaim.yaml || { echo "Bucket Claim not found." | tee -a "$LOG_FILE"; }
log_and_run kubectl delete -f cosi-examples/bucketclass-delete-on-claim-removal.yaml || { echo "Bucket Class not found." | tee -a "$LOG_FILE"; }

log_and_run echo "Deleting s3-secret-for-cosi secret..."
log_and_run kubectl delete secret s3-secret-for-cosi --namespace=default || { echo "Secret s3-secret-for-cosi not found." | tee -a "$LOG_FILE"; }
Expand Down
58 changes: 58 additions & 0 deletions .github/scripts/e2e_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,62 @@ if [[ "$USER_EXISTS" != *"NoSuchEntity"* ]]; then
exit 1
fi

# Step 13: Test deletion bucket with deletion policy set

log_and_run echo "Applying Bucket Class with deletion policy and respective Bucket Claim..."
log_and_run kubectl apply -f cosi-examples/bucketclass-delete-on-claim-removal.yaml
log_and_run kubectl apply -f cosi-examples/bucketclaim-delete-on-claim-removal.yaml

log_and_run echo "Listing all S3 buckets before deletion..."
log_and_run aws s3 ls --endpoint-url "$S3_ENDPOINT"

BUCKET_CLASS_NAME="bucket-class-delete-on-claim-removal"

log_and_run echo "Verifying bucket creation with prefix '$BUCKET_CLASS_NAME'..."

for ((i=1; i<=$ATTEMPTS; i++)); do
log_and_run aws --endpoint-url "$S3_ENDPOINT" s3 ls
BUCKET_TO_BE_DELETED=$(aws --endpoint-url "$S3_ENDPOINT" s3api list-buckets --query "Buckets[?starts_with(Name, '$BUCKET_CLASS_NAME')].Name" --output text)

if [ -n "$BUCKET_TO_BE_DELETED" ]; then
log_and_run echo "Bucket created with prefix '$BUCKET_CLASS_NAME': $BUCKET_TO_BE_DELETED"
break
else
log_and_run echo "Attempt $i: Bucket with prefix '$BUCKET_CLASS_NAME' not found. Retrying in $DELAY seconds..."
sleep $DELAY
fi
done

if [ -z "$BUCKET_TO_BE_DELETED" ]; then
log_and_run echo "Bucket with prefix '$BUCKET_CLASS_NAME' was not created."
exit 1
fi

log_and_run echo "Deleting Bucket Claim..."
log_and_run kubectl delete -f cosi-examples/bucketclaim-deletion-policy.yaml

# Check if the bucket with name $BUCKET_TO_BE_DELETED exists by doing a head bucket.
# If bucket exists, retry with ATTEMPTS and DELAY. If bucket is not found, test success.

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
else
log_and_run echo "Attempt $i: Bucket with name '$BUCKET_TO_BE_DELETED' still exists. Retrying in $DELAY seconds..."
sleep $DELAY
fi
done

if [[ "$BUCKET_HEAD_RESULT" != *"Not Found"* ]]; then
log_and_run echo "Bucket with name '$BUCKET_TO_BE_DELETED' was not deleted after $ATTEMPTS attempts."
exit 1
fi

log_and_run echo "Bucket deletion verified successfully."

log_and_run echo "All verifications for object-storage-access-secret passed successfully."
8 changes: 8 additions & 0 deletions cosi-examples/bucketclaim-delete-on-claim-removal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
kind: BucketClaim
apiVersion: objectstorage.k8s.io/v1alpha1
metadata:
name: bucket-claim-auto-delete-s3-bucket
spec:
bucketClassName: bucket-class-delete-on-claim-removal
protocols:
- s3
9 changes: 9 additions & 0 deletions cosi-examples/bucketclass-delete-on-claim-removal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: BucketClass
apiVersion: objectstorage.k8s.io/v1alpha1
metadata:
name: bucket-class-delete-on-claim-removal
driverName: cosi.scality.com
deletionPolicy: Delete
parameters:
objectStorageSecretName: s3-secret-for-cosi
objectStorageSecretNamespace: default

0 comments on commit 537fc6c

Please sign in to comment.