-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oss): impl deletions logic for bucket (#308)
Signed-off-by: maslow <[email protected]>
- Loading branch information
Showing
2 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import ( | |
"context" | ||
"errors" | ||
"github.com/labring/laf/controllers/oss/driver" | ||
"github.com/minio/minio-go/v7" | ||
"laf/pkg/util" | ||
"time" | ||
|
||
|
@@ -53,7 +54,6 @@ type BucketReconciler struct { | |
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *BucketReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
_ = log.FromContext(ctx) | ||
|
||
// get the bucket | ||
var bucket ossv1.Bucket | ||
|
@@ -114,14 +114,36 @@ func (r *BucketReconciler) apply(ctx context.Context, bucket *ossv1.Bucket) (ctr | |
_log.Info("Set bucket quota", "bucket", bucket.Name, "quota", bucket.Spec.Storage.String()) | ||
} | ||
|
||
// TODO: reconcile the bucket capacity | ||
// TODO: sync the bucket capacity | ||
|
||
return ctrl.Result{RequeueAfter: time.Minute * 15}, nil | ||
} | ||
|
||
// delete the bucket | ||
func (r *BucketReconciler) delete(ctx context.Context, bucket *ossv1.Bucket) (ctrl.Result, error) { | ||
// TODO: delete the bucket | ||
_log := log.FromContext(ctx) | ||
|
||
// create the minio admin client | ||
mca, err := r.createMinioClient(ctx, bucket) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
// delete the bucket | ||
if err := mca.DeleteBucket(bucket.Name); err != nil { | ||
// reject if the bucket is not exists | ||
if minio.ToErrorResponse(err).Code != "NoSuchBucket" { | ||
return ctrl.Result{}, nil | ||
} | ||
} | ||
|
||
// remove the finalizer | ||
bucket.ObjectMeta.Finalizers = util.RemoveString(bucket.ObjectMeta.Finalizers, bucketFinalizer) | ||
if err := r.Update(ctx, bucket); err != nil { | ||
return ctrl.Result{}, err | ||
} | ||
|
||
_log.Info("Deleted bucket", "bucket", bucket.Name) | ||
return ctrl.Result{}, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters