Skip to content

Commit c12c64e

Browse files
committed
rbd: implement GetSnapshot CSI procedure
See-also: container-storage-interface/spec#586 Signed-off-by: Niels de Vos <ndevos@ibm.com>
1 parent c19f472 commit c12c64e

File tree

7 files changed

+1403
-1170
lines changed

7 files changed

+1403
-1170
lines changed

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ require (
4343
k8s.io/utils v0.0.0-20241210054802-24370beab758
4444
)
4545

46+
// FIXME: for texting https://github.com/container-storage-interface/spec/pull/586
47+
replace github.com/container-storage-interface/spec => github.com/xing-yang/spec v0.1.1-0.20250423161802-69d15cde6003 // GetSnapshot branch
48+
4649
require (
4750
// sigs.k8s.io/controller-runtime wants this version, it gets replaced below
4851
k8s.io/client-go v12.0.0+incompatible

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
159159
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
160160
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
161161
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
162-
github.com/container-storage-interface/spec v1.11.0 h1:H/YKTOeUZwHtyPOr9raR+HgFmGluGCklulxDYxSdVNM=
163-
github.com/container-storage-interface/spec v1.11.0/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
164162
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
165163
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
166164
github.com/csi-addons/kubernetes-csi-addons v0.12.0 h1:RbF2dCjWV4ljynibEOkA0wbwwt/09awjOKgEFC14Bns=
@@ -652,6 +650,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
652650
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
653651
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
654652
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
653+
github.com/xing-yang/spec v0.1.1-0.20250423161802-69d15cde6003 h1:T9DDPr22JY/YzulKhQ5djqKCxAhRmmbxKUHbvZ+r7Ic=
654+
github.com/xing-yang/spec v0.1.1-0.20250423161802-69d15cde6003/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
655655
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
656656
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
657657
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

internal/rbd/controllerserver.go

+24
Original file line numberDiff line numberDiff line change
@@ -1701,3 +1701,27 @@ func (cs *ControllerServer) ControllerUnpublishVolume(
17011701

17021702
return &csi.ControllerUnpublishVolumeResponse{}, nil
17031703
}
1704+
1705+
func (cs *ControllerServer) GetSnapshot(
1706+
ctx context.Context,
1707+
req *csi.GetSnapshotRequest,
1708+
) (*csi.GetSnapshotResponse, error) {
1709+
mgr := NewManager(cs.Driver.GetInstanceID(), nil, req.GetSecrets())
1710+
defer mgr.Destroy(ctx)
1711+
1712+
snapID := req.GetSnapshotId()
1713+
snapshot, err := mgr.GetSnapshotByID(ctx, snapID)
1714+
if err != nil {
1715+
return nil, status.Errorf(codes.NotFound, "failed to find snapshot with ID %q: %s", snapID, err.Error())
1716+
}
1717+
defer snapshot.Destroy(ctx)
1718+
1719+
csiSnap, err := snapshot.ToCSI(ctx)
1720+
if err != nil {
1721+
return nil, status.Error(codes.Internal, err.Error())
1722+
}
1723+
1724+
return &csi.GetSnapshotResponse{
1725+
Snapshot: csiSnap,
1726+
}, nil
1727+
}

internal/rbd/driver/driver.go

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (r *Driver) Run(conf *util.Config) {
112112
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
113113
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
114114
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
115+
csi.ControllerServiceCapability_RPC_GET_SNAPSHOT,
115116
})
116117
// We only support the multi-writer option when using block, but it's a supported capability for the plugin in
117118
// general

0 commit comments

Comments
 (0)