Skip to content

Commit

Permalink
cleanup: upgrade golint version and fix golint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhupku authored and umagnus committed Sep 13, 2024
1 parent 8201c63 commit ce9ffba
Show file tree
Hide file tree
Showing 31 changed files with 149 additions and 148 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
version: v1.60
args: --timeout 10m
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ run:
linters:
disable:
- typecheck
- structcheck
enable:
- golint
- revive

linters-settings:
depguard:
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azure_common_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestRescanAllVolumes(t *testing.T) {
if runtime.GOOS == "darwin" {
if runtime.GOOS == "darwin" { // nolint: staticcheck
t.Skipf("skip test on GOOS=%s", runtime.GOOS)
}
err := rescanAllVolumes(azureutils.NewOSIOHandler())
Expand Down
6 changes: 3 additions & 3 deletions pkg/azuredisk/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" // nolint: staticcheck
"github.com/container-storage-interface/spec/lib/go/csi"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -177,7 +177,7 @@ func newDriverV1(options *DriverOptions) *Driver {

topologyKey = fmt.Sprintf("topology.%s/zone", driver.Name)

getter := func(key string) (interface{}, error) { return nil, nil }
getter := func(_ string) (interface{}, error) { return nil, nil }
var err error
if driver.getDiskThrottlingCache, err = azcache.NewTimedCache(5*time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
Expand Down Expand Up @@ -458,7 +458,7 @@ func (d *DriverCore) waitForSnapshotReady(ctx context.Context, subsID, resourceG
return nil
}

timeTick := time.Tick(intervel)
timeTick := time.Tick(intervel) // nolint: staticcheck
timeAfter := time.After(timeout)
for {
select {
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azuredisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" // nolint: staticcheck
"github.com/Azure/go-autorest/autorest/date"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azuredisk_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ package azuredisk

// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
func NewDriver(options *DriverOptions) CSIDriver {
func NewDriver(options *DriverOptions) CSIDriver { // nolint: staticcheck
return newDriverV1(options)
}
2 changes: 1 addition & 1 deletion pkg/azuredisk/azuredisk_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"context"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" // nolint: staticcheck
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
Expand Down
24 changes: 12 additions & 12 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" // nolint: staticcheck
"github.com/container-storage-interface/spec/lib/go/csi"

"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -297,7 +297,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
if strings.Contains(err.Error(), consts.NotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

isOperationSucceeded = true
Expand Down Expand Up @@ -389,7 +389,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
nodeName := types.NodeName(nodeID)
diskName, err := azureutils.GetDiskName(diskURI)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_publish_volume", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
Expand Down Expand Up @@ -427,11 +427,11 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
} else {
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(consts.TooManyRequests)) ||
strings.Contains(strings.ToLower(err.Error()), consts.ClientThrottled) {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
var cachingMode compute.CachingTypes
if cachingMode, err = azureutils.GetCachingMode(volumeContext); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
klog.V(2).Infof("Trying to attach volume %s to node %s", diskURI, nodeName)

Expand Down Expand Up @@ -464,7 +464,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
if len(errMsg) > maxErrMsgLength {
errMsg = errMsg[:maxErrMsgLength]
}
return nil, status.Errorf(codes.Internal, errMsg)
return nil, status.Errorf(codes.Internal, "%v", errMsg)
}
}
klog.V(2).Infof("attach volume %s to node %s successfully", diskURI, nodeName)
Expand Down Expand Up @@ -496,7 +496,7 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control

diskName, err := azureutils.GetDiskName(diskURI)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_unpublish_volume", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
Expand All @@ -516,7 +516,7 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control
if len(errMsg) > maxErrMsgLength {
errMsg = errMsg[:maxErrMsgLength]
}
return nil, status.Errorf(codes.Internal, errMsg)
return nil, status.Errorf(codes.Internal, "%v", errMsg)
}
}
klog.V(2).Infof("detach volume %s from node %s successfully", diskURI, nodeID)
Expand Down Expand Up @@ -594,7 +594,7 @@ func (d *Driver) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (
func (d *Driver) listVolumesInCluster(ctx context.Context, start, maxEntries int) (*csi.ListVolumesResponse, error) {
pvList, err := d.cloud.KubeClient.CoreV1().PersistentVolumes().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, status.Errorf(codes.Internal, "ListVolumes failed while fetching PersistentVolumes List with error: %v", err.Error())
return nil, status.Errorf(codes.Internal, "ListVolumes failed while fetching PersistentVolumes List with error: %v", err)
}

// get all resource groups and put them into a sorted slice
Expand Down Expand Up @@ -893,7 +893,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ

customTagsMap, err := volumehelper.ConvertTagsToMap(customTags)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
}
tags := make(map[string]*string)
for k, v := range customTagsMap {
Expand Down Expand Up @@ -1038,7 +1038,7 @@ func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequ
if azureutils.IsARMResourceID(snapshotID) {
snapshotName, resourceGroup, subsID, err = d.getSnapshotInfo(snapshotID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
}

Expand Down Expand Up @@ -1095,7 +1095,7 @@ func (d *Driver) getSnapshotByID(ctx context.Context, subsID, resourceGroup, sna
if azureutils.IsARMResourceID(snapshotID) {
snapshotName, resourceGroup, subsID, err = d.getSnapshotInfo(snapshotID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"reflect"
"testing"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" // nolint: staticcheck
"github.com/Azure/go-autorest/autorest/date"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/mock/gomock"
Expand Down
18 changes: 9 additions & 9 deletions pkg/azuredisk/controllerserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (d *DriverV2) CreateVolume(ctx context.Context, req *csi.CreateVolumeReques
if strings.Contains(err.Error(), consts.NotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

isOperationSucceeded = true
Expand Down Expand Up @@ -332,7 +332,7 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
nodeName := types.NodeName(nodeID)
diskName, err := azureutils.GetDiskName(diskURI)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_publish_volume", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
Expand Down Expand Up @@ -365,11 +365,11 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
} else {
if strings.Contains(strings.ToLower(err.Error()), strings.ToLower(consts.TooManyRequests)) ||
strings.Contains(strings.ToLower(err.Error()), consts.ClientThrottled) {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
var cachingMode compute.CachingTypes
if cachingMode, err = azureutils.GetCachingMode(volumeContext); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
klog.V(2).Infof("Trying to attach volume %s to node %s", diskURI, nodeName)

Expand Down Expand Up @@ -419,7 +419,7 @@ func (d *DriverV2) ControllerUnpublishVolume(ctx context.Context, req *csi.Contr

diskName, err := azureutils.GetDiskName(diskURI)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}

mc := metrics.NewMetricContext(consts.AzureDiskCSIDriverName, "controller_unpublish_volume", d.cloud.ResourceGroup, d.cloud.SubscriptionID, d.Name)
Expand Down Expand Up @@ -511,7 +511,7 @@ func (d *DriverV2) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest)
func (d *DriverV2) listVolumesInCluster(ctx context.Context, start, maxEntries int) (*csi.ListVolumesResponse, error) {
pvList, err := d.cloud.KubeClient.CoreV1().PersistentVolumes().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, status.Errorf(codes.Internal, "ListVolumes failed while fetching PersistentVolumes List with error: %v", err.Error())
return nil, status.Errorf(codes.Internal, "ListVolumes failed while fetching PersistentVolumes List with error: %v", err)
}

// get all resource groups and put them into a sorted slice
Expand Down Expand Up @@ -799,7 +799,7 @@ func (d *DriverV2) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRe

customTagsMap, err := volumehelper.ConvertTagsToMap(customTags)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
}
tags := make(map[string]*string)
for k, v := range customTagsMap {
Expand Down Expand Up @@ -872,7 +872,7 @@ func (d *DriverV2) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRe
if azureutils.IsARMResourceID(snapshotID) {
snapshotName, resourceGroup, subsID, err = d.getSnapshotInfo(snapshotID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
}

Expand Down Expand Up @@ -930,7 +930,7 @@ func (d *DriverV2) getSnapshotByID(ctx context.Context, subsID, resourceGroup, s
if azureutils.IsARMResourceID(snapshotID) {
snapshotName, resourceGroup, subsID, err = d.getSnapshotInfo(snapshotID)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/azuredisk/fake_azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"testing"
"time"

"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-08-01/compute" // nolint: staticcheck
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -126,7 +126,7 @@ func newFakeDriverV1(t *testing.T) (*fakeDriverV1, error) {

driver.mounter = mounter

cache, err := azcache.NewTimedCache(time.Minute, func(key string) (interface{}, error) {
cache, err := azcache.NewTimedCache(time.Minute, func(_ string) (interface{}, error) {
return nil, nil
}, false)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/azuredisk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (d *Driver) NodePublishVolume(_ context.Context, req *csi.NodePublishVolume
}
klog.V(2).Infof("NodePublishVolume [block]: found device path %s with lun %s", source, lun)
if err = d.ensureBlockTargetFile(target); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
case *csi.VolumeCapability_Mount:
mnt, err := d.ensureMountPoint(target)
Expand Down Expand Up @@ -497,7 +497,7 @@ func (d *Driver) NodeExpandVolume(_ context.Context, req *csi.NodeExpandVolumeRe

devicePath, err := getDevicePathWithMountPath(volumePath, d.mounter)
if err != nil {
return nil, status.Errorf(codes.NotFound, err.Error())
return nil, status.Errorf(codes.NotFound, "%v", err)
}

if d.enableDiskOnlineResize {
Expand Down Expand Up @@ -612,7 +612,7 @@ func (d *Driver) getDevicePathWithLUN(lunStr string) (string, error) {
scsiHostRescan(d.ioHandler, d.mounter)

newDevicePath := ""
err = wait.PollImmediate(1*time.Second, 2*time.Minute, func() (bool, error) {
err = wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 2*time.Minute, true, func(context.Context) (bool, error) {
var err error
if newDevicePath, err = findDiskByLun(int(lun), d.ioHandler, d.mounter); err != nil {
return false, fmt.Errorf("azureDisk - findDiskByLun(%v) failed with error(%s)", lun, err)
Expand Down
Loading

0 comments on commit ce9ffba

Please sign in to comment.