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

@@ -20,19 +20,17 @@ import (
"context" "context"
"flag" "flag"
"fmt" "fmt"
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter"
"net/http" "net/http"
"os" "os"
"os/signal" "os/signal"
"strings" "strings"
"time" "time"
utils "github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"
"google.golang.org/grpc" "google.golang.org/grpc"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/labels"
coreinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes" "k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest" "k8s.io/client-go/rest"
@@ -51,7 +49,8 @@ import (
clientset "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned" clientset "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned"
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned/scheme" snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned/scheme"
informers "github.com/kubernetes-csi/external-snapshotter/client/v6/informers/externalversions" informers "github.com/kubernetes-csi/external-snapshotter/client/v6/informers/externalversions"
coreinformers "k8s.io/client-go/informers" "github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter"
utils "github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"
) )
const ( const (
@@ -229,6 +228,12 @@ func main() {
snapShotter := snapshotter.NewSnapshotter(csiConn) snapShotter := snapshotter.NewSnapshotter(csiConn)
var groupSnapshotter group_snapshotter.GroupSnapshotter var groupSnapshotter group_snapshotter.GroupSnapshotter
if *enableVolumeGroupSnapshots { if *enableVolumeGroupSnapshots {
supportsCreateVolumeGroupSnapshot, err := supportsGroupControllerCreateVolumeGroupSnapshot(ctx, csiConn)
if err != nil {
klog.Errorf("error determining if driver supports create/delete group snapshot operations: %v", err)
} else if !supportsCreateVolumeGroupSnapshot {
klog.Warningf("CSI driver %s does not support GroupControllerCreateVolumeGroupSnapshot when the --enable-volume-group-snapshots flag is true", driverName)
}
groupSnapshotter = group_snapshotter.NewGroupSnapshotter(csiConn) groupSnapshotter = group_snapshotter.NewGroupSnapshotter(csiConn)
if len(*groupSnapshotNamePrefix) == 0 { if len(*groupSnapshotNamePrefix) == 0 {
klog.Error("group snapshot name prefix cannot be of length 0") klog.Error("group snapshot name prefix cannot be of length 0")
@@ -317,3 +322,12 @@ func supportsControllerCreateSnapshot(ctx context.Context, conn *grpc.ClientConn
return capabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT], nil return capabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT], nil
} }
func supportsGroupControllerCreateVolumeGroupSnapshot(ctx context.Context, conn *grpc.ClientConn) (bool, error) {
capabilities, err := csirpc.GetGroupControllerCapabilities(ctx, conn)
if err != nil {
return false, err
}
return capabilities[csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT], nil
}

2
go.mod
View File

@@ -8,7 +8,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 github.com/fsnotify/fsnotify v1.6.0
github.com/golang/mock v1.6.0 github.com/golang/mock v1.6.0
github.com/google/gofuzz v1.2.0 github.com/google/gofuzz v1.2.0
github.com/kubernetes-csi/csi-lib-utils v0.13.0 github.com/kubernetes-csi/csi-lib-utils v0.14.0
github.com/kubernetes-csi/csi-test/v4 v4.4.0 github.com/kubernetes-csi/csi-test/v4 v4.4.0
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.1.0 github.com/kubernetes-csi/external-snapshotter/client/v6 v6.1.0
github.com/prometheus/client_golang v1.16.0 github.com/prometheus/client_golang v1.16.0

4
go.sum
View File

@@ -124,8 +124,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubernetes-csi/csi-lib-utils v0.13.0 h1:QrTdZVZbHlaSUBN9ReayBPnnF1N0edFIpUKBwVIBW3w= github.com/kubernetes-csi/csi-lib-utils v0.14.0 h1:pusB32LkSd7GhuT8Z6cyRFqByujc28ygWV97ndaT19s=
github.com/kubernetes-csi/csi-lib-utils v0.13.0/go.mod h1:JS9eDIZmSjx4F9o0bLTVK/qfhIIOifdjEfVXzxWapfE= github.com/kubernetes-csi/csi-lib-utils v0.14.0/go.mod h1:uX8xidqxGJOLXtsfCCVsxWtZl/9NiLyd2DD3Nb+KoP4=
github.com/kubernetes-csi/csi-test/v4 v4.4.0 h1:r0mnAwDURI24Vw3a/LyA/ga11yD5ZGuU7+REO35Na9s= github.com/kubernetes-csi/csi-test/v4 v4.4.0 h1:r0mnAwDURI24Vw3a/LyA/ga11yD5ZGuU7+REO35Na9s=
github.com/kubernetes-csi/csi-test/v4 v4.4.0/go.mod h1:t1RzseMZJKy313nezI/d7TolbbiKpUZM3SXQvXxOX0w= github.com/kubernetes-csi/csi-test/v4 v4.4.0/go.mod h1:t1RzseMZJKy313nezI/d7TolbbiKpUZM3SXQvXxOX0w=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=

View File

@@ -54,8 +54,8 @@ func SetMaxGRPCLogLength(characterCount int) {
// file or have format '<protocol>://', following gRPC name resolution mechanism at // file or have format '<protocol>://', following gRPC name resolution mechanism at
// https://github.com/grpc/grpc/blob/master/doc/naming.md. // 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 // The function tries to connect for 30 seconds, and returns an error if no connection has been established at that point.
// and adds interceptor for logging of all gRPC messages at level 5. // 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 // For a connection to a Unix Domain socket, the behavior after
// loosing the connection is configurable. The default is to // 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 // For other connections, the default behavior from gRPC is used and
// loss of connection is not detected reliably. // loss of connection is not detected reliably.
func Connect(address string, metricsManager metrics.CSIMetricsManager, options ...Option) (*grpc.ClientConn, error) { 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. // 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 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. // ProbeForever calls Probe() of a CSI driver and waits until the driver becomes ready.
// Any error other than timeout is returned. // Any error other than timeout is returned.
func ProbeForever(conn *grpc.ClientConn, singleProbeTimeout time.Duration) error { func ProbeForever(conn *grpc.ClientConn, singleProbeTimeout time.Duration) error {

2
vendor/modules.txt vendored
View File

@@ -90,7 +90,7 @@ github.com/josharian/intern
# github.com/json-iterator/go v1.1.12 # github.com/json-iterator/go v1.1.12
## explicit; go 1.12 ## explicit; go 1.12
github.com/json-iterator/go github.com/json-iterator/go
# github.com/kubernetes-csi/csi-lib-utils v0.13.0 # github.com/kubernetes-csi/csi-lib-utils v0.14.0
## explicit; go 1.18 ## explicit; go 1.18
github.com/kubernetes-csi/csi-lib-utils/connection github.com/kubernetes-csi/csi-lib-utils/connection
github.com/kubernetes-csi/csi-lib-utils/leaderelection github.com/kubernetes-csi/csi-lib-utils/leaderelection