Skip to content

Commit 45085bb

Browse files
committed
Add GetGroupControllerCapabilities common function
1 parent 597d128 commit 45085bb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

rpc/common.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,33 @@ func GetControllerCapabilities(ctx context.Context, conn *grpc.ClientConn) (Cont
104104
return caps, nil
105105
}
106106

107+
// GroupControllerCapabilitySet is set of CSI groupcontroller capabilities. Only supported capabilities are in the map.
108+
type GroupControllerCapabilitySet map[csi.GroupControllerServiceCapability_RPC_Type]bool
109+
110+
// GetGroupControllerCapabilities returns set of supported group controller capabilities of CSI driver.
111+
func GetGroupControllerCapabilities(ctx context.Context, conn *grpc.ClientConn) (GroupControllerCapabilitySet, error) {
112+
client := csi.NewGroupControllerClient(conn)
113+
req := csi.GroupControllerGetCapabilitiesRequest{}
114+
rsp, err := client.GroupControllerGetCapabilities(ctx, &req)
115+
if err != nil {
116+
return nil, err
117+
}
118+
119+
caps := GroupControllerCapabilitySet{}
120+
for _, cap := range rsp.GetCapabilities() {
121+
if cap == nil {
122+
continue
123+
}
124+
rpc := cap.GetRpc()
125+
if rpc == nil {
126+
continue
127+
}
128+
t := rpc.GetType()
129+
caps[t] = true
130+
}
131+
return caps, nil
132+
}
133+
107134
// ProbeForever calls Probe() of a CSI driver and waits until the driver becomes ready.
108135
// Any error other than timeout is returned.
109136
func ProbeForever(conn *grpc.ClientConn, singleProbeTimeout time.Duration) error {

0 commit comments

Comments
 (0)