From 55c015c6ae28a0e5250941204aa4891f38da8193 Mon Sep 17 00:00:00 2001 From: rchikatw Date: Wed, 13 Nov 2024 19:45:27 +0530 Subject: [PATCH] server: saving quota in GiB instead GB Signed-off-by: rchikatw --- services/provider/server/server.go | 7 ++++--- services/provider/server/server_test.go | 11 ++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index 62349d3b59..ad0b09ba40 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -61,6 +61,7 @@ const ( ramenDRStorageIDKey = "ramendr.openshift.io/storageID" ramenDRReplicationIDKey = "ramendr.openshift.io/replicationid" ramenDRFlattenModeKey = "replication.storage.openshift.io/flatten-mode" + oneGibiBytes = 1024 * 1024 * 1024 ) const ( @@ -407,9 +408,9 @@ func (s *OCSProviderServer) getExternalResources(ctx context.Context, consumerRe }, }, Quota: corev1.ResourceQuotaSpec{ - Hard: corev1.ResourceList{"requests.storage": *resource.NewScaledQuantity( - int64(consumerResource.Spec.StorageQuotaInGiB), - resource.Giga, + Hard: corev1.ResourceList{"requests.storage": *resource.NewQuantity( + int64(consumerResource.Spec.StorageQuotaInGiB*oneGibiBytes), + resource.BinarySI, )}, }, } diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index 80a3445953..7179b2ebe5 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -49,9 +49,9 @@ var clusterResourceQuotaSpec = "av1.ClusterResourceQuotaSpec{ }, }, Quota: corev1.ResourceQuotaSpec{ - Hard: corev1.ResourceList{"requests.storage": *resource.NewScaledQuantity( - int64(consumerResource.Spec.StorageQuotaInGiB), - resource.Giga, + Hard: corev1.ResourceList{"requests.storage": *resource.NewQuantity( + int64(consumerResource.Spec.StorageQuotaInGiB*oneGibiBytes), + resource.BinarySI, )}, }, } @@ -337,8 +337,9 @@ func TestGetExternalResources(t *testing.T) { var clusterResourceQuotaSpec quotav1.ClusterResourceQuotaSpec err = json.Unmarshal([]byte(extResource.Data), &clusterResourceQuotaSpec) assert.NoError(t, err) - quantity, _ := resource.ParseQuantity("10240G") - assert.Equal(t, clusterResourceQuotaSpec.Quota.Hard["requests.storage"], quantity) + expected := resource.NewQuantity(int64(10240*oneGibiBytes), resource.BinarySI) + actual := clusterResourceQuotaSpec.Quota.Hard["requests.storage"] + assert.Equal(t, actual.Value(), expected.Value()) } else if extResource.Kind == "Noobaa" { var extNoobaaSpec, mockNoobaaSpec nbv1.NooBaaSpec err = json.Unmarshal(extResource.Data, &extNoobaaSpec)