Skip to content

Commit

Permalink
provider: update ramen replicationid
Browse files Browse the repository at this point in the history
Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Feb 11, 2025
1 parent 525723f commit 7e83be4
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 49 deletions.
132 changes: 87 additions & 45 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,6 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S
return nil, err
}

replicationID := req.StorageClaimName

for _, cephRes := range storageRequest.Status.CephResources {
switch cephRes.Kind {
case "CephClient":
Expand Down Expand Up @@ -815,6 +813,65 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S
strconv.Itoa(blockPool.Status.PoolID),
rns.Name)

if blockPool.GetAnnotations()[util.BlockPoolMirroringTargetIDAnnotation] != "" {
peerCephfsid, err := s.getPeerCephFSID(blockPool.Spec.Mirroring.Peers.SecretNames[0])
if err != nil {
klog.Errorf("failed to get peer Ceph FSIS. %v", err)
}

peerStorageID := calculateCephRbdStorageId(
peerCephfsid,
blockPool.GetAnnotations()[util.BlockPoolMirroringTargetIDAnnotation],
*rns.Spec.Mirroring.RemoteNamespace)

replicationID := generateReplicationID(storageID, peerStorageID)
extR = append(extR,
&pb.ExternalResource{
Name: fmt.Sprintf("rbd-volumereplicationclass-%v", util.FnvHash(volumeReplicationClass5mSchedule)),
Kind: "VolumeReplicationClass",
Labels: map[string]string{
ramenDRStorageIDLabelKey: storageID,
ramenDRReplicationIDLabelKey: replicationID,
ramenMaintenanceModeLabelKey: "Failover",
},
Annotations: map[string]string{
"replication.storage.openshift.io/is-default-class": "true",
},
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": volumeReplicationClass5mSchedule,
"clusterID": clientProfile,
},
Provisioner: util.RbdDriverName,
}),
},
&pb.ExternalResource{
Name: fmt.Sprintf("rbd-flatten-volumereplicationclass-%v", util.FnvHash(volumeReplicationClass5mSchedule)),
Kind: "VolumeReplicationClass",
Labels: map[string]string{
ramenDRStorageIDLabelKey: storageID,
ramenDRReplicationIDLabelKey: replicationID,
ramenMaintenanceModeLabelKey: "Failover",
ramenDRFlattenModeLabelKey: "force",
},
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": volumeReplicationClass5mSchedule,
"clusterID": clientProfile,
},
Provisioner: util.RbdDriverName,
}),
},
)
}

extR = append(extR,
&pb.ExternalResource{
Name: "ceph-rbd",
Expand Down Expand Up @@ -846,49 +903,6 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S
"pool": rns.Spec.BlockPoolName,
}),
},
&pb.ExternalResource{
Name: fmt.Sprintf("rbd-volumereplicationclass-%v", util.FnvHash(volumeReplicationClass5mSchedule)),
Kind: "VolumeReplicationClass",
Labels: map[string]string{
ramenDRStorageIDLabelKey: storageID,
ramenDRReplicationIDLabelKey: replicationID,
ramenMaintenanceModeLabelKey: "Failover",
},
Annotations: map[string]string{
"replication.storage.openshift.io/is-default-class": "true",
},
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": volumeReplicationClass5mSchedule,
"clusterID": clientProfile,
},
Provisioner: util.RbdDriverName,
}),
},
&pb.ExternalResource{
Name: fmt.Sprintf("rbd-flatten-volumereplicationclass-%v", util.FnvHash(volumeReplicationClass5mSchedule)),
Kind: "VolumeReplicationClass",
Labels: map[string]string{
ramenDRStorageIDLabelKey: storageID,
ramenDRReplicationIDLabelKey: replicationID,
ramenMaintenanceModeLabelKey: "Failover",
ramenDRFlattenModeLabelKey: "force",
},
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": volumeReplicationClass5mSchedule,
"clusterID": clientProfile,
},
Provisioner: util.RbdDriverName,
}),
},
&pb.ExternalResource{
Kind: "ClientProfile",
Name: "ceph-rbd",
Expand Down Expand Up @@ -1339,3 +1353,31 @@ func calculateCephRbdStorageId(cephfsid, poolID, radosnamespacename string) stri
func calculateCephFsStorageId(cephfsid, fileSystemName, subVolumeGroupName string) string {
return util.CalculateMD5Hash([3]string{cephfsid, fileSystemName, subVolumeGroupName})
}

func (s *OCSProviderServer) getPeerCephFSID(secretName string) (string, error) {
secret := &corev1.Secret{}
secret.Name = secretName
secret.Namespace = s.namespace
err := s.client.Get(context.Background(), client.ObjectKeyFromObject(secret), secret)
if err != nil {
return "", err
}
decodeString, err := base64.StdEncoding.DecodeString(string(secret.Data["token"]))
if err != nil {
return "", err
}
token := struct {
FSID string `json:"fsid"`
}{}
err = json.Unmarshal(decodeString, &token)
if err != nil {
return "", err
}
return token.FSID, nil
}

func generateReplicationID(storageIDs ...string) string {
slices.Sort(storageIDs)
return util.CalculateMD5Hash(storageIDs)

}
31 changes: 27 additions & 4 deletions services/provider/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"k8s.io/utils/ptr"
"reflect"
"strconv"
"testing"
Expand Down Expand Up @@ -713,7 +714,7 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) {
Name: "rbd-volumereplicationclass-1625360775",
Kind: "VolumeReplicationClass",
Labels: map[string]string{
"ramendr.openshift.io/replicationid": "block-pool-claim",
"ramendr.openshift.io/replicationid": "7800db73e1f67a64524d91ee68670b8b",
"ramendr.openshift.io/storageid": "854666c7477123fb05f20bf615e69a46",
"ramendr.openshift.io/maintenancemodes": "Failover",
},
Expand All @@ -735,7 +736,7 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) {
Kind: "VolumeReplicationClass",
Labels: map[string]string{
"replication.storage.openshift.io/flatten-mode": "force",
"ramendr.openshift.io/replicationid": "block-pool-claim",
"ramendr.openshift.io/replicationid": "7800db73e1f67a64524d91ee68670b8b",
"ramendr.openshift.io/storageid": "854666c7477123fb05f20bf615e69a46",
"ramendr.openshift.io/maintenancemodes": "Failover",
},
Expand Down Expand Up @@ -1135,7 +1136,8 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) {
Spec: rookCephv1.CephBlockPoolRadosNamespaceSpec{
BlockPoolName: "cephblockpool",
Mirroring: &rookCephv1.RadosNamespaceMirroring{
Mode: "pool",
Mode: "pool",
RemoteNamespace: ptr.To("peer-remote"),
},
},
}
Expand All @@ -1145,10 +1147,20 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) {
ObjectMeta: metav1.ObjectMeta{
Name: "cephblockpool",
Namespace: server.namespace,
Annotations: map[string]string{
"ocs.openshift.io/mirroring-target-id": "3",
},
},
Spec: rookCephv1.NamedBlockPoolSpec{
PoolSpec: rookCephv1.PoolSpec{
Mirroring: rookCephv1.MirroringSpec{Enabled: false},
Mirroring: rookCephv1.MirroringSpec{
Enabled: false,
Peers: &rookCephv1.MirroringPeerSpec{
SecretNames: []string{
"mirroring-token",
},
},
},
},
},
Status: &rookCephv1.CephBlockPoolStatus{
Expand All @@ -1157,6 +1169,17 @@ func TestOCSProviderServerGetStorageClaimConfig(t *testing.T) {
}
assert.NoError(t, client.Create(ctx, cephBlockPool))

mirroringToken := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "mirroring-token",
Namespace: server.namespace,
},
Data: map[string][]byte{
"token": []byte("eyJmc2lkIjoiZjk1NGYwNGItM2M1Yi00MWMxLWFkODUtNjEzNzA3ZDBjZDllIiwiY2xpZW50X2lkIjoicmJkLW1pcnJvci1wZWVyIiwia2V5IjoiQVFDYUZJNW5ZRVJrR0JBQWQzLzVQS1V3RFVuTXkxbHBMSEh2ZXc9PSIsIm1vbl9ob3N0IjoidjI6MTAuMC4xMzUuMTY5OjMzMDAvMCx2MjoxMC4wLjE1Ny4xNTY6MzMwMC8wLHYyOjEwLjAuMTcyLjExMjozMzAwLzAiLCJuYW1lc3BhY2UiOiJvcGVuc2hpZnQtc3RvcmFnZSJ9"),
},
}
assert.NoError(t, client.Create(ctx, mirroringToken))

// get the storage class request config for block pool
req := pb.StorageClaimConfigRequest{
StorageConsumerUUID: string(consumerResource.UID),
Expand Down

0 comments on commit 7e83be4

Please sign in to comment.