@@ -163,6 +163,7 @@ func LogGRPC(ctx context.Context, method string, req, reply interface{}, cc *grp
163
163
return err
164
164
}
165
165
166
+ // GetDriverName returns name of CSI driver.
166
167
func GetDriverName (ctx context.Context , conn * grpc.ClientConn ) (string , error ) {
167
168
client := csi .NewIdentityClient (conn )
168
169
@@ -177,3 +178,68 @@ func GetDriverName(ctx context.Context, conn *grpc.ClientConn) (string, error) {
177
178
}
178
179
return name , nil
179
180
}
181
+
182
+ // PluginCapabilitySet is set of CSI plugin capabilities. Only supported capabilities are in the map.
183
+ type PluginCapabilitySet map [csi.PluginCapability_Service_Type ]bool
184
+
185
+ // GetPluginCapabilities returns set of supported capabilities of CSI driver.
186
+ func GetPluginCapabilities (ctx context.Context , conn * grpc.ClientConn ) (PluginCapabilitySet , error ) {
187
+ client := csi .NewIdentityClient (conn )
188
+ req := csi.GetPluginCapabilitiesRequest {}
189
+ rsp , err := client .GetPluginCapabilities (ctx , & req )
190
+ if err != nil {
191
+ return nil , err
192
+ }
193
+ caps := PluginCapabilitySet {}
194
+ for _ , cap := range rsp .GetCapabilities () {
195
+ if cap == nil {
196
+ continue
197
+ }
198
+ srv := cap .GetService ()
199
+ if srv == nil {
200
+ continue
201
+ }
202
+ t := srv .GetType ()
203
+ caps [t ] = true
204
+ }
205
+ return caps , nil
206
+ }
207
+
208
+ // ControllerCapabilitySet is set of CSI controller capabilities. Only supported capabilities are in the map.
209
+ type ControllerCapabilitySet map [csi.ControllerServiceCapability_RPC_Type ]bool
210
+
211
+ // GetControllerCapabilities returns set of supported controller capabilities of CSI driver.
212
+ func GetControllerCapabilities (ctx context.Context , conn * grpc.ClientConn ) (ControllerCapabilitySet , error ) {
213
+ client := csi .NewControllerClient (conn )
214
+ req := csi.ControllerGetCapabilitiesRequest {}
215
+ rsp , err := client .ControllerGetCapabilities (ctx , & req )
216
+ if err != nil {
217
+ return nil , err
218
+ }
219
+
220
+ caps := ControllerCapabilitySet {}
221
+ for _ , cap := range rsp .GetCapabilities () {
222
+ if cap == nil {
223
+ continue
224
+ }
225
+ rpc := cap .GetRpc ()
226
+ if rpc == nil {
227
+ continue
228
+ }
229
+ t := rpc .GetType ()
230
+ caps [t ] = true
231
+ }
232
+ return caps , nil
233
+ }
234
+
235
+ // Probe calls Probe() of a CSI driver and waits until the driver becomes ready.
236
+ // TODO: wait until the driver is ready? It may require timeout instead of context as a parameter.
237
+ func Probe (ctx context.Context , conn * grpc.ClientConn ) error {
238
+ client := csi .NewIdentityClient (conn )
239
+ req := csi.ProbeRequest {}
240
+ _ , err := client .Probe (ctx , & req )
241
+ if err != nil {
242
+ return err
243
+ }
244
+ return nil
245
+ }
0 commit comments