@@ -52,40 +52,6 @@ const (
52
52
attachableDiskTypePersistent = "PERSISTENT"
53
53
)
54
54
55
- func getRequestCapacity (capRange * csi.CapacityRange ) (int64 , error ) {
56
- // TODO: Take another look at these casts/caps. Make sure this func is correct
57
- var capBytes int64
58
- // Default case where nothing is set
59
- if capRange == nil {
60
- capBytes = MinimumVolumeSizeInBytes
61
- return capBytes , nil
62
- }
63
-
64
- rBytes := capRange .GetRequiredBytes ()
65
- rSet := rBytes > 0
66
- lBytes := capRange .GetLimitBytes ()
67
- lSet := lBytes > 0
68
-
69
- if lSet && rSet && lBytes < rBytes {
70
- return 0 , fmt .Errorf ("Limit bytes %v is less than required bytes %v" , lBytes , rBytes )
71
- }
72
- if lSet && lBytes < MinimumVolumeSizeInBytes {
73
- return 0 , fmt .Errorf ("Limit bytes %v is less than minimum volume size: %v" , lBytes , MinimumVolumeSizeInBytes )
74
- }
75
-
76
- // If Required set just set capacity to that which is Required
77
- if rSet {
78
- capBytes = rBytes
79
- }
80
-
81
- // Limit is more than Required, but larger than Minimum. So we just set capcity to Minimum
82
- // Too small, default
83
- if capBytes < MinimumVolumeSizeInBytes {
84
- capBytes = MinimumVolumeSizeInBytes
85
- }
86
- return capBytes , nil
87
- }
88
-
89
55
func (gceCS * GCEControllerServer ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
90
56
// TODO: Check create zone against Driver zone. They must MATCH
91
57
glog .Infof ("CreateVolume called with request %v" , * req )
@@ -213,9 +179,7 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
213
179
214
180
zone , name , err := utils .SplitZoneNameId (volumeID )
215
181
if err != nil {
216
- // Cannot find volume associated with this ID because can't even get the name or zone
217
- // This is a success according to the spec
218
- return & csi.DeleteVolumeResponse {}, nil
182
+ return nil , status .Error (codes .InvalidArgument , fmt .Sprintf ("DeleteVolume Volume ID could not be split into parts: %v" , err ))
219
183
}
220
184
221
185
deleteOp , err := gceCS .CloudProvider .DeleteDisk (ctx , zone , name )
@@ -371,31 +335,6 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
371
335
return & csi.ControllerUnpublishVolumeResponse {}, nil
372
336
}
373
337
374
- // TODO: This abstraction isn't great. We shouldn't need diskIsAttached AND diskIsAttachedAndCompatible to duplicate code
375
- func diskIsAttached (volume * compute.Disk , instance * compute.Instance ) bool {
376
- for _ , disk := range instance .Disks {
377
- if disk .DeviceName == volume .Name {
378
- // Disk is attached to node
379
- return true
380
- }
381
- }
382
- return false
383
- }
384
-
385
- func diskIsAttachedAndCompatible (volume * compute.Disk , instance * compute.Instance , volumeCapability * csi.VolumeCapability , readWrite string ) (bool , error ) {
386
- for _ , disk := range instance .Disks {
387
- if disk .DeviceName == volume .Name {
388
- // Disk is attached to node
389
- if disk .Mode != readWrite {
390
- return true , fmt .Errorf ("disk mode does not match. Got %v. Want %v" , disk .Mode , readWrite )
391
- }
392
- // TODO: Check volume_capability.
393
- return true , nil
394
- }
395
- }
396
- return false , nil
397
- }
398
-
399
338
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
400
339
// TODO: Factor out the volume capability functionality and use as validation in all other functions as well
401
340
glog .V (5 ).Infof ("Using default ValidateVolumeCapabilities" )
@@ -459,3 +398,61 @@ func (gceCS *GCEControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
459
398
func (gceCS * GCEControllerServer ) ListSnapshots (ctx context.Context , req * csi.ListSnapshotsRequest ) (* csi.ListSnapshotsResponse , error ) {
460
399
return nil , status .Error (codes .Unimplemented , "" )
461
400
}
401
+
402
+ func getRequestCapacity (capRange * csi.CapacityRange ) (int64 , error ) {
403
+ // TODO: Take another look at these casts/caps. Make sure this func is correct
404
+ var capBytes int64
405
+ // Default case where nothing is set
406
+ if capRange == nil {
407
+ capBytes = MinimumVolumeSizeInBytes
408
+ return capBytes , nil
409
+ }
410
+
411
+ rBytes := capRange .GetRequiredBytes ()
412
+ rSet := rBytes > 0
413
+ lBytes := capRange .GetLimitBytes ()
414
+ lSet := lBytes > 0
415
+
416
+ if lSet && rSet && lBytes < rBytes {
417
+ return 0 , fmt .Errorf ("Limit bytes %v is less than required bytes %v" , lBytes , rBytes )
418
+ }
419
+ if lSet && lBytes < MinimumVolumeSizeInBytes {
420
+ return 0 , fmt .Errorf ("Limit bytes %v is less than minimum volume size: %v" , lBytes , MinimumVolumeSizeInBytes )
421
+ }
422
+
423
+ // If Required set just set capacity to that which is Required
424
+ if rSet {
425
+ capBytes = rBytes
426
+ }
427
+
428
+ // Limit is more than Required, but larger than Minimum. So we just set capcity to Minimum
429
+ // Too small, default
430
+ if capBytes < MinimumVolumeSizeInBytes {
431
+ capBytes = MinimumVolumeSizeInBytes
432
+ }
433
+ return capBytes , nil
434
+ }
435
+
436
+ func diskIsAttached (volume * compute.Disk , instance * compute.Instance ) bool {
437
+ for _ , disk := range instance .Disks {
438
+ if disk .DeviceName == volume .Name {
439
+ // Disk is attached to node
440
+ return true
441
+ }
442
+ }
443
+ return false
444
+ }
445
+
446
+ func diskIsAttachedAndCompatible (volume * compute.Disk , instance * compute.Instance , volumeCapability * csi.VolumeCapability , readWrite string ) (bool , error ) {
447
+ for _ , disk := range instance .Disks {
448
+ if disk .DeviceName == volume .Name {
449
+ // Disk is attached to node
450
+ if disk .Mode != readWrite {
451
+ return true , fmt .Errorf ("disk mode does not match. Got %v. Want %v" , disk .Mode , readWrite )
452
+ }
453
+ // TODO: Check volume_capability.
454
+ return true , nil
455
+ }
456
+ }
457
+ return false , nil
458
+ }
0 commit comments