Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix support for volume snapshots by setting snapshot id on volume creation. #129

Merged
merged 2 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,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