Skip to content

Commit e9734d1

Browse files
committed
Fixes for govet errors
Signed-off-by: Yussuf Shaikh <[email protected]>
1 parent 539b40c commit e9734d1

File tree

4 files changed

+39
-73
lines changed

4 files changed

+39
-73
lines changed

pkg/driver/controller.go

Lines changed: 24 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,14 @@ import (
3030
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/util"
3131
)
3232

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+
)
5739

40+
var (
5841
// controllerCaps represents the capability of controller service
5942
controllerCaps = []csi.ControllerServiceCapability_RPC_Type{
6043
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
@@ -143,7 +126,7 @@ func newControllerService(driverOptions *Options) controllerService {
143126
}
144127

145128
func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
146-
klog.V(4).Infof("CreateVolume: called with args %+v", *req)
129+
klog.V(4).Infof("CreateVolume: called with args %+v", req)
147130
volName := req.GetName()
148131
if len(volName) == 0 {
149132
return nil, status.Error(codes.InvalidArgument, "Volume name not provided")
@@ -213,7 +196,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol
213196
}
214197

215198
func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
216-
klog.V(4).Infof("DeleteVolume: called with args: %+v", *req)
199+
klog.V(4).Infof("DeleteVolume: called with args: %+v", req)
217200
volumeID := req.GetVolumeId()
218201
if len(volumeID) == 0 {
219202
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -239,7 +222,7 @@ func (d *controllerService) DeleteVolume(ctx context.Context, req *csi.DeleteVol
239222
}
240223

241224
func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
242-
klog.V(4).Infof("ControllerPublishVolume: called with args %+v", *req)
225+
klog.V(4).Infof("ControllerPublishVolume: called with args %+v", req)
243226
volumeID := req.GetVolumeId()
244227
if len(volumeID) == 0 {
245228
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -301,7 +284,7 @@ func (d *controllerService) ControllerPublishVolume(ctx context.Context, req *cs
301284
}
302285

303286
func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
304-
klog.V(4).Infof("ControllerUnpublishVolume: called with args %+v", *req)
287+
klog.V(4).Infof("ControllerUnpublishVolume: called with args %+v", req)
305288
volumeID := req.GetVolumeId()
306289
if len(volumeID) == 0 {
307290
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -338,7 +321,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *
338321
}
339322

340323
func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
341-
klog.V(4).Infof("ControllerGetCapabilities: called with args %+v", *req)
324+
klog.V(4).Infof("ControllerGetCapabilities: called with args %+v", req)
342325
var caps []*csi.ControllerServiceCapability
343326
for _, cap := range controllerCaps {
344327
c := &csi.ControllerServiceCapability{
@@ -354,17 +337,17 @@ func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *
354337
}
355338

356339
func (d *controllerService) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
357-
klog.V(4).Infof("GetCapacity: called with args %+v", *req)
340+
klog.V(4).Infof("GetCapacity: called with args %+v", req)
358341
return nil, status.Error(codes.Unimplemented, "")
359342
}
360343

361344
func (d *controllerService) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
362-
klog.V(4).Infof("ListVolumes: called with args %+v", *req)
345+
klog.V(4).Infof("ListVolumes: called with args %+v", req)
363346
return nil, status.Error(codes.Unimplemented, "")
364347
}
365348

366349
func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
367-
klog.V(4).Infof("ValidateVolumeCapabilities: called with args %+v", *req)
350+
klog.V(4).Infof("ValidateVolumeCapabilities: called with args %+v", req)
368351
volumeID := req.GetVolumeId()
369352
if len(volumeID) == 0 {
370353
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -392,7 +375,7 @@ func (d *controllerService) ValidateVolumeCapabilities(ctx context.Context, req
392375
}
393376

394377
func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
395-
klog.V(4).Infof("ControllerExpandVolume: called with args %+v", *req)
378+
klog.V(4).Infof("ControllerExpandVolume: called with args %+v", req)
396379
volumeID := req.GetVolumeId()
397380
if len(volumeID) == 0 {
398381
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -426,47 +409,30 @@ func (d *controllerService) ControllerExpandVolume(ctx context.Context, req *csi
426409
}
427410

428411
func (d *controllerService) ControllerGetVolume(ctx context.Context, req *csi.ControllerGetVolumeRequest) (*csi.ControllerGetVolumeResponse, error) {
429-
klog.V(4).Infof("ControllerGetVolume: called with args %+v", *req)
412+
klog.V(4).Infof("ControllerGetVolume: called with args %+v", req)
430413
return nil, status.Error(codes.Unimplemented, "")
431414
}
432415

433416
func (d *controllerService) ControllerModifyVolume(ctx context.Context, req *csi.ControllerModifyVolumeRequest) (*csi.ControllerModifyVolumeResponse, error) {
434-
klog.V(4).InfoS("ControllerModifyVolume: called with args %+v", *req)
417+
klog.V(4).InfoS("ControllerModifyVolume: called with args %+v", req)
435418
return nil, status.Error(codes.Unimplemented, "")
436419
}
437420

438421
func isValidVolumeCapabilities(volCaps []*csi.VolumeCapability) bool {
439-
hasSupport := func(cap *csi.VolumeCapability) bool {
440-
for _, c := range volumeCaps {
441-
if c.GetMode() == cap.AccessMode.GetMode() {
442-
return true
443-
}
444-
}
445-
return false
446-
}
447-
448-
foundAll := true
449422
for _, c := range volCaps {
450-
if !hasSupport(c) {
451-
foundAll = false
423+
mode := c.AccessMode.GetMode()
424+
if mode != SingleNodeWriter && mode != MultiNodeMultiWriter && mode != MultiNodeReaderOnly {
425+
return false
452426
}
453427
}
454-
return foundAll
428+
return true
455429
}
456430

457431
// Check if the volume is shareable
458432
func isShareableVolume(volCaps []*csi.VolumeCapability) bool {
459-
isShareable := func(cap *csi.VolumeCapability) bool {
460-
for _, c := range shareableVolumeCaps {
461-
if c.GetMode() == cap.AccessMode.GetMode() {
462-
return true
463-
}
464-
}
465-
return false
466-
}
467-
468433
for _, c := range volCaps {
469-
if isShareable(c) {
434+
mode := c.AccessMode.GetMode()
435+
if mode == MultiNodeMultiWriter || mode == MultiNodeReaderOnly {
470436
return true
471437
}
472438
}

pkg/driver/identity.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
27-
klog.V(6).Infof("GetPluginInfo: called with args %+v", *req)
27+
klog.V(6).Infof("GetPluginInfo: called with args %+v", req)
2828
resp := &csi.GetPluginInfoResponse{
2929
Name: DriverName,
3030
VendorVersion: driverVersion,
@@ -34,7 +34,7 @@ func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoReques
3434
}
3535

3636
func (d *Driver) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
37-
klog.V(6).Infof("GetPluginCapabilities: called with args %+v", *req)
37+
klog.V(6).Infof("GetPluginCapabilities: called with args %+v", req)
3838
resp := &csi.GetPluginCapabilitiesResponse{
3939
Capabilities: []*csi.PluginCapability{
4040
{
@@ -58,6 +58,6 @@ func (d *Driver) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCa
5858
}
5959

6060
func (d *Driver) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
61-
klog.V(6).Infof("Probe: called with args %+v", *req)
61+
klog.V(6).Infof("Probe: called with args %+v", req)
6262
return &csi.ProbeResponse{}, nil
6363
}

pkg/driver/node.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func newNodeService(driverOptions *Options) nodeService {
113113
}
114114

115115
func (d *nodeService) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
116-
klog.V(4).Infof("NodeStageVolume: called with args %+v", *req)
116+
klog.V(4).Infof("NodeStageVolume: called with args %+v", req)
117117

118118
volumeID := req.GetVolumeId()
119119
if len(volumeID) == 0 {
@@ -254,7 +254,7 @@ func (d *nodeService) stageVolume(wwn string, req *csi.NodeStageVolumeRequest) e
254254
}
255255

256256
func (d *nodeService) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) {
257-
klog.V(4).Infof("NodeUnstageVolume: called with args %+v", *req)
257+
klog.V(4).Infof("NodeUnstageVolume: called with args %+v", req)
258258

259259
volumeID := req.GetVolumeId()
260260
if len(volumeID) == 0 {
@@ -342,7 +342,7 @@ func (d *nodeService) deleteDevice(deviceName string) error {
342342
}
343343

344344
func (d *nodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
345-
klog.V(4).Infof("NodeExpandVolume: called with args %+v", *req)
345+
klog.V(4).Infof("NodeExpandVolume: called with args %+v", req)
346346

347347
volumeID := req.GetVolumeId()
348348
if len(volumeID) == 0 {
@@ -413,7 +413,7 @@ func (d *nodeService) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
413413
}
414414

415415
func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
416-
klog.V(4).Infof("NodePublishVolume: called with args %+v", *req)
416+
klog.V(4).Infof("NodePublishVolume: called with args %+v", req)
417417
volumeID := req.GetVolumeId()
418418
if len(volumeID) == 0 {
419419
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -469,7 +469,7 @@ func (d *nodeService) NodePublishVolume(ctx context.Context, req *csi.NodePublis
469469
}
470470

471471
func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
472-
klog.V(4).Infof("NodeUnpublishVolume: called with args %+v", *req)
472+
klog.V(4).Infof("NodeUnpublishVolume: called with args %+v", req)
473473
volumeID := req.GetVolumeId()
474474
if len(volumeID) == 0 {
475475
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
@@ -499,7 +499,7 @@ func (d *nodeService) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
499499
func (d *nodeService) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) {
500500
var resp *csi.NodeGetVolumeStatsResponse
501501
if req != nil {
502-
klog.V(4).Infof("NodeGetVolumeStats: called with args %+v", *req)
502+
klog.V(4).Infof("NodeGetVolumeStats: called with args %+v", req)
503503
}
504504

505505
if req == nil || req.VolumeId == "" {
@@ -568,7 +568,7 @@ func (d *nodeService) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo
568568
}
569569

570570
func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
571-
klog.V(4).Infof("NodeGetCapabilities: called with args %+v", *req)
571+
klog.V(4).Infof("NodeGetCapabilities: called with args %+v", req)
572572
var caps []*csi.NodeServiceCapability
573573
for _, cap := range nodeCaps {
574574
c := &csi.NodeServiceCapability{
@@ -584,7 +584,7 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
584584
}
585585

586586
func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
587-
klog.V(4).Infof("NodeGetInfo: called with args %+v", *req)
587+
klog.V(4).Infof("NodeGetInfo: called with args %+v", req)
588588

589589
in, err := d.cloud.GetPVMInstanceByID(d.pvmInstanceId)
590590
if err != nil {

pkg/driver/node_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,19 +551,19 @@ func TestNodeExpandVolume(t *testing.T) {
551551

552552
tests := []struct {
553553
name string
554-
request csi.NodeExpandVolumeRequest
554+
request *csi.NodeExpandVolumeRequest
555555
expectResponseCode codes.Code
556556
expectMock func(mockMounter mocks.MockMounter)
557557
volumeLock bool
558558
}{
559559
{
560560
name: "fail missing volumeId",
561-
request: csi.NodeExpandVolumeRequest{},
561+
request: &csi.NodeExpandVolumeRequest{},
562562
expectResponseCode: codes.InvalidArgument,
563563
},
564564
{
565565
name: "fail if volume already locked",
566-
request: csi.NodeExpandVolumeRequest{
566+
request: &csi.NodeExpandVolumeRequest{
567567
VolumeId: "test-volume-id",
568568
},
569569
expectResponseCode: codes.InvalidArgument,
@@ -581,7 +581,7 @@ func TestNodeExpandVolume(t *testing.T) {
581581
powervsDriver.volumeLocks.TryAcquire(test.request.VolumeId)
582582
defer powervsDriver.volumeLocks.Release(test.request.VolumeId)
583583
}
584-
_, err := powervsDriver.NodeExpandVolume(context.Background(), &test.request)
584+
_, err := powervsDriver.NodeExpandVolume(context.Background(), test.request)
585585
if err != nil {
586586
if test.expectResponseCode != codes.OK {
587587
expectErr(t, err, test.expectResponseCode)

0 commit comments

Comments
 (0)