@@ -52,11 +52,12 @@ import (
52
52
)
53
53
54
54
const (
55
- TicketAnnotation = "ocs.openshift.io/provider-onboarding-ticket"
56
- ProviderCertsMountPoint = "/mnt/cert"
57
- onboardingTicketKeySecret = "onboarding-ticket-key"
58
- storageRequestNameLabel = "ocs.openshift.io/storagerequest-name"
59
- notAvailable = "N/A"
55
+ TicketAnnotation = "ocs.openshift.io/provider-onboarding-ticket"
56
+ ProviderCertsMountPoint = "/mnt/cert"
57
+ onboardingTicketKeySecret = "onboarding-ticket-key"
58
+ storageRequestNameLabel = "ocs.openshift.io/storagerequest-name"
59
+ notAvailable = "N/A"
60
+ rbdMirrorBootstrapPeerSecretName = "rbdMirrorBootstrapPeerSecretName"
60
61
)
61
62
62
63
const (
@@ -966,3 +967,95 @@ func (s *OCSProviderServer) PeerStorageCluster(ctx context.Context, req *pb.Peer
966
967
967
968
return & pb.PeerStorageClusterResponse {}, nil
968
969
}
970
+
971
+ func (s * OCSProviderServer ) GetClientsInfo (ctx context.Context , req * pb.GetClientsInfoRequest ) (* pb.GetClientsInfoResponse , error ) {
972
+ storageCluster , err := util .GetStorageClusterInNamespace (ctx , s .client , s .namespace )
973
+ if err != nil {
974
+ return nil , status .Errorf (codes .Internal , "failed to get storageCluster. %v" , err )
975
+ }
976
+
977
+ if storageCluster .UID != types .UID (req .StorageClusterUID ) {
978
+ return nil , status .Errorf (codes .InvalidArgument , "storageClusterUID specified on the req does not match any existing storage cluster" )
979
+ }
980
+
981
+ var clientsInfo []* pb.ClientInfo
982
+
983
+ for i := range req .ClientIDs {
984
+ consumer , err := s .consumerManager .Get (ctx , req .ClientIDs [i ])
985
+ if err != nil {
986
+ return nil , status .Errorf (codes .Internal , "failed to get consumer. %v" , err )
987
+ }
988
+ rnsList := & rookCephv1.CephBlockPoolRadosNamespaceList {}
989
+ err = s .client .List (ctx , rnsList , client .InNamespace (s .namespace ), client.MatchingLabels {controllers .StorageConsumerNameLabel : consumer .Name }, client .Limit (1 ))
990
+ if err != nil {
991
+ return nil , status .Errorf (codes .Internal , "failed to list rados namespace. %v" , err )
992
+ }
993
+ if len (rnsList .Items ) == 0 {
994
+ return nil , status .Errorf (codes .Internal , "rados namespace for the client not found: %v" , consumer .UID )
995
+ }
996
+ clientsInfo = append (clientsInfo , & pb.ClientInfo {ClientID : req .ClientIDs [i ], RadosNamespace : rnsList .Items [0 ].Name })
997
+ }
998
+
999
+ return & pb.GetClientsInfoResponse {ClientsInfo : clientsInfo }, nil
1000
+ }
1001
+
1002
+ func (s * OCSProviderServer ) GetBlockPoolsInfo (ctx context.Context , req * pb.GetBlockPoolsInfoRequest ) (* pb.GetBlockPoolsInfoResponse , error ) {
1003
+ storageCluster , err := util .GetStorageClusterInNamespace (ctx , s .client , s .namespace )
1004
+ if err != nil {
1005
+ return nil , status .Errorf (codes .Internal , "failed to get storageCluster. %v" , err )
1006
+ }
1007
+
1008
+ if storageCluster .UID != types .UID (req .StorageClusterUID ) {
1009
+ return nil , status .Errorf (codes .InvalidArgument , "storageClusterUID specified on the req does not match any existing storage cluster" )
1010
+ }
1011
+
1012
+ var blockPoolsInfo []* pb.BlockPoolInfo
1013
+ for i := range req .BlockPoolNames {
1014
+ cephBlockPool := & rookCephv1.CephBlockPool {}
1015
+ cephBlockPool .Name = req .BlockPoolNames [i ]
1016
+ cephBlockPool .Namespace = s .namespace
1017
+ err = s .client .Get (ctx , client .ObjectKeyFromObject (cephBlockPool ), cephBlockPool )
1018
+ if err != nil {
1019
+ return nil , status .Errorf (codes .Internal , "failed to get CephBlockPool: %v. %v" , cephBlockPool .Name , err )
1020
+ }
1021
+
1022
+ // if the blockPool mirroring is not enabled return an error
1023
+ if ! cephBlockPool .Spec .Mirroring .Enabled {
1024
+ errMsg := fmt .Sprintf ("Mirroring is not enabled for CephBlockPool: %v" , cephBlockPool .Name )
1025
+ klog .Error (errMsg )
1026
+ return nil , status .Errorf (codes .Internal , errMsg )
1027
+ }
1028
+
1029
+ if cephBlockPool .Status .Info != nil &&
1030
+ cephBlockPool .Status .Info [rbdMirrorBootstrapPeerSecretName ] != "" {
1031
+ secret := & corev1.Secret {}
1032
+ secret .Name = cephBlockPool .Status .Info [rbdMirrorBootstrapPeerSecretName ]
1033
+ secret .Namespace = s .namespace
1034
+ err := s .client .Get (ctx , client .ObjectKeyFromObject (secret ), secret )
1035
+ if err != nil {
1036
+ errMsg := fmt .Sprintf ("Error fetching bootstrap secret %s for CephBlockPool %s: %v" ,
1037
+ cephBlockPool .Status .Info [rbdMirrorBootstrapPeerSecretName ],
1038
+ cephBlockPool .Name ,
1039
+ err )
1040
+ klog .Error (errMsg )
1041
+ return nil , status .Errorf (codes .Internal , errMsg )
1042
+ }
1043
+ if _ , ok := secret .Data ["token" ]; ! ok {
1044
+ return nil , status .Errorf (codes .Internal , "error fetching mirroring token for CephBlockPool %s" , cephBlockPool .Name )
1045
+ }
1046
+
1047
+ blockPoolsInfo = append (blockPoolsInfo , & pb.BlockPoolInfo {
1048
+ BlockPoolName : cephBlockPool .Name ,
1049
+ MirroringToken : string (secret .Data ["token" ]),
1050
+ BlockPoolID : strconv .Itoa (cephBlockPool .Status .PoolID ),
1051
+ })
1052
+ } else {
1053
+ errMsg := fmt .Sprintf ("Mirroring Token for CephBlockPool %s is not generated" , cephBlockPool .Name )
1054
+ klog .Error (errMsg )
1055
+ return nil , status .Errorf (codes .Internal , errMsg )
1056
+ }
1057
+
1058
+ }
1059
+
1060
+ return & pb.GetBlockPoolsInfoResponse {BlockPoolsInfo : blockPoolsInfo }, nil
1061
+ }
0 commit comments