@@ -30,31 +30,14 @@ import (
30
30
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/util"
31
31
)
32
32
33
- var (
34
-
35
- // Supported volume capabilities
36
- volumeCaps = []csi.VolumeCapability_AccessMode {
37
- {
38
- Mode : csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER ,
39
- },
40
- {
41
- Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER ,
42
- },
43
- {
44
- Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ,
45
- },
46
- }
47
-
48
- // Shareable volume capabilities
49
- shareableVolumeCaps = []csi.VolumeCapability_AccessMode {
50
- {
51
- Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER ,
52
- },
53
- {
54
- Mode : csi .VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY ,
55
- },
56
- }
33
+ // Supported access modes
34
+ const (
35
+ SingleNodeWriter = csi .VolumeCapability_AccessMode_SINGLE_NODE_WRITER
36
+ MultiNodeMultiWriter = csi .VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER
37
+ MultiNodeReaderOnly = csi .VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY
38
+ )
57
39
40
+ var (
58
41
// controllerCaps represents the capability of controller service
59
42
controllerCaps = []csi.ControllerServiceCapability_RPC_Type {
60
43
csi .ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME ,
@@ -68,6 +51,7 @@ type controllerService struct {
68
51
cloud cloud.Cloud
69
52
driverOptions * Options
70
53
volumeLocks * util.VolumeLocks
54
+ csi.UnimplementedControllerServer
71
55
}
72
56
73
57
// Provider holds information from the cloud provider.
@@ -142,7 +126,7 @@ func newControllerService(driverOptions *Options) controllerService {
142
126
}
143
127
144
128
func (d * controllerService ) CreateVolume (ctx context.Context , req * csi.CreateVolumeRequest ) (* csi.CreateVolumeResponse , error ) {
145
- klog .V (4 ).Infof ("CreateVolume: called with args %+v" , * req )
129
+ klog .V (4 ).Infof ("CreateVolume: called with args %+v" , req )
146
130
volName := req .GetName ()
147
131
if len (volName ) == 0 {
148
132
return nil , status .Error (codes .InvalidArgument , "Volume name not provided" )
@@ -212,7 +196,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
212
196
}
213
197
214
198
func (d * controllerService ) DeleteVolume (ctx context.Context , req * csi.DeleteVolumeRequest ) (* csi.DeleteVolumeResponse , error ) {
215
- klog .V (4 ).Infof ("DeleteVolume: called with args: %+v" , * req )
199
+ klog .V (4 ).Infof ("DeleteVolume: called with args: %+v" , req )
216
200
volumeID := req .GetVolumeId ()
217
201
if len (volumeID ) == 0 {
218
202
return nil , status .Error (codes .InvalidArgument , "Volume ID not provided" )
@@ -238,7 +222,7 @@ func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol
238
222
}
239
223
240
224
func (d * controllerService ) ControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
241
- klog .V (4 ).Infof ("ControllerPublishVolume: called with args %+v" , * req )
225
+ klog .V (4 ).Infof ("ControllerPublishVolume: called with args %+v" , req )
242
226
volumeID := req .GetVolumeId ()
243
227
if len (volumeID ) == 0 {
244
228
return nil , status .Error (codes .InvalidArgument , "Volume ID not provided" )
@@ -300,7 +284,7 @@ func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *cs
300
284
}
301
285
302
286
func (d * controllerService ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
303
- klog .V (4 ).Infof ("ControllerUnpublishVolume: called with args %+v" , * req )
287
+ klog .V (4 ).Infof ("ControllerUnpublishVolume: called with args %+v" , req )
304
288
volumeID := req .GetVolumeId ()
305
289
if len (volumeID ) == 0 {
306
290
return nil , status .Error (codes .InvalidArgument , "Volume ID not provided" )
@@ -337,7 +321,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *
337
321
}
338
322
339
323
func (d * controllerService ) ControllerGetCapabilities (ctx context.Context , req * csi.ControllerGetCapabilitiesRequest ) (* csi.ControllerGetCapabilitiesResponse , error ) {
340
- klog .V (4 ).Infof ("ControllerGetCapabilities: called with args %+v" , * req )
324
+ klog .V (4 ).Infof ("ControllerGetCapabilities: called with args %+v" , req )
341
325
var caps []* csi.ControllerServiceCapability
342
326
for _ , cap := range controllerCaps {
343
327
c := & csi.ControllerServiceCapability {
@@ -353,17 +337,17 @@ func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *
353
337
}
354
338
355
339
func (d * controllerService ) GetCapacity (ctx context.Context , req * csi.GetCapacityRequest ) (* csi.GetCapacityResponse , error ) {
356
- klog .V (4 ).Infof ("GetCapacity: called with args %+v" , * req )
340
+ klog .V (4 ).Infof ("GetCapacity: called with args %+v" , req )
357
341
return nil , status .Error (codes .Unimplemented , "" )
358
342
}
359
343
360
344
func (d * controllerService ) ListVolumes (ctx context.Context , req * csi.ListVolumesRequest ) (* csi.ListVolumesResponse , error ) {
361
- klog .V (4 ).Infof ("ListVolumes: called with args %+v" , * req )
345
+ klog .V (4 ).Infof ("ListVolumes: called with args %+v" , req )
362
346
return nil , status .Error (codes .Unimplemented , "" )
363
347
}
364
348
365
349
func (d * controllerService ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
366
- klog .V (4 ).Infof ("ValidateVolumeCapabilities: called with args %+v" , * req )
350
+ klog .V (4 ).Infof ("ValidateVolumeCapabilities: called with args %+v" , req )
367
351
volumeID := req .GetVolumeId ()
368
352
if len (volumeID ) == 0 {
369
353
return nil , status .Error (codes .InvalidArgument , "Volume ID not provided" )
@@ -391,7 +375,7 @@ func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req
391
375
}
392
376
393
377
func (d * controllerService ) ControllerExpandVolume (ctx context.Context , req * csi.ControllerExpandVolumeRequest ) (* csi.ControllerExpandVolumeResponse , error ) {
394
- klog .V (4 ).Infof ("ControllerExpandVolume: called with args %+v" , * req )
378
+ klog .V (4 ).Infof ("ControllerExpandVolume: called with args %+v" , req )
395
379
volumeID := req .GetVolumeId ()
396
380
if len (volumeID ) == 0 {
397
381
return nil , status .Error (codes .InvalidArgument , "Volume ID not provided" )
@@ -425,47 +409,30 @@ func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi
425
409
}
426
410
427
411
func (d * controllerService ) ControllerGetVolume (ctx context.Context , req * csi.ControllerGetVolumeRequest ) (* csi.ControllerGetVolumeResponse , error ) {
428
- klog .V (4 ).Infof ("ControllerGetVolume: called with args %+v" , * req )
412
+ klog .V (4 ).Infof ("ControllerGetVolume: called with args %+v" , req )
429
413
return nil , status .Error (codes .Unimplemented , "" )
430
414
}
431
415
432
416
func (d * controllerService ) ControllerModifyVolume (ctx context.Context , req * csi.ControllerModifyVolumeRequest ) (* csi.ControllerModifyVolumeResponse , error ) {
433
- klog .V (4 ).InfoS ("ControllerModifyVolume: called with args %+v" , * req )
417
+ klog .V (4 ).InfoS ("ControllerModifyVolume: called with args %+v" , req )
434
418
return nil , status .Error (codes .Unimplemented , "" )
435
419
}
436
420
437
421
func isValidVolumeCapabilities (volCaps []* csi.VolumeCapability ) bool {
438
- hasSupport := func (cap * csi.VolumeCapability ) bool {
439
- for _ , c := range volumeCaps {
440
- if c .GetMode () == cap .AccessMode .GetMode () {
441
- return true
442
- }
443
- }
444
- return false
445
- }
446
-
447
- foundAll := true
448
422
for _ , c := range volCaps {
449
- if ! hasSupport (c ) {
450
- foundAll = false
423
+ mode := c .AccessMode .GetMode ()
424
+ if mode != SingleNodeWriter && mode != MultiNodeMultiWriter && mode != MultiNodeReaderOnly {
425
+ return false
451
426
}
452
427
}
453
- return foundAll
428
+ return true
454
429
}
455
430
456
431
// Check if the volume is shareable
457
432
func isShareableVolume (volCaps []* csi.VolumeCapability ) bool {
458
- isShareable := func (cap * csi.VolumeCapability ) bool {
459
- for _ , c := range shareableVolumeCaps {
460
- if c .GetMode () == cap .AccessMode .GetMode () {
461
- return true
462
- }
463
- }
464
- return false
465
- }
466
-
467
433
for _ , c := range volCaps {
468
- if isShareable (c ) {
434
+ mode := c .AccessMode .GetMode ()
435
+ if mode == MultiNodeMultiWriter || mode == MultiNodeReaderOnly {
469
436
return true
470
437
}
471
438
}
0 commit comments