Skip to content

Commit

Permalink
add server side implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Rewant Soni <[email protected]>

add generated changes

Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Nov 12, 2024
1 parent 0755a24 commit 80fcbed
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
1 change: 1 addition & 0 deletions deploy/ocs-operator/manifests/provider-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rules:
resources:
- cephfilesystemsubvolumegroups
- cephblockpoolradosnamespaces
- cephblockpools
verbs:
- get
- list
Expand Down
1 change: 1 addition & 0 deletions rbac/provider-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rules:
resources:
- cephfilesystemsubvolumegroups
- cephblockpoolradosnamespaces
- cephblockpools
verbs:
- get
- list
Expand Down
97 changes: 94 additions & 3 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ const (
storageRequestNameLabel = "ocs.openshift.io/storagerequest-name"
notAvailable = "N/A"

ramenDRStorageIDKey = "ramendr.openshift.io/storageID"
ramenDRReplicationIDKey = "ramendr.openshift.io/replicationid"
ramenDRFlattenModeKey = "replication.storage.openshift.io/flatten-mode"
ramenDRStorageIDKey = "ramendr.openshift.io/storageID"
ramenDRReplicationIDKey = "ramendr.openshift.io/replicationid"
ramenDRFlattenModeKey = "replication.storage.openshift.io/flatten-mode"
rbdMirrorBootstrapPeerSecretName = "rbdMirrorBootstrapPeerSecretName"
)

const (
Expand Down Expand Up @@ -1042,3 +1043,93 @@ func (s *OCSProviderServer) PeerStorageCluster(ctx context.Context, req *pb.Peer

return &pb.PeerStorageClusterResponse{}, nil
}

func (s *OCSProviderServer) GetStorageClientsInfo(ctx context.Context, req *pb.StorageClientsInfoRequest) (*pb.StorageClientsInfoResponse, error) {
storageCluster, err := util.GetStorageClusterInNamespace(ctx, s.client, s.namespace)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get storageCluster. %v", err)
}

if storageCluster.UID != types.UID(req.StorageClusterUID) {
return nil, status.Errorf(codes.InvalidArgument, "storageClusterUID specified on the req does not match any existing storage cluster")
}

var clientsInfo []*pb.ClientInfo

for i := range req.ClientIDs {
consumer, err := s.consumerManager.Get(ctx, req.ClientIDs[i])
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get consumer. %v", err)
}
rnsList := &rookCephv1.CephBlockPoolRadosNamespaceList{}
err = s.client.List(
ctx,
rnsList,
client.InNamespace(s.namespace),
client.MatchingLabels{controllers.StorageConsumerNameLabel: consumer.Name},
client.Limit(1),
)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list rados namespace. %v", err)
}
if len(rnsList.Items) == 0 {
return nil, status.Errorf(codes.Internal, "rados namespace for the client not found: %v", consumer.UID)
}
clientsInfo = append(clientsInfo, &pb.ClientInfo{ClientID: req.ClientIDs[i], RadosNamespace: rnsList.Items[0].Name})
}

return &pb.StorageClientsInfoResponse{ClientsInfo: clientsInfo}, nil
}

func (s *OCSProviderServer) GetBlockPoolsInfo(ctx context.Context, req *pb.BlockPoolsInfoRequest) (*pb.BlockPoolsInfoResponse, error) {
storageCluster, err := util.GetStorageClusterInNamespace(ctx, s.client, s.namespace)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get storageCluster. %v", err)
}

if storageCluster.UID != types.UID(req.StorageClusterUID) {
return nil, status.Errorf(codes.InvalidArgument, "storageClusterUID specified on the req does not match any existing storage cluster")
}

var blockPoolsInfo []*pb.BlockPoolInfo
for i := range req.BlockPoolNames {
cephBlockPool := &rookCephv1.CephBlockPool{}
cephBlockPool.Name = req.BlockPoolNames[i]
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 CephBlockPool: %v. %v", cephBlockPool.Name, err)
}

var mirroringToken string

if cephBlockPool.Spec.Mirroring.Enabled &&
cephBlockPool.Status.Info != nil &&
cephBlockPool.Status.Info[rbdMirrorBootstrapPeerSecretName] != "" {
secret := &corev1.Secret{}
secret.Name = cephBlockPool.Status.Info[rbdMirrorBootstrapPeerSecretName]
secret.Namespace = s.namespace
err := s.client.Get(ctx, client.ObjectKeyFromObject(secret), secret)
if err != nil {
errMsg := fmt.Sprintf(
"failed to get bootstrap secret %s for CephBlockPool %s: %v",
cephBlockPool.Status.Info[rbdMirrorBootstrapPeerSecretName],
cephBlockPool.Name,
err,
)
klog.Error(errMsg)
return nil, status.Errorf(codes.Internal, "failed to get bootstrap secret for CephBlockPool %s.", cephBlockPool.Name)
}
mirroringToken = string(secret.Data["token"])
}

blockPoolsInfo = append(blockPoolsInfo, &pb.BlockPoolInfo{
BlockPoolName: cephBlockPool.Name,
MirroringToken: mirroringToken,
BlockPoolID: strconv.Itoa(cephBlockPool.Status.PoolID),
})

}

return &pb.BlockPoolsInfoResponse{BlockPoolsInfo: blockPoolsInfo}, nil
}

0 comments on commit 80fcbed

Please sign in to comment.