Skip to content

Commit a3e2af9

Browse files
committed
Add ControllerServer.GetSnapshot CSI procedure
1 parent e5b1f6b commit a3e2af9

File tree

6 files changed

+1409
-1171
lines changed

6 files changed

+1409
-1171
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.0
55
toolchain go1.24.3
66

77
require (
8-
github.com/container-storage-interface/spec v1.11.0
8+
github.com/container-storage-interface/spec v1.11.1-0.20250515121015-a539b4f9fe41
99
github.com/kubernetes-csi/csi-lib-utils v0.20.0
1010
github.com/pborman/uuid v1.2.1
1111
github.com/stretchr/testify v1.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM
44
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
55
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
66
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
7-
github.com/container-storage-interface/spec v1.11.0 h1:H/YKTOeUZwHtyPOr9raR+HgFmGluGCklulxDYxSdVNM=
8-
github.com/container-storage-interface/spec v1.11.0/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
7+
github.com/container-storage-interface/spec v1.11.1-0.20250515121015-a539b4f9fe41 h1:7+UfUxukJlnEVGALQzUcCYXP/ISyS/VZJ7DPpAQxROY=
8+
github.com/container-storage-interface/spec v1.11.1-0.20250515121015-a539b4f9fe41/go.mod h1:DtUvaQszPml1YJfIK7c00mlv6/g4wNMLanLgiUbKFRI=
99
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
1010
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1111
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=

pkg/hostpath/controllerserver.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,39 @@ func (hp *hostPath) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReq
773773
}, nil
774774
}
775775

776+
func (hp *hostPath) GetSnapshot(ctx context.Context, req *csi.GetSnapshotRequest) (*csi.GetSnapshotResponse, error) {
777+
if err := hp.validateControllerServiceRequest(csi.ControllerServiceCapability_RPC_GET_SNAPSHOT); err != nil {
778+
klog.V(3).Infof("invalid get snapshot req: %v", req)
779+
return nil, err
780+
}
781+
782+
// Lock before acting on global state. A production-quality
783+
// driver might use more fine-grained locking.
784+
hp.mutex.Lock()
785+
defer hp.mutex.Unlock()
786+
787+
// case 1: SnapshotId is not empty, return snapshots that match the snapshot id,
788+
// none if not found.
789+
if len(req.GetSnapshotId()) == 0 {
790+
}
791+
792+
snapshotID := req.SnapshotId
793+
snapshot, err := hp.state.GetSnapshotByID(snapshotID)
794+
if err != nil {
795+
return nil, status.Errorf(codes.NotFound, "Snapshot with ID %q not found: %v", snapshotID, err)
796+
}
797+
798+
return &csi.GetSnapshotResponse{
799+
Snapshot: &csi.Snapshot{
800+
SnapshotId: snapshot.Id,
801+
SourceVolumeId: snapshot.VolID,
802+
CreationTime: snapshot.CreationTime,
803+
SizeBytes: snapshot.SizeBytes,
804+
ReadyToUse: snapshot.ReadyToUse,
805+
},
806+
}, nil
807+
}
808+
776809
func (hp *hostPath) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
777810
if !hp.config.EnableVolumeExpansion {
778811
return nil, status.Error(codes.Unimplemented, "ControllerExpandVolume is not supported")
@@ -878,6 +911,7 @@ func (hp *hostPath) getControllerServiceCapabilities() []*csi.ControllerServiceC
878911
csi.ControllerServiceCapability_RPC_GET_CAPACITY,
879912
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
880913
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
914+
csi.ControllerServiceCapability_RPC_GET_SNAPSHOT,
881915
csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
882916
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
883917
csi.ControllerServiceCapability_RPC_VOLUME_CONDITION,

0 commit comments

Comments
 (0)