From b78691a56704884d1da0544a2779b8f42b45d3f1 Mon Sep 17 00:00:00 2001 From: xzy Date: Thu, 26 Sep 2024 17:49:03 +0800 Subject: [PATCH] sync resourcequota objectstorage/size status used (#5102) --- .../controllers/objectstorageuser_controller.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controllers/objectstorage/controllers/objectstorageuser_controller.go b/controllers/objectstorage/controllers/objectstorageuser_controller.go index adc3ccd0f28..722d912da05 100644 --- a/controllers/objectstorage/controllers/objectstorageuser_controller.go +++ b/controllers/objectstorage/controllers/objectstorageuser_controller.go @@ -20,6 +20,7 @@ import ( "bytes" "context" "fmt" + "strconv" "strings" "time" @@ -148,6 +149,7 @@ func (r *ObjectStorageUserReconciler) Reconcile(ctx context.Context, req ctrl.Re } quota := resourceQuota.Spec.Hard.Name(ResourceObjectStorageSize, resource.BinarySI) + used := resourceQuota.Status.Used.Name(ResourceObjectStorageSize, resource.BinarySI) updated := r.initObjectStorageUser(user, username, quota.Value()) @@ -201,6 +203,14 @@ func (r *ObjectStorageUserReconciler) Reconcile(ctx context.Context, req ctrl.Re updated = true } + if used.Value() != size { + resourceQuota.Status.Used[ResourceObjectStorageSize] = resource.MustParse(strconv.FormatInt(size, 10)) + if err := r.Status().Update(ctx, resourceQuota); err != nil { + r.Logger.Error(err, "failed to update status", "name", resourceQuota.Name, "namespace", userNamespace) + return ctrl.Result{}, err + } + } + if user.Status.ObjectsCount != objectsCount { user.Status.ObjectsCount = objectsCount updated = true