Skip to content

Commit

Permalink
Merge pull request #129 from justinbarrick/release-0.4.0
Browse files Browse the repository at this point in the history
Fix support for volume snapshots by setting snapshot id on volume creation.
  • Loading branch information
fatih authored and jcodybaker committed Apr 25, 2019
1 parent 5ff421a commit edbc695
Show file tree
Hide file tree
Showing 2 changed files with 33 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 @@ -156,6 +156,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
volumeReq.Tags = append(volumeReq.Tags, d.doTag)
}

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

ll.Info("checking volume limit")
if err := d.checkLimit(ctx); err != nil {
return nil, err
Expand Down
28 changes: 24 additions & 4 deletions test/kubernetes/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ func TestSnapshot_Create(t *testing.T) {
},
},
Command: []string{
"sleep",
"1000000",
"sh", "-c",
"echo testcanary > /data/canary && sleep 1000000",
},
},
},
Expand Down Expand Up @@ -476,6 +476,27 @@ func TestSnapshot_Create(t *testing.T) {
Name: "my-csi-app-2-restored",
},
Spec: v1.PodSpec{
// This init container verifies that the /data/canary file is present.
// If it is not, then the volume was not properly restored.
// waitForPod only waits for the pod to enter the running state, so will not
// detect any failures after that, so this has to be an InitContainer so that
// the pod never enters the running state if it fails.
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 +508,7 @@ func TestSnapshot_Create(t *testing.T) {
},
},
Command: []string{
"sleep",
"1000000",
"sleep", "1000000",
},
},
},
Expand Down

0 comments on commit edbc695

Please sign in to comment.