Merge pull request #864 from carlory/patch-001

check if the csi driver is supported the volume group snapshot cap
This commit is contained in:
Kubernetes Prow Robot
2023-09-05 19:40:51 -07:00
committed by GitHub
6 changed files with 52 additions and 11 deletions

View File

@@ -54,8 +54,8 @@ func SetMaxGRPCLogLength(characterCount int) {
// file or have format '<protocol>://', following gRPC name resolution mechanism at
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
//
// The function tries to connect indefinitely every second until it connects. The function automatically disables TLS
// and adds interceptor for logging of all gRPC messages at level 5.
// The function tries to connect for 30 seconds, and returns an error if no connection has been established at that point.
// The function automatically disables TLS and adds interceptor for logging of all gRPC messages at level 5.
//
// For a connection to a Unix Domain socket, the behavior after
// loosing the connection is configurable. The default is to
@@ -70,7 +70,7 @@ func SetMaxGRPCLogLength(characterCount int) {
// For other connections, the default behavior from gRPC is used and
// loss of connection is not detected reliably.
func Connect(address string, metricsManager metrics.CSIMetricsManager, options ...Option) (*grpc.ClientConn, error) {
return connect(address, metricsManager, []grpc.DialOption{}, options)
return connect(address, metricsManager, []grpc.DialOption{grpc.WithTimeout(time.Second * 30)}, options)
}
// Option is the type of all optional parameters for Connect.

View File

@@ -104,6 +104,33 @@ func GetControllerCapabilities(ctx context.Context, conn *grpc.ClientConn) (Cont
return caps, nil
}
// GroupControllerCapabilitySet is set of CSI groupcontroller capabilities. Only supported capabilities are in the map.
type GroupControllerCapabilitySet map[csi.GroupControllerServiceCapability_RPC_Type]bool
// GetGroupControllerCapabilities returns set of supported group controller capabilities of CSI driver.
func GetGroupControllerCapabilities(ctx context.Context, conn *grpc.ClientConn) (GroupControllerCapabilitySet, error) {
client := csi.NewGroupControllerClient(conn)
req := csi.GroupControllerGetCapabilitiesRequest{}
rsp, err := client.GroupControllerGetCapabilities(ctx, &req)
if err != nil {
return nil, err
}
caps := GroupControllerCapabilitySet{}
for _, cap := range rsp.GetCapabilities() {
if cap == nil {
continue
}
rpc := cap.GetRpc()
if rpc == nil {
continue
}
t := rpc.GetType()
caps[t] = true
}
return caps, nil
}
// ProbeForever calls Probe() of a CSI driver and waits until the driver becomes ready.
// Any error other than timeout is returned.
func ProbeForever(conn *grpc.ClientConn, singleProbeTimeout time.Duration) error {