Skip to content

Commit

Permalink
Merge pull request #2906 from rewantsoni/vrc
Browse files Browse the repository at this point in the history
provider: generate vrcs name to align with internal mode
  • Loading branch information
openshift-merge-bot[bot] authored Nov 22, 2024
2 parents 3ef212d + 53c7df5 commit 11f536b
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 16 deletions.
14 changes: 14 additions & 0 deletions controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"hash/fnv"
"os"

ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
Expand Down Expand Up @@ -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)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 11 additions & 10 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -834,15 +835,15 @@ 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{
"replication.storage.openshift.io/replication-secret-name": provisionerSecretName,
"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,
Expand Down
10 changes: 4 additions & 6 deletions services/provider/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 11f536b

Please sign in to comment.