@@ -24,6 +24,7 @@ import (
24
24
"github.com/golang/protobuf/ptypes"
25
25
26
26
"context"
27
+
27
28
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
28
29
csi "github.com/container-storage-interface/spec/lib/go/csi"
29
30
compute "google.golang.org/api/compute/v1"
@@ -163,6 +164,14 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
163
164
if content .GetSnapshot () != nil {
164
165
// TODO(#161): Add support for Volume Source (cloning) introduced in CSI v1.0.0
165
166
snapshotId = content .GetSnapshot ().GetSnapshotId ()
167
+
168
+ // Verify that snapshot exists
169
+ sl , err := gceCS .getSnapshotById (ctx , snapshotId )
170
+ if err != nil {
171
+ return nil , status .Errorf (codes .Internal , "CreateVolume failed to get snapshot %s: %v" , snapshotId , err )
172
+ } else if len (sl .Entries ) == 0 {
173
+ return nil , status .Errorf (codes .NotFound , "CreateVolume source snapshot %s does not exist" , snapshotId )
174
+ }
166
175
}
167
176
}
168
177
@@ -171,7 +180,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
171
180
switch replicationType {
172
181
case replicationTypeNone :
173
182
if len (zones ) != 1 {
174
- return nil , status .Errorf (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones ))
183
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateVolume failed to get a single zone for creating zonal disk, instead got: %v" , zones ))
175
184
}
176
185
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , diskType , capacityRange , capBytes , snapshotId , diskEncryptionKmsKey )
177
186
if err != nil {
0 commit comments