Skip to content

[feat] Support LinodeObjectStorageBucket deletion if forceDeleteBucket is set #780

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

Merged
merged 7 commits into from
Jul 2, 2025

Conversation

AshleyDumaine
Copy link
Collaborator

@AshleyDumaine AshleyDumaine commented Jun 25, 2025

What this PR does / why we need it:
We want to be able to clean up buckets, which is very useful in the cases of test clusters or short-lived / non-production clusters.

This PR adds the missing bucket deletion functionality which will only perform the bucket deletion (including ALL OBJECTS IN THE BUCKET) if LinodeObjectStorageBucket.spec.forceDeleteBucket is set to true (defaults to false). This is leveraged in the etcd-backup flavors via the FORCE_DELETE_OBJ_BUCKETS env var (defaults to false).

Which issue(s) this PR fixes:
Fixes #415

Special notes for your reviewer:

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests
  • adds or updates e2e tests

Testing

  1. Create a cluster that uses the etcd-backup addon like kubeadm-full. Make sure to enable bucket force-deletion:
make local-release # for the updated etcd-backup templates
make local-deploy 
export FORCE_DELETE_OBJ_BUCKETS=true
clusterctl generate cluster test-cluster --kubernetes-version v1.31.8 --flavor kubeadm-full --infrastructure local-linode:v0.0.0 > test-cluster.yaml
# optionally check the test-cluster.yaml
kubectl apply -f test-cluster.yaml
  1. Ensure the test-cluster-etcd-backup bucket shows up in your account
  2. Delete the cluster:
kubectl delete cluster test-cluster
  1. Ensure the test-cluster-etcd-backup bucket disappears from your account

@AshleyDumaine AshleyDumaine force-pushed the force-delete-buckets branch 6 times, most recently from f236605 to 1f20f21 Compare June 25, 2025 21:15
Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 79.39914% with 48 lines in your changes missing coverage. Please review.

Project coverage is 63.50%. Comparing base (ad49dff) to head (4181923).

Files with missing lines Patch % Lines
...controller/linodeobjectstoragebucket_controller.go 47.50% 18 Missing and 3 partials ⚠️
cloud/services/object_storage_buckets.go 75.55% 10 Missing and 1 partial ⚠️
cloud/services/object_storage_objects.go 91.42% 6 Missing and 3 partials ⚠️
cloud/scope/object_storage_bucket.go 83.72% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #780      +/-   ##
==========================================
+ Coverage   62.93%   63.50%   +0.56%     
==========================================
  Files          69       69              
  Lines        6735     6958     +223     
==========================================
+ Hits         4239     4419     +180     
- Misses       2254     2288      +34     
- Partials      242      251       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AshleyDumaine AshleyDumaine force-pushed the force-delete-buckets branch 6 times, most recently from 2b08f30 to 4bfc7e3 Compare June 27, 2025 19:57
@AshleyDumaine AshleyDumaine marked this pull request as ready for review June 27, 2025 20:04
@AshleyDumaine AshleyDumaine force-pushed the force-delete-buckets branch 15 times, most recently from 2f10fdb to 0ac9fb6 Compare July 1, 2025 19:53
}

controllerutil.AddFinalizer(obj, finalizer)
if err := s.Client.Update(ctx, obj); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch instead of update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is following the same logic as https://github.com/linode/cluster-api-provider-linode/blob/main/cloud/scope/common.go#L188-L199 which uses Update but I'm not opposed to using Patch if that works better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just worried about potential conflicts - since this is a different object

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

conflicts are already be handled via retry/requeue on the bucket reconciler but maybe switching to patch would help with that

return err
}

for _, obj := range page.Contents {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we delete page by page? might help avoid cases where the objectsToDelete is too large for a single request

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tchinmai7
tchinmai7 previously approved these changes Jul 1, 2025
eljohnson92
eljohnson92 previously approved these changes Jul 2, 2025
@AshleyDumaine AshleyDumaine dismissed stale reviews from eljohnson92 and tchinmai7 via 6ff6b44 July 2, 2025 15:05
@AshleyDumaine AshleyDumaine force-pushed the force-delete-buckets branch from 6ff6b44 to 614c54b Compare July 2, 2025 15:38
@AshleyDumaine AshleyDumaine merged commit fd878a5 into main Jul 2, 2025
14 checks passed
@AshleyDumaine AshleyDumaine deleted the force-delete-buckets branch July 2, 2025 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow deleting buckets with objects in it
3 participants