Skip to content

Commit 0bf66d5

Browse files
committed
check if the csi driver is supported the volume group snapshot cap when the --enable-volume-group-snapshots arg is true
1 parent dd523a0 commit 0bf66d5

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

cmd/csi-snapshotter/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ import (
2020
"context"
2121
"flag"
2222
"fmt"
23-
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter"
2423
"net/http"
2524
"os"
2625
"os/signal"
2726
"strings"
2827
"time"
2928

29+
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter"
30+
3031
utils "github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"
3132

3233
"google.golang.org/grpc"
@@ -229,6 +230,15 @@ func main() {
229230
snapShotter := snapshotter.NewSnapshotter(csiConn)
230231
var groupSnapshotter group_snapshotter.GroupSnapshotter
231232
if *enableVolumeGroupSnapshots {
233+
supportsCreateVolumeGroupSnapshot, err := supportsGroupControllerCreateVolumeGroupSnapshot(ctx, csiConn)
234+
if err != nil {
235+
klog.Errorf("error determining if driver supports create/delete group snapshot operations: %v", err)
236+
os.Exit(1)
237+
}
238+
if !supportsCreateVolumeGroupSnapshot {
239+
klog.Errorf("CSI driver %s does not support GroupControllerCreateVolumeGroupSnapshot", driverName)
240+
os.Exit(1)
241+
}
232242
groupSnapshotter = group_snapshotter.NewGroupSnapshotter(csiConn)
233243
if len(*groupSnapshotNamePrefix) == 0 {
234244
klog.Error("group snapshot name prefix cannot be of length 0")
@@ -317,3 +327,12 @@ func supportsControllerCreateSnapshot(ctx context.Context, conn *grpc.ClientConn
317327

318328
return capabilities[csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT], nil
319329
}
330+
331+
func supportsGroupControllerCreateVolumeGroupSnapshot(ctx context.Context, conn *grpc.ClientConn) (bool, error) {
332+
capabilities, err := csirpc.GetGroupControllerCapabilities(ctx, conn)
333+
if err != nil {
334+
return false, err
335+
}
336+
337+
return capabilities[csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT], nil
338+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/fsnotify/fsnotify v1.6.0
99
github.com/golang/mock v1.6.0
1010
github.com/google/gofuzz v1.2.0
11-
github.com/kubernetes-csi/csi-lib-utils v0.13.0
11+
github.com/kubernetes-csi/csi-lib-utils v0.13.1-0.20230614195818-bfa15ceaac7f
1212
github.com/kubernetes-csi/csi-test/v4 v4.4.0
1313
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.1.0
1414
github.com/prometheus/client_golang v1.16.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
124124
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
125125
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
126126
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
127-
github.com/kubernetes-csi/csi-lib-utils v0.13.0 h1:QrTdZVZbHlaSUBN9ReayBPnnF1N0edFIpUKBwVIBW3w=
128-
github.com/kubernetes-csi/csi-lib-utils v0.13.0/go.mod h1:JS9eDIZmSjx4F9o0bLTVK/qfhIIOifdjEfVXzxWapfE=
127+
github.com/kubernetes-csi/csi-lib-utils v0.13.1-0.20230614195818-bfa15ceaac7f h1:a2zXCQoCaG0UVQcakxaJ4HnkSNB/zFrvubqzNMT38Qc=
128+
github.com/kubernetes-csi/csi-lib-utils v0.13.1-0.20230614195818-bfa15ceaac7f/go.mod h1:uX8xidqxGJOLXtsfCCVsxWtZl/9NiLyd2DD3Nb+KoP4=
129129
github.com/kubernetes-csi/csi-test/v4 v4.4.0 h1:r0mnAwDURI24Vw3a/LyA/ga11yD5ZGuU7+REO35Na9s=
130130
github.com/kubernetes-csi/csi-test/v4 v4.4.0/go.mod h1:t1RzseMZJKy313nezI/d7TolbbiKpUZM3SXQvXxOX0w=
131131
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=

vendor/github.com/kubernetes-csi/csi-lib-utils/connection/connection.go

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/kubernetes-csi/csi-lib-utils/rpc/common.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ github.com/josharian/intern
9090
# github.com/json-iterator/go v1.1.12
9191
## explicit; go 1.12
9292
github.com/json-iterator/go
93-
# github.com/kubernetes-csi/csi-lib-utils v0.13.0
93+
# github.com/kubernetes-csi/csi-lib-utils v0.13.1-0.20230614195818-bfa15ceaac7f
9494
## explicit; go 1.18
9595
github.com/kubernetes-csi/csi-lib-utils/connection
9696
github.com/kubernetes-csi/csi-lib-utils/leaderelection

0 commit comments

Comments
 (0)