Skip to content

Commit

Permalink
check if the csi driver is supported the volume group snapshot cap wh…
Browse files Browse the repository at this point in the history
…en the --enable-volume-group-snapshots arg is true
  • Loading branch information
carlory committed Jun 25, 2023
1 parent dd523a0 commit fbfc135
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
21 changes: 20 additions & 1 deletion cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"context"
"flag"
"fmt"
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter"
"net/http"
"os"
"os/signal"
"strings"
"time"

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

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

"google.golang.org/grpc"
Expand Down Expand Up @@ -229,6 +230,15 @@ 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)
os.Exit(1)
}
if !supportsCreateVolumeGroupSnapshot {
klog.Errorf("CSI driver %s does not support GroupControllerCreateVolumeGroupSnapshot", driverName)
os.Exit(1)
}
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 +327,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 fbfc135

Please sign in to comment.