@@ -224,14 +224,19 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
224
224
225
225
volKey , err := common .VolumeIDToKey (volumeID )
226
226
if err != nil {
227
- // Cannot find volume associated with this ID because can't even get the name or zone
228
- // This is a success according to the spec
227
+ // Cannot find volume associated with this ID because VolumeID is not in
228
+ // correct format, this is a success according to the Spec
229
+ klog .Warningf ("DeleteVolume treating volume as deleted because volume id %s is invalid: %v" , volumeID , err )
229
230
return & csi.DeleteVolumeResponse {}, nil
230
231
}
231
232
232
233
volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , volKey )
233
234
if err != nil {
234
- return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v: %v" , volumeID , err ))
235
+ if gce .IsGCENotFoundError (err ) {
236
+ klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err )
237
+ return & csi.DeleteVolumeResponse {}, nil
238
+ }
239
+ return nil , status .Errorf (codes .Internal , "DeleteVolume error repairing underspecified volume key: %v" , err )
235
240
}
236
241
237
242
if acquired := gceCS .volumeLocks .TryAcquire (volumeID ); ! acquired {
@@ -267,12 +272,15 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
267
272
268
273
volKey , err := common .VolumeIDToKey (volumeID )
269
274
if err != nil {
270
- return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v : %v" , volumeID , err ))
275
+ return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("ControllerPublishVolume volume ID is invalid : %v" , err ))
271
276
}
272
277
273
278
volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , volKey )
274
279
if err != nil {
275
- return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v: %v" , volumeID , err ))
280
+ if gce .IsGCENotFoundError (err ) {
281
+ return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err )
282
+ }
283
+ return nil , status .Errorf (codes .Internal , "ControllerPublishVolume error repairing underspecified volume key: %v" , err )
276
284
}
277
285
278
286
// Acquires the lock for the volume on that node only, because we need to support the ability
@@ -294,7 +302,7 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
294
302
295
303
_ , err = gceCS .CloudProvider .GetDisk (ctx , volKey )
296
304
if err != nil {
297
- if gce .IsGCEError (err , "notFound" ) {
305
+ if gce .IsGCENotFoundError (err ) {
298
306
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find disk %v: %v" , volKey .String (), err ))
299
307
}
300
308
return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown get disk error: %v" , err ))
@@ -305,7 +313,7 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
305
313
}
306
314
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
307
315
if err != nil {
308
- if gce .IsGCEError (err , "notFound" ) {
316
+ if gce .IsGCENotFoundError (err ) {
309
317
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find instance %v: %v" , nodeID , err ))
310
318
}
311
319
return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown get instance error: %v" , err ))
@@ -365,7 +373,7 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
365
373
366
374
volKey , err := common .VolumeIDToKey (volumeID )
367
375
if err != nil {
368
- return nil , err
376
+ return nil , status . Error ( codes . InvalidArgument , fmt . Sprintf ( "ControllerUnpublishVolume Volume ID is invalid: %v" , err ))
369
377
}
370
378
371
379
// Acquires the lock for the volume on that node only, because we need to support the ability
@@ -382,7 +390,12 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
382
390
}
383
391
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
384
392
if err != nil {
385
- return nil , err
393
+ if gce .IsGCENotFoundError (err ) {
394
+ // Node not existing on GCE means that disk has been detached
395
+ klog .Warningf ("Treating volume %v as unpublished because node %v could not be found" , volKey .String (), instanceName )
396
+ return & csi.ControllerUnpublishVolumeResponse {}, nil
397
+ }
398
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("error getting instance: %v" , err ))
386
399
}
387
400
388
401
deviceName , err := common .GetDeviceName (volKey )
@@ -420,7 +433,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
420
433
}
421
434
volKey , err := common .VolumeIDToKey (volumeID )
422
435
if err != nil {
423
- return nil , status .Error (codes .NotFound , fmt .Sprintf ("Volume ID is of improper format, got %v" , volumeID ))
436
+ return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("ValidateVolumeCapabilities Volume ID is invalid: %v" , err ))
424
437
}
425
438
426
439
if acquired := gceCS .volumeLocks .TryAcquire (volumeID ); ! acquired {
@@ -430,7 +443,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
430
443
431
444
_ , err = gceCS .CloudProvider .GetDisk (ctx , volKey )
432
445
if err != nil {
433
- if gce .IsGCEError (err , "notFound" ) {
446
+ if gce .IsGCENotFoundError (err ) {
434
447
return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find disk %v: %v" , volKey .Name , err ))
435
448
}
436
449
return nil , status .Error (codes .Internal , fmt .Sprintf ("Unknown get disk error: %v" , err ))
@@ -532,14 +545,23 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
532
545
}
533
546
volKey , err := common .VolumeIDToKey (volumeID )
534
547
if err != nil {
535
- return nil , status .Error (codes .NotFound , fmt .Sprintf ("Could not find volume with ID %v : %v" , volumeID , err ))
548
+ return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("CreateSnapshot Volume ID is invalid : %v" , err ))
536
549
}
537
550
538
551
if acquired := gceCS .volumeLocks .TryAcquire (volumeID ); ! acquired {
539
552
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , volumeID )
540
553
}
541
554
defer gceCS .volumeLocks .Release (volumeID )
542
555
556
+ // Check if volume exists
557
+ _ , err = gceCS .CloudProvider .GetDisk (ctx , volKey )
558
+ if err != nil {
559
+ if gce .IsGCENotFoundError (err ) {
560
+ return nil , status .Error (codes .NotFound , fmt .Sprintf ("CreateSnapshot could not find disk %v: %v" , volKey .String (), err ))
561
+ }
562
+ return nil , status .Error (codes .Internal , fmt .Sprintf ("CreateSnapshot unknown get disk error: %v" , err ))
563
+ }
564
+
543
565
// Check if snapshot already exists
544
566
var snapshot * compute.Snapshot
545
567
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , req .Name )
@@ -670,7 +692,7 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
670
692
671
693
volKey , err := common .VolumeIDToKey (volumeID )
672
694
if err != nil {
673
- return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("ControllerExpandVolume volume ID is invalid: %v" , err ))
695
+ return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("ControllerExpandVolume Volume ID is invalid: %v" , err ))
674
696
}
675
697
676
698
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , volKey , reqBytes )
0 commit comments