Skip to content

Commit

Permalink
controllers: send the client profile mapping required for DR
Browse files Browse the repository at this point in the history
this mapping is sent only if rns is enabled for mirroring
remote poolID is fetched from GetBlockPoolInfo rpc, which is then
written to a configMap to be read in provider server
local poolID is fetched from cephBlockPool status

Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Nov 9, 2024
1 parent 7db386e commit fbc1c87
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const (
monSecret = "rook-ceph-mon"
)

const peerPoolIDConfigMapName = "peer-pool-id"

type OCSProviderServer struct {
pb.UnimplementedOCSProviderServer
client client.Client
Expand Down Expand Up @@ -730,6 +732,8 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S
rbdStorageClassData["encryptionKMSID"] = storageRequest.Spec.EncryptionMethod
}

storageClaimHash := util.CalculateMD5Hash(req.StorageClaimName)

extR = append(extR,
&pb.ExternalResource{
Name: "ceph-rbd",
Expand Down Expand Up @@ -758,6 +762,50 @@ func (s *OCSProviderServer) GetStorageClaimConfig(ctx context.Context, req *pb.S
})},
)

if rns.Spec.Mirroring != nil {
cephBlockPool := &rookCephv1.CephBlockPool{}
cephBlockPool.Name = rns.Spec.BlockPoolName
cephBlockPool.Namespace = s.namespace
err = s.client.Get(ctx, client.ObjectKeyFromObject(cephBlockPool), cephBlockPool)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get %s CephBlockPool. %v", cephBlockPool.Name, err)
}
peerPoolIDConfigMap := &v1.ConfigMap{}
peerPoolIDConfigMap.Name = peerPoolIDConfigMapName
peerPoolIDConfigMap.Namespace = s.namespace

err := s.client.Get(ctx, client.ObjectKeyFromObject(peerPoolIDConfigMap), peerPoolIDConfigMap)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get %s ConfigMap for peer pool id. %v", peerPoolIDConfigMapName, err)
}
peerPoolID, ok := peerPoolIDConfigMap.Data[cephBlockPool.Name]
if !ok {
return nil, status.Errorf(codes.Internal, "Peer pool is not found for %s CephBlockPool. %v", cephBlockPool.Name, err)
}
poolID, err := strconv.Atoi(peerPoolID)
if err != nil {
return nil, status.Errorf(codes.Internal, "Error converting poolID to int. %v", err)

}
extR = append(extR, &pb.ExternalResource{
Kind: "ClientProfileMapping",
Name: "ceph-rbd",
Data: mustMarshal(&csiopv1a1.ClientProfileMappingSpec{
BlockPoolMapping: []csiopv1a1.BlockPoolMappingSpec{
{
Local: csiopv1a1.BlockPoolRefSpec{
ClientProfileName: storageClaimHash,
PoolId: cephBlockPool.Status.PoolID,
},
Remote: csiopv1a1.BlockPoolRefSpec{
ClientProfileName: storageClaimHash,
PoolId: poolID,
},
},
},
})})
}

case "CephFilesystemSubVolumeGroup":
subVolumeGroup := &rookCephv1.CephFilesystemSubVolumeGroup{}
err := s.client.Get(ctx, types.NamespacedName{Name: cephRes.Name, Namespace: s.namespace}, subVolumeGroup)
Expand Down

0 comments on commit fbc1c87

Please sign in to comment.