-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COSI-25, COSI-32: Implement Delete Bucket API, Add Tests, and Enhance CI #61
Conversation
9c7bce3
to
4652178
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
@@ Coverage Diff @@
## main #61 +/- ##
==========================================
+ Coverage 93.12% 93.43% +0.31%
==========================================
Files 9 9
Lines 611 640 +29
==========================================
+ Hits 569 598 +29
Misses 36 36
Partials 6 6 |
a2113ff
to
e45538a
Compare
.github/scripts/e2e_tests.sh
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cli has a command to wait for a condition with retries: aws s3api wait ...
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/wait/bucket-not-exists.html
And you can configure the retries with max_attempts
and retry_mode
: https://docs.aws.amazon.com/cli/latest/topic/config-vars.html#retry-configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the suggestion.
Unfortunately, the list-buckets API does not support this functionality. Since we only have the prefix Bucket_CLASS_NAME and not the exact bucket name, it cannot be used in this case.
- --retry and --delay: These options are not natively supported by the aws s3api list-buckets command. You would need to implement a custom retry logic, as demonstrated in the script above.
- aws s3api wait: This command is ideal for waiting on conditions such as bucket existence. However, it requires an exact bucket name and does not work with prefixes.
That being said, I have added support for retry logic in other cases, such as checking if a bucket is being deleted (when we know the exact bucket name) and verifying a user is being deleted (when we know the user’s name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually had to change it a bit more, so used the AWS variables instead of --retry and --delay as its not supported for every API.
BUCKET_HEAD_RESULT=$(log_and_run AWS_MAX_ATTEMPTS=$ATTEMPTS AWS_RETRY_DELAY=$DELAY aws --endpoint-url "$S3_ENDPOINT" s3api head`-bucket --bucket "$BUCKET_TO_BE_DELETED" --profile iam 2>&1 || true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for multiple comments, had some CI issues
FInally adding the passing commit link here for reference: 7ff62b3
spec: | ||
bucketClassName: delete-bucket-class | ||
protocols: | ||
- s3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- s3 | |
- s3 |
indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its up for debate, I have usually seen (most common) without indent when using -
.
I would prefer to follow the industry norm here, unless we have a specific standard or reason.
Technically both are correct though.
klog.ErrorS(err, "Failed to get bucket object from kubernetes", "bucketName", bucketName) | ||
return nil, status.Error(codes.Internal, "failed to get bucket object from kubernetes") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is a recurring pattern to both log and return an error, it could benefit from a small helper that uses the same message and argument list for the log and the error, so by using a variable argument list, you could do here for example:
return loggedError(err, "failed to get ...", "bucketName", bucketName)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not focusing on logs too much right now, as we will change the logging mechanism next sprint. We will use OTel SDK for logs, which will probably remove all these logs
I added your comment in this ticket
e27a1d2
to
07a2202
Compare
- Gets parameters from the bucket object to get config for IAM client - Adds methods to IAM client to delete user, inline policy and keys - If inline policy doesn't exist, logs a warning and continues
e45538a
to
bc73aba
Compare
rebased to main and pushed, didn't change anything yet |
103fd74
to
7ff62b3
Compare
- Only delete bucket if it can be deleted by a simple delete operation. - If the bucket deletion operation gives an error for any reason, the bucket will not be deleted. Example: If objects are present in the bucket.
This commit refactors the test file by: - Extracting common test data and parameters into helper functions - Reducing repetitive code in BeforeEach/AfterEach blocks - Using local variables or dereferencing pointers to avoid addressability errors for string constants - Improving readability and maintainability of the tests - used AWS CLI delay and retries to check user and bucket deletion
7ff62b3
to
4bb5259
Compare
Update: Rebased, and squashed commits I will merge the PR. |
Note for reviewers: Reviewing commit by commit is easier, as we have a commit story.
Summary
This PR implements the DeleteBucket API and adds comprehensive tests and CI improvements:
Changes:
Impact:
• Improves DeleteBucket reliability and test coverage.
• Enhances CI workflows and test maintainability.
Tickets: COSI-25, COSI-32