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 11, 2024
1 parent 6807fe5 commit e069e9a
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 5 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
103 changes: 98 additions & 5 deletions services/provider/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ import (
)

const (
TicketAnnotation = "ocs.openshift.io/provider-onboarding-ticket"
ProviderCertsMountPoint = "/mnt/cert"
onboardingTicketKeySecret = "onboarding-ticket-key"
storageRequestNameLabel = "ocs.openshift.io/storagerequest-name"
notAvailable = "N/A"
TicketAnnotation = "ocs.openshift.io/provider-onboarding-ticket"
ProviderCertsMountPoint = "/mnt/cert"
onboardingTicketKeySecret = "onboarding-ticket-key"
storageRequestNameLabel = "ocs.openshift.io/storagerequest-name"
notAvailable = "N/A"
rbdMirrorBootstrapPeerSecretName = "rbdMirrorBootstrapPeerSecretName"
)

const (
Expand Down Expand Up @@ -966,3 +967,95 @@ func (s *OCSProviderServer) PeerStorageCluster(ctx context.Context, req *pb.Peer

return &pb.PeerStorageClusterResponse{}, nil
}

func (s *OCSProviderServer) GetClientsInfo(ctx context.Context, req *pb.GetClientsInfoRequest) (*pb.GetClientsInfoResponse, 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.GetClientsInfoResponse{ClientsInfo: clientsInfo}, nil
}

func (s *OCSProviderServer) GetBlockPoolsInfo(ctx context.Context, req *pb.GetBlockPoolsInfoRequest) (*pb.GetBlockPoolsInfoResponse, 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)
}

// if the blockPool mirroring is not enabled return an error
if !cephBlockPool.Spec.Mirroring.Enabled {
errMsg := fmt.Sprintf("Mirroring is not enabled for CephBlockPool: %v", cephBlockPool.Name)
klog.Error(errMsg)
return nil, status.Errorf(codes.Internal, errMsg)
}

if 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("Error fetching bootstrap secret %s for CephBlockPool %s: %v",
cephBlockPool.Status.Info[rbdMirrorBootstrapPeerSecretName],
cephBlockPool.Name,
err)
klog.Error(errMsg)
return nil, status.Errorf(codes.Internal, errMsg)
}
if _, ok := secret.Data["token"]; !ok {
return nil, status.Errorf(codes.Internal, "error fetching mirroring token for CephBlockPool %s", cephBlockPool.Name)
}

blockPoolsInfo = append(blockPoolsInfo, &pb.BlockPoolInfo{
BlockPoolName: cephBlockPool.Name,
MirroringToken: string(secret.Data["token"]),
BlockPoolID: strconv.Itoa(cephBlockPool.Status.PoolID),
})
} else {
errMsg := fmt.Sprintf("Mirroring Token for CephBlockPool %s is not generated", cephBlockPool.Name)
klog.Error(errMsg)
return nil, status.Errorf(codes.Internal, errMsg)
}

}

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

0 comments on commit e069e9a

Please sign in to comment.