Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: send the client profile mapping required for DR #2879

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this above after line 60.


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
Loading