From a84e6fbf54fd0ff7dbe682e1215dfc4480b04ae8 Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Thu, 7 Nov 2024 12:59:40 +0530 Subject: [PATCH] controllers: send the client profile mapping required for DR 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 --- services/provider/server/server.go | 56 ++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/services/provider/server/server.go b/services/provider/server/server.go index 62349d3b59..3386a91650 100644 --- a/services/provider/server/server.go +++ b/services/provider/server/server.go @@ -68,6 +68,8 @@ const ( monSecret = "rook-ceph-mon" ) +const peerPoolIDConfigMapName = "peer-pool-id" + type OCSProviderServer struct { pb.UnimplementedOCSProviderServer client client.Client @@ -422,6 +424,60 @@ func (s *OCSProviderServer) getExternalResources(ctx context.Context, consumerRe } + rnsList := &rookCephv1.CephBlockPoolRadosNamespaceList{} + err = s.client.List( + ctx, + rnsList, + client.InNamespace(s.namespace), + client.MatchingLabels{controllers.StorageConsumerNameLabel: consumerResource.Name}, + client.Limit(2), + ) + if err != nil { + return nil, fmt.Errorf("failed to list cephBlockPoolRados namespace. %v", err) + } + if len(rnsList.Items) > 1 { + return nil, fmt.Errorf("invalid number of radosnamespace found") + } else if len(rnsList.Items) == 1 && rnsList.Items[0].Spec.Mirroring != nil { + rns := &rnsList.Items[0] + 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) + } + peerPoolIDAsInt, err := strconv.Atoi(peerPoolID) + if err != nil { + return nil, status.Errorf(codes.Internal, "Error converting poolID to int. %v", err) + } + + clientName := consumerResource.Status.Client.Name + clientProfileName := fmt.Sprintf("%s-ceph-rbd", clientName) + clientProfileHash := util.CalculateMD5Hash(clientProfileName) + extR = append(extR, &pb.ExternalResource{ + Name: consumerResource.Status.Client.Name, + Kind: "ClientProfileMapping", + Data: mustMarshal(&csiopv1a1.BlockPoolMappingSpec{ + Local: csiopv1a1.BlockPoolRefSpec{PoolId: cephBlockPool.Status.PoolID, ClientProfileName: clientProfileHash}, + Remote: csiopv1a1.BlockPoolRefSpec{PoolId: peerPoolIDAsInt, ClientProfileName: clientProfileHash}, + }), + }) + } + // Fetch noobaa remote secret and management address and append to extResources consumerName := consumerResource.Name noobaaOperatorSecret := &v1.Secret{}