mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-17 20:00:23 +00:00
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:
parent
2465310543
commit
a85b4a9305
@ -70,8 +70,6 @@ func NewCSIDriver(name, v, nodeID string) *CSIDriver {
|
||||
|
||||
// ValidateControllerServiceRequest validates the controller
|
||||
// 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 {
|
||||
if c == csi.ControllerServiceCapability_RPC_UNKNOWN {
|
||||
return nil
|
||||
@ -133,8 +131,6 @@ func (d *CSIDriver) AddGroupControllerServiceCapabilities(cl []csi.GroupControll
|
||||
|
||||
// ValidateGroupControllerServiceRequest validates the group controller
|
||||
// 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 {
|
||||
if c == csi.GroupControllerServiceCapability_RPC_UNKNOWN {
|
||||
return nil
|
||||
|
@ -86,7 +86,7 @@ func ConstructMountOptions(mountOptions []string, volCap *csi.VolumeCapability)
|
||||
|
||||
return false
|
||||
}
|
||||
for _, f := range m.MountFlags {
|
||||
for _, f := range m.GetMountFlags() {
|
||||
if !hasOption(mountOptions, f) {
|
||||
mountOptions = append(mountOptions, f)
|
||||
}
|
||||
|
@ -121,52 +121,52 @@ func getReqID(req interface{}) string {
|
||||
reqID := ""
|
||||
switch r := req.(type) {
|
||||
case *csi.CreateVolumeRequest:
|
||||
reqID = r.Name
|
||||
reqID = r.GetName()
|
||||
|
||||
case *csi.DeleteVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
|
||||
case *csi.CreateSnapshotRequest:
|
||||
reqID = r.Name
|
||||
reqID = r.GetName()
|
||||
case *csi.DeleteSnapshotRequest:
|
||||
reqID = r.SnapshotId
|
||||
reqID = r.GetSnapshotId()
|
||||
|
||||
case *csi.ControllerExpandVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
|
||||
case *csi.NodeStageVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *csi.NodeUnstageVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
|
||||
case *csi.NodePublishVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *csi.NodeUnpublishVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
|
||||
case *csi.NodeExpandVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
|
||||
case *csi.CreateVolumeGroupSnapshotRequest:
|
||||
reqID = r.Name
|
||||
reqID = r.GetName()
|
||||
case *csi.DeleteVolumeGroupSnapshotRequest:
|
||||
reqID = r.GroupSnapshotId
|
||||
reqID = r.GetGroupSnapshotId()
|
||||
case *csi.GetVolumeGroupSnapshotRequest:
|
||||
reqID = r.GroupSnapshotId
|
||||
reqID = r.GetGroupSnapshotId()
|
||||
|
||||
// Replication
|
||||
case *replication.EnableVolumeReplicationRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *replication.DisableVolumeReplicationRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *replication.PromoteVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *replication.DemoteVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *replication.ResyncVolumeRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
case *replication.GetVolumeReplicationInfoRequest:
|
||||
reqID = r.VolumeId
|
||||
reqID = r.GetVolumeId()
|
||||
}
|
||||
|
||||
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,
|
||||
// however more granular level check could help us in future, so keeping it here as an additional measure.
|
||||
for _, cap := range caps {
|
||||
if cap.AccessMode != nil {
|
||||
if cap.GetAccessMode() != 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,
|
||||
csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER,
|
||||
csi.VolumeCapability_AccessMode_SINGLE_NODE_SINGLE_WRITER:
|
||||
@ -372,8 +372,8 @@ func IsFileRWO(caps []*csi.VolumeCapability) bool {
|
||||
// or block mode.
|
||||
func IsReaderOnly(caps []*csi.VolumeCapability) bool {
|
||||
for _, cap := range caps {
|
||||
if cap.AccessMode != nil {
|
||||
switch cap.AccessMode.Mode { //nolint:exhaustive // only check what we want
|
||||
if cap.GetAccessMode() != nil {
|
||||
switch cap.GetAccessMode().GetMode() { //nolint:exhaustive // only check what we want
|
||||
case csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY,
|
||||
csi.VolumeCapability_AccessMode_SINGLE_NODE_READER_ONLY:
|
||||
return true
|
||||
@ -397,8 +397,8 @@ func IsBlockMultiWriter(caps []*csi.VolumeCapability) (bool, bool) {
|
||||
var block bool
|
||||
|
||||
for _, cap := range caps {
|
||||
if cap.AccessMode != nil {
|
||||
switch cap.AccessMode.Mode { //nolint:exhaustive // only check what we want
|
||||
if cap.GetAccessMode() != nil {
|
||||
switch cap.GetAccessMode().GetMode() { //nolint:exhaustive // only check what we want
|
||||
case csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
|
||||
csi.VolumeCapability_AccessMode_SINGLE_NODE_MULTI_WRITER:
|
||||
multiWriter = true
|
||||
|
@ -25,7 +25,6 @@ import (
|
||||
|
||||
"github.com/container-storage-interface/spec/lib/go/csi"
|
||||
"github.com/csi-addons/spec/lib/go/replication"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
mount "k8s.io/mount-utils"
|
||||
)
|
||||
@ -127,12 +126,12 @@ func TestFilesystemNodeGetVolumeStats(t *testing.T) {
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NotEqual(t, len(stats.Usage), 0)
|
||||
for _, usage := range stats.Usage {
|
||||
assert.NotEqual(t, usage.Available, -1)
|
||||
assert.NotEqual(t, usage.Total, -1)
|
||||
assert.NotEqual(t, usage.Used, -1)
|
||||
assert.NotEqual(t, usage.Unit, 0)
|
||||
require.NotEmpty(t, stats.GetUsage())
|
||||
for _, usage := range stats.GetUsage() {
|
||||
require.NotEqual(t, -1, usage.GetAvailable())
|
||||
require.NotEqual(t, -1, usage.GetTotal())
|
||||
require.NotEqual(t, -1, usage.GetUsed())
|
||||
require.NotEqual(t, 0, usage.GetUnit())
|
||||
}
|
||||
|
||||
// tests done, no need to retry again
|
||||
@ -143,9 +142,9 @@ func TestFilesystemNodeGetVolumeStats(t *testing.T) {
|
||||
func TestRequirePositive(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
assert.Equal(t, requirePositive(0), int64(0))
|
||||
assert.Equal(t, requirePositive(-1), int64(0))
|
||||
assert.Equal(t, requirePositive(1), int64(1))
|
||||
require.Equal(t, int64(0), requirePositive(0))
|
||||
require.Equal(t, int64(0), requirePositive(-1))
|
||||
require.Equal(t, int64(1), requirePositive(1))
|
||||
}
|
||||
|
||||
func TestIsBlockMultiNode(t *testing.T) {
|
||||
@ -204,8 +203,8 @@ func TestIsBlockMultiNode(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
isBlock, isMultiNode := IsBlockMultiNode(test.caps)
|
||||
assert.Equal(t, isBlock, test.isBlock, test.name)
|
||||
assert.Equal(t, isMultiNode, test.isMultiNode, test.name)
|
||||
require.Equal(t, isBlock, test.isBlock, test.name)
|
||||
require.Equal(t, isMultiNode, test.isMultiNode, test.name)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user