Skip to content

Commit

Permalink
Merge pull request #864 from carlory/patch-001
Browse files Browse the repository at this point in the history
check if the csi driver is supported the volume group snapshot cap
  • Loading branch information
k8s-ci-robot authored Sep 6, 2023
2 parents ab6f8cc + c494031 commit 737d5fc
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
22 changes: 18 additions & 4 deletions cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ import (
"context"
"flag"
"fmt"
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter"
"net/http"
"os"
"os/signal"
"strings"
"time"

utils "github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"

"google.golang.org/grpc"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
coreinformers "k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand All @@ -51,7 +49,8 @@ import (
clientset "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned"
snapshotscheme "github.com/kubernetes-csi/external-snapshotter/client/v6/clientset/versioned/scheme"
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 (
Expand Down Expand Up @@ -229,6 +228,12 @@ func main() {
snapShotter := snapshotter.NewSnapshotter(csiConn)
var groupSnapshotter group_snapshotter.GroupSnapshotter
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)
if len(*groupSnapshotNamePrefix) == 0 {
klog.Error("group snapshot name prefix cannot be of length 0")
Expand Down Expand Up @@ -317,3 +322,12 @@ func supportsControllerCreateSnapshot(ctx context.Context, conn *grpc.ClientConn

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 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/golang/mock v1.6.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/external-snapshotter/client/v6 v6.1.0
github.com/prometheus/client_golang v1.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
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.13.0/go.mod h1:JS9eDIZmSjx4F9o0bLTVK/qfhIIOifdjEfVXzxWapfE=
github.com/kubernetes-csi/csi-lib-utils v0.14.0 h1:pusB32LkSd7GhuT8Z6cyRFqByujc28ygWV97ndaT19s=
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/go.mod h1:t1RzseMZJKy313nezI/d7TolbbiKpUZM3SXQvXxOX0w=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions vendor/github.com/kubernetes-csi/csi-lib-utils/rpc/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ github.com/josharian/intern
# github.com/json-iterator/go v1.1.12
## explicit; go 1.12
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
github.com/kubernetes-csi/csi-lib-utils/connection
github.com/kubernetes-csi/csi-lib-utils/leaderelection
Expand Down

0 comments on commit 737d5fc

Please sign in to comment.