util: address golangci-lint for csi-common

addressing golangci-lint issues in the
csi-common related code.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-04-04 10:55:49 +02:00 committed by mergify[bot]
parent 2465310543
commit a85b4a9305
4 changed files with 37 additions and 42 deletions

View File

@ -70,8 +70,6 @@ func NewCSIDriver(name, v, nodeID string) *CSIDriver {
// ValidateControllerServiceRequest validates the controller // ValidateControllerServiceRequest validates the controller
// plugin capabilities. // plugin capabilities.
//
//nolint:interfacer // c can be of type fmt.Stringer, but that does not make the API clearer
func (d *CSIDriver) ValidateControllerServiceRequest(c csi.ControllerServiceCapability_RPC_Type) error { func (d *CSIDriver) ValidateControllerServiceRequest(c csi.ControllerServiceCapability_RPC_Type) error {
if c == csi.ControllerServiceCapability_RPC_UNKNOWN { if c == csi.ControllerServiceCapability_RPC_UNKNOWN {
return nil return nil
@ -133,8 +131,6 @@ func (d *CSIDriver) AddGroupControllerServiceCapabilities(cl []csi.GroupControll
// ValidateGroupControllerServiceRequest validates the group controller // ValidateGroupControllerServiceRequest validates the group controller
// plugin capabilities. // plugin capabilities.
//
//nolint:interfacer // c can be of type fmt.Stringer, but that does not make the API clearer
func (d *CSIDriver) ValidateGroupControllerServiceRequest(c csi.GroupControllerServiceCapability_RPC_Type) error { func (d *CSIDriver) ValidateGroupControllerServiceRequest(c csi.GroupControllerServiceCapability_RPC_Type) error {
if c == csi.GroupControllerServiceCapability_RPC_UNKNOWN { if c == csi.GroupControllerServiceCapability_RPC_UNKNOWN {
return nil return nil

View File

@ -86,7 +86,7 @@ func ConstructMountOptions(mountOptions []string, volCap *csi.VolumeCapability)
return false return false
} }
for _, f := range m.MountFlags { for _, f := range m.GetMountFlags() {
if !hasOption(mountOptions, f) { if !hasOption(mountOptions, f) {
mountOptions = append(mountOptions, f) mountOptions = append(mountOptions, f)
} }

View File

@ -121,52 +121,52 @@ func getReqID(req interface{}) string {
reqID := "" reqID := ""
switch r := req.(type) { switch r := req.(type) {
case *csi.CreateVolumeRequest: case *csi.CreateVolumeRequest:
reqID = r.Name reqID = r.GetName()
case *csi.DeleteVolumeRequest: case *csi.DeleteVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.CreateSnapshotRequest: case *csi.CreateSnapshotRequest:
reqID = r.Name reqID = r.GetName()
case *csi.DeleteSnapshotRequest: case *csi.DeleteSnapshotRequest:
reqID = r.SnapshotId reqID = r.GetSnapshotId()
case *csi.ControllerExpandVolumeRequest: case *csi.ControllerExpandVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.NodeStageVolumeRequest: case *csi.NodeStageVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.NodeUnstageVolumeRequest: case *csi.NodeUnstageVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.NodePublishVolumeRequest: case *csi.NodePublishVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.NodeUnpublishVolumeRequest: case *csi.NodeUnpublishVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.NodeExpandVolumeRequest: case *csi.NodeExpandVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *csi.CreateVolumeGroupSnapshotRequest: case *csi.CreateVolumeGroupSnapshotRequest:
reqID = r.Name reqID = r.GetName()
case *csi.DeleteVolumeGroupSnapshotRequest: case *csi.DeleteVolumeGroupSnapshotRequest:
reqID = r.GroupSnapshotId reqID = r.GetGroupSnapshotId()
case *csi.GetVolumeGroupSnapshotRequest: case *csi.GetVolumeGroupSnapshotRequest:
reqID = r.GroupSnapshotId reqID = r.GetGroupSnapshotId()
// Replication // Replication
case *replication.EnableVolumeReplicationRequest: case *replication.EnableVolumeReplicationRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *replication.DisableVolumeReplicationRequest: case *replication.DisableVolumeReplicationRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *replication.PromoteVolumeRequest: case *replication.PromoteVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *replication.DemoteVolumeRequest: case *replication.DemoteVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *replication.ResyncVolumeRequest: case *replication.ResyncVolumeRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
case *replication.GetVolumeReplicationInfoRequest: case *replication.GetVolumeReplicationInfoRequest:
reqID = r.VolumeId reqID = r.GetVolumeId()
} }
return reqID return reqID
@ -353,9 +353,9 @@ func IsFileRWO(caps []*csi.VolumeCapability) bool {
// to preserve backward compatibility we allow RWO filemode, ideally SINGLE_NODE_WRITER check is good enough, // to preserve backward compatibility we allow RWO filemode, ideally SINGLE_NODE_WRITER check is good enough,
// however more granular level check could help us in future, so keeping it here as an additional measure. // however more granular level check could help us in future, so keeping it here as an additional measure.
for _, cap := range caps { for _, cap := range caps {
if cap.AccessMode != nil { if cap.GetAccessMode() != nil {
if cap.GetMount() != nil { if cap.GetMount() != nil {
switch cap.AccessMode.Mode { //nolint:exhaustive // only check what we want switch cap.GetAccessMode().GetMode() { //nolint:exhaustive // only check what we want
case csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, case csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER, csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER,
csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER: csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER:
@ -372,8 +372,8 @@ func IsFileRWO(caps []*csi.VolumeCapability) bool {
// or block mode. // or block mode.
func IsReaderOnly(caps []*csi.VolumeCapability) bool { func IsReaderOnly(caps []*csi.VolumeCapability) bool {
for _, cap := range caps { for _, cap := range caps {
if cap.AccessMode != nil { if cap.GetAccessMode() != nil {
switch cap.AccessMode.Mode { //nolint:exhaustive // only check what we want switch cap.GetAccessMode().GetMode() { //nolint:exhaustive // only check what we want
case csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY, case csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY,
csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY: csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY:
return true return true
@ -397,8 +397,8 @@ func IsBlockMultiWriter(caps []*csi.VolumeCapability) (bool, bool) {
var block bool var block bool
for _, cap := range caps { for _, cap := range caps {
if cap.AccessMode != nil { if cap.GetAccessMode() != nil {
switch cap.AccessMode.Mode { //nolint:exhaustive // only check what we want switch cap.GetAccessMode().GetMode() { //nolint:exhaustive // only check what we want
case csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, case csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER: csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER:
multiWriter = true multiWriter = true

View File

@ -25,7 +25,6 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/csi-addons/spec/lib/go/replication" "github.com/csi-addons/spec/lib/go/replication"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
mount "k8s.io/mount-utils" mount "k8s.io/mount-utils"
) )
@ -127,12 +126,12 @@ func TestFilesystemNodeGetVolumeStats(t *testing.T) {
} }
require.NoError(t, err) require.NoError(t, err)
assert.NotEqual(t, len(stats.Usage), 0) require.NotEmpty(t, stats.GetUsage())
for _, usage := range stats.Usage { for _, usage := range stats.GetUsage() {
assert.NotEqual(t, usage.Available, -1) require.NotEqual(t, -1, usage.GetAvailable())
assert.NotEqual(t, usage.Total, -1) require.NotEqual(t, -1, usage.GetTotal())
assert.NotEqual(t, usage.Used, -1) require.NotEqual(t, -1, usage.GetUsed())
assert.NotEqual(t, usage.Unit, 0) require.NotEqual(t, 0, usage.GetUnit())
} }
// tests done, no need to retry again // tests done, no need to retry again
@ -143,9 +142,9 @@ func TestFilesystemNodeGetVolumeStats(t *testing.T) {
func TestRequirePositive(t *testing.T) { func TestRequirePositive(t *testing.T) {
t.Parallel() t.Parallel()
assert.Equal(t, requirePositive(0), int64(0)) require.Equal(t, int64(0), requirePositive(0))
assert.Equal(t, requirePositive(-1), int64(0)) require.Equal(t, int64(0), requirePositive(-1))
assert.Equal(t, requirePositive(1), int64(1)) require.Equal(t, int64(1), requirePositive(1))
} }
func TestIsBlockMultiNode(t *testing.T) { func TestIsBlockMultiNode(t *testing.T) {
@ -204,8 +203,8 @@ func TestIsBlockMultiNode(t *testing.T) {
for _, test := range tests { for _, test := range tests {
isBlock, isMultiNode := IsBlockMultiNode(test.caps) isBlock, isMultiNode := IsBlockMultiNode(test.caps)
assert.Equal(t, isBlock, test.isBlock, test.name) require.Equal(t, isBlock, test.isBlock, test.name)
assert.Equal(t, isMultiNode, test.isMultiNode, test.name) require.Equal(t, isMultiNode, test.isMultiNode, test.name)
} }
} }