Skip to content

Commit

Permalink
Fixes for govet errors
Browse files Browse the repository at this point in the history
Signed-off-by: Yussuf Shaikh <[email protected]>
  • Loading branch information
yussufsh committed Dec 13, 2024
1 parent 539b40c commit e9734d1
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 73 deletions.
82 changes: 24 additions & 58 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,14 @@ import (
"sigs.k8s.io/ibm-powervs-block-csi-driver/pkg/util"
)

var (

// Supported volume capabilities
volumeCaps = []csi.VolumeCapability_AccessMode{
{
Mode: csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
},
{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY,
},
}

// Shareable volume capabilities
shareableVolumeCaps = []csi.VolumeCapability_AccessMode{
{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
},
{
Mode: csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY,
},
}
// Supported access modes
const (
SingleNodeWriter = csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER
MultiNodeMultiWriter = csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER
MultiNodeReaderOnly = csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY
)

var (
// controllerCaps represents the capability of controller service
controllerCaps = []csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
Expand Down Expand Up @@ -143,7 +126,7 @@ func newControllerService(driverOptions *Options) controllerService {
}

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

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

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

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

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

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

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

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

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

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

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

func isValidVolumeCapabilities(volCaps []*csi.VolumeCapability) bool {
hasSupport := func(cap *csi.VolumeCapability) bool {
for _, c := range volumeCaps {
if c.GetMode() == cap.AccessMode.GetMode() {
return true
}
}
return false
}

foundAll := true
for _, c := range volCaps {
if !hasSupport(c) {
foundAll = false
mode := c.AccessMode.GetMode()
if mode != SingleNodeWriter && mode != MultiNodeMultiWriter && mode != MultiNodeReaderOnly {
return false
}
}
return foundAll
return true
}

// Check if the volume is shareable
func isShareableVolume(volCaps []*csi.VolumeCapability) bool {
isShareable := func(cap *csi.VolumeCapability) bool {
for _, c := range shareableVolumeCaps {
if c.GetMode() == cap.AccessMode.GetMode() {
return true
}
}
return false
}

for _, c := range volCaps {
if isShareable(c) {
mode := c.AccessMode.GetMode()
if mode == MultiNodeMultiWriter || mode == MultiNodeReaderOnly {
return true
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/driver/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

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

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

func (d *Driver) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
klog.V(6).Infof("Probe: called with args %+v", *req)
klog.V(6).Infof("Probe: called with args %+v", req)
return &csi.ProbeResponse{}, nil
}
16 changes: 8 additions & 8 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func newNodeService(driverOptions *Options) nodeService {
}

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

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

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

volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
Expand Down Expand Up @@ -342,7 +342,7 @@ func (d *nodeService) deleteDevice(deviceName string) error {
}

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

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

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

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

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

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

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

in, err := d.cloud.GetPVMInstanceByID(d.pvmInstanceId)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,19 @@ func TestNodeExpandVolume(t *testing.T) {

tests := []struct {
name string
request csi.NodeExpandVolumeRequest
request *csi.NodeExpandVolumeRequest
expectResponseCode codes.Code
expectMock func(mockMounter mocks.MockMounter)
volumeLock bool
}{
{
name: "fail missing volumeId",
request: csi.NodeExpandVolumeRequest{},
request: &csi.NodeExpandVolumeRequest{},
expectResponseCode: codes.InvalidArgument,
},
{
name: "fail if volume already locked",
request: csi.NodeExpandVolumeRequest{
request: &csi.NodeExpandVolumeRequest{
VolumeId: "test-volume-id",
},
expectResponseCode: codes.InvalidArgument,
Expand All @@ -581,7 +581,7 @@ func TestNodeExpandVolume(t *testing.T) {
powervsDriver.volumeLocks.TryAcquire(test.request.VolumeId)
defer powervsDriver.volumeLocks.Release(test.request.VolumeId)
}
_, err := powervsDriver.NodeExpandVolume(context.Background(), &test.request)
_, err := powervsDriver.NodeExpandVolume(context.Background(), test.request)
if err != nil {
if test.expectResponseCode != codes.OK {
expectErr(t, err, test.expectResponseCode)
Expand Down

0 comments on commit e9734d1

Please sign in to comment.