Skip to content

Commit

Permalink
Fix support for volume snapshots by setting snapshot id on volume cre…
Browse files Browse the repository at this point in the history
…ation.
  • Loading branch information
Justin Barrick committed Mar 1, 2019
1 parent 685a76e commit 4e9c09b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
9 changes: 9 additions & 0 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
SizeGigaBytes: size / GB,
}

contentSource := req.GetVolumeContentSource()
if contentSource != nil {
snapshot := contentSource.GetSnapshot()
if snapshot != nil {
ll.Info("using snapshot as volume source")
volumeReq.SnapshotID = snapshot.GetId()
}
}

ll.Info("checking volume limit")
if err := d.checkLimit(ctx); err != nil {
return nil, err
Expand Down
38 changes: 34 additions & 4 deletions test/kubernetes/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ func TestSnapshot_Create(t *testing.T) {
Name: "my-csi-app-2",
},
Spec: v1.PodSpec{
InitContainers: []v1.Container{
{
Name: "my-csi",
Image: "busybox",
VolumeMounts: []v1.VolumeMount{
{
MountPath: "/data",
Name: volumeName,
},
},
Command: []string{
"sh", "-c",
"echo testcanary > /data/canary",
},
},
},
Containers: []v1.Container{
{
Name: "my-csi-app",
Expand All @@ -369,8 +385,7 @@ func TestSnapshot_Create(t *testing.T) {
},
},
Command: []string{
"sleep",
"1000000",
"sleep", "1000000",
},
},
},
Expand Down Expand Up @@ -476,6 +491,22 @@ func TestSnapshot_Create(t *testing.T) {
Name: "my-csi-app-2-restored",
},
Spec: v1.PodSpec{
InitContainers: []v1.Container{
{
Name: "my-csi",
Image: "busybox",
VolumeMounts: []v1.VolumeMount{
{
MountPath: "/data",
Name: volumeName,
},
},
Command: []string{
"cat",
"/data/canary",
},
},
},
Containers: []v1.Container{
{
Name: "my-csi-app",
Expand All @@ -487,8 +518,7 @@ func TestSnapshot_Create(t *testing.T) {
},
},
Command: []string{
"sleep",
"1000000",
"sleep", "1000000",
},
},
},
Expand Down

0 comments on commit 4e9c09b

Please sign in to comment.