diff --git a/controllers/account/go.mod b/controllers/account/go.mod index ea8c2580a8e..f7362efa431 100644 --- a/controllers/account/go.mod +++ b/controllers/account/go.mod @@ -50,7 +50,6 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/clbanning/mxj/v2 v2.5.7 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.8.0 // indirect diff --git a/controllers/job/init/go.mod b/controllers/job/init/go.mod index 7a3c5f8810e..482dcf1042c 100644 --- a/controllers/job/init/go.mod +++ b/controllers/job/init/go.mod @@ -17,7 +17,6 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.8.0 // indirect diff --git a/controllers/license/go.mod b/controllers/license/go.mod index 562ed596360..52f23c676a7 100644 --- a/controllers/license/go.mod +++ b/controllers/license/go.mod @@ -23,7 +23,6 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect github.com/evanphx/json-patch/v5 v5.8.0 // indirect diff --git a/controllers/objectstorage/controllers/objectstorageuser_controller.go b/controllers/objectstorage/controllers/objectstorageuser_controller.go index 0b85da99b4d..3f37abe11c3 100644 --- a/controllers/objectstorage/controllers/objectstorageuser_controller.go +++ b/controllers/objectstorage/controllers/objectstorageuser_controller.go @@ -20,7 +20,6 @@ import ( "bytes" "context" "fmt" - "strconv" "strings" "time" @@ -219,8 +218,10 @@ 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)) + stringSize := ConvertBytesToString(size) + + if used.String() != stringSize { + resourceQuota.Status.Used[ResourceObjectStorageSize] = resource.MustParse(stringSize) 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 @@ -433,6 +434,30 @@ func (r *ObjectStorageUserReconciler) initObjectStorageKeySecret(secret *corev1. return updated } +func ConvertBytesToString(bytes int64) string { + var unit string + var value float64 + + switch { + case bytes >= 1<<40: // 1 TiB + value = float64(bytes) / (1 << 40) + unit = "Ti" + case bytes >= 1<<30: // 1 GiB + value = float64(bytes) / (1 << 30) + unit = "Gi" + case bytes >= 1<<20: // 1 MiB + value = float64(bytes) / (1 << 20) + unit = "Mi" + case bytes >= 1<<10: // 1 KiB + value = float64(bytes) / (1 << 10) + unit = "Ki" + default: + return fmt.Sprintf("%d", bytes) + } + + return fmt.Sprintf("%.0f%s", value, unit) +} + // SetupWithManager sets up the controller with the Manager. func (r *ObjectStorageUserReconciler) SetupWithManager(mgr ctrl.Manager) error { r.Logger = ctrl.Log.WithName("object-storage-user-controller") diff --git a/controllers/pkg/go.mod b/controllers/pkg/go.mod index 4151613e102..d826f798637 100644 --- a/controllers/pkg/go.mod +++ b/controllers/pkg/go.mod @@ -20,7 +20,6 @@ replace ( require ( github.com/containers/storage v1.50.2 - github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 github.com/dustin/go-humanize v1.0.1 github.com/go-logr/logr v1.4.1 github.com/golang-jwt/jwt/v4 v4.5.0 diff --git a/controllers/pkg/go.sum b/controllers/pkg/go.sum index 5af680fa90a..568738cb47f 100644 --- a/controllers/pkg/go.sum +++ b/controllers/pkg/go.sum @@ -10,8 +10,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 h1:4GI5eviCwbPxDE311KryyyPUTO7IDVyHGp3Iyl+fEZY= -github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49/go.mod h1:sbm1DAsayX+XsXCOC2CFAAU9JZhX0SPKwnybDjSd0Ls= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= diff --git a/controllers/resources/go.mod b/controllers/resources/go.mod index 8dfe62ca9e6..6f938e03aa9 100644 --- a/controllers/resources/go.mod +++ b/controllers/resources/go.mod @@ -32,7 +32,6 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.8.0 // indirect @@ -61,7 +60,6 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.17.7 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect - github.com/labring/sealos/controllers/account v0.0.0 // indirect github.com/mailru/easyjson v0.7.7 // indirect github.com/matoous/go-nanoid/v2 v2.0.0 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect @@ -98,8 +96,6 @@ require ( golang.org/x/time v0.5.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/appengine v1.6.8 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240125205218-1f4bbc51befe // indirect - google.golang.org/grpc v1.61.0 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect @@ -120,7 +116,6 @@ require ( ) replace ( - github.com/labring/sealos/controllers/account => ../account github.com/labring/sealos/controllers/pkg => ../pkg github.com/labring/sealos/controllers/user => ../user ) diff --git a/service/account/go.mod b/service/account/go.mod index 62fb257ae58..5ee8671e9ad 100644 --- a/service/account/go.mod +++ b/service/account/go.mod @@ -28,7 +28,6 @@ require ( github.com/bytedance/sonic v1.9.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dinoallo/sealos-networkmanager-protoapi v0.0.0-20230928031328-cf9649d6af49 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch/v5 v5.8.0 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect