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 <resoni@redhat.com>
  • Loading branch information
rewantsoni committed Nov 14, 2024
1 parent 201c936 commit a84e6fb
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const (
monSecret = "rook-ceph-mon"
)

const peerPoolIDConfigMapName = "peer-pool-id"

type OCSProviderServer struct {
pb.UnimplementedOCSProviderServer
client client.Client
Expand Down Expand Up @@ -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{}
Expand Down

0 comments on commit a84e6fb

Please sign in to comment.