From 53c7df55b87e58f7c8a48d35774f109a421a61de Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Fri, 22 Nov 2024 20:50:44 +0530 Subject: [PATCH] provider: generate vrcs name to align with internal mode Signed-off-by: Rewant Soni --- controllers/util/util.go | 14 +++++++++++++ .../ocs-operator/v4/controllers/util/util.go | 14 +++++++++++++ services/provider/server/server.go | 21 ++++++++++--------- services/provider/server/server_test.go | 10 ++++----- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/controllers/util/util.go b/controllers/util/util.go index 634ad65245..0a8e0c38dc 100644 --- a/controllers/util/util.go +++ b/controllers/util/util.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "hash/fnv" "os" ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" @@ -99,6 +100,19 @@ func CalculateMD5Hash(value any) string { return hex.EncodeToString(hash[:]) } +/* +fnv64a is a 64-bit non-cryptographic hash algorithm with a low collision and a high distribution rate. +https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function +*/ +func FnvHash(s string) uint32 { + h := fnv.New32a() + _, err := h.Write([]byte(s)) + if err != nil { + return 0 + } + return h.Sum32() +} + func AssertEqual[T comparable](actual T, expected T, exitCode int) { if actual != expected { os.Exit(exitCode) diff --git a/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/util.go b/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/util.go index 634ad65245..0a8e0c38dc 100644 --- a/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/util.go +++ b/metrics/vendor/github.com/red-hat-storage/ocs-operator/v4/controllers/util/util.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "hash/fnv" "os" ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" @@ -99,6 +100,19 @@ func CalculateMD5Hash(value any) string { return hex.EncodeToString(hash[:]) } +/* +fnv64a is a 64-bit non-cryptographic hash algorithm with a low collision and a high distribution rate. +https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function +*/ +func FnvHash(s string) uint32 { + h := fnv.New32a() + _, err := h.Write([]byte(s)) + if err != nil { + return 0 + } + return h.Sum32() +} + func AssertEqual[T comparable](actual T, expected T, exitCode int) { if actual != expected { os.Exit(exitCode) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index b3308f4f91..1733875208 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -58,12 +58,13 @@ const ( storageRequestNameLabel = "ocs.openshift.io/storagerequest-name" notAvailable = "N/A" - ramenDRStorageIDKey = "ramendr.openshift.io/storageID" - ramenDRReplicationIDKey = "ramendr.openshift.io/replicationid" - ramenDRFlattenModeKey = "replication.storage.openshift.io/flatten-mode" - oneGibInBytes = 1024 * 1024 * 1024 - monConfigMap = "rook-ceph-mon-endpoints" - monSecret = "rook-ceph-mon" + ramenDRStorageIDKey = "ramendr.openshift.io/storageID" + ramenDRReplicationIDKey = "ramendr.openshift.io/replicationid" + ramenDRFlattenModeKey = "replication.storage.openshift.io/flatten-mode" + oneGibInBytes = 1024 * 1024 * 1024 + monConfigMap = "rook-ceph-mon-endpoints" + monSecret = "rook-ceph-mon" + volumeReplicationClass5mSchedule = "5m" ) type OCSProviderServer struct { @@ -816,14 +817,14 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S }), Labels: getExternalResourceLabels("VolumeGroupSnapshotClass", mirroringEnabled, false, replicationID, storageID)}, &pb.ExternalResource{ - Name: "ceph-rbd", + Name: fmt.Sprintf("rbd-volumereplicationclass-%v", util.FnvHash(volumeReplicationClass5mSchedule)), Kind: "VolumeReplicationClass", Data: mustMarshal(&replicationv1alpha1.VolumeReplicationClassSpec{ Parameters: map[string]string{ "replication.storage.openshift.io/replication-secret-name": provisionerSecretName, "mirroringMode": "snapshot", // This is a temporary fix till we get the replication schedule to ocs-operator - "schedulingInterval": "5m", + "schedulingInterval": volumeReplicationClass5mSchedule, "clusterID": clientProfile, }, Provisioner: util.RbdDriverName, @@ -834,7 +835,7 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S }, }, &pb.ExternalResource{ - Name: "ceph-rbd-flatten", + Name: fmt.Sprintf("rbd-flatten-volumereplicationclass-%v", util.FnvHash(volumeReplicationClass5mSchedule)), Kind: "VolumeReplicationClass", Data: mustMarshal(&replicationv1alpha1.VolumeReplicationClassSpec{ Parameters: map[string]string{ @@ -842,7 +843,7 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S "mirroringMode": "snapshot", "flattenMode": "force", // This is a temporary fix till we get the replication schedule to ocs-operator - "schedulingInterval": "5m", + "schedulingInterval": volumeReplicationClass5mSchedule, "clusterID": clientProfile, }, Provisioner: util.RbdDriverName, diff --git a/services/provider/server/server_test.go b/services/provider/server/server_test.go index d659149594..6f07935b08 100644 --- a/services/provider/server/server_test.go +++ b/services/provider/server/server_test.go @@ -661,8 +661,8 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { "ramendr.openshift.io/storageID": "8d40b6be71600457b5dec219d2ce2d4c", }, }, - "ceph-rbd-volumereplicationclass": { - Name: "ceph-rbd", + "rbd-volumereplicationclass-1625360775": { + Name: "rbd-volumereplicationclass-1625360775", Kind: "VolumeReplicationClass", Data: &replicationv1alpha1.VolumeReplicationClassSpec{ Parameters: map[string]string{ @@ -681,8 +681,8 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { "replication.storage.openshift.io/is-default-class": "true", }, }, - "ceph-rbd-flatten-volumereplicationclass": { - Name: "ceph-rbd-flatten", + "rbd-flatten-volumereplicationclass-1625360775": { + Name: "rbd-flatten-volumereplicationclass-1625360775", Kind: "VolumeReplicationClass", Data: &replicationv1alpha1.VolumeReplicationClassSpec{ Parameters: map[string]string{ @@ -1103,8 +1103,6 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) { name = fmt.Sprintf("%s-storageclass", name) } else if extResource.Kind == "VolumeGroupSnapshotClass" { name = fmt.Sprintf("%s-volumegroupsnapshotclass", name) - } else if extResource.Kind == "VolumeReplicationClass" { - name = fmt.Sprintf("%s-volumereplicationclass", name) } else if extResource.Kind == "ClientProfile" { name = fmt.Sprintf("%s-clientprofile", name) }