Skip to content

Commit

Permalink
Merge pull request #2508 from umagnus/release-1.29-golint
Browse files Browse the repository at this point in the history
[release-1.29] cleanup: upgrade golint version and fix golint errors
  • Loading branch information
andyzhangx authored Sep 13, 2024
2 parents a06a5e2 + c28d5ff commit 8c99f35
Show file tree
Hide file tree
Showing 32 changed files with 181 additions and 181 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
12 changes: 6 additions & 6 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 All @@ -36,7 +36,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/volume/util/hostutil"
"k8s.io/mount-utils"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
"sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
Expand Down Expand Up @@ -187,7 +187,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.throttlingCache, err = azcache.NewTimedCache(5*time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
Expand Down Expand Up @@ -479,7 +479,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 Expand Up @@ -508,7 +508,7 @@ func (d *DriverCore) getUsedLunsFromVolumeAttachments(ctx context.Context, nodeN
}

volumeAttachments, err := kubeClient.StorageV1().VolumeAttachments().List(ctx, metav1.ListOptions{
TimeoutSeconds: pointer.Int64Ptr(2)})
TimeoutSeconds: ptr.To(int64(2))})
if err != nil {
return nil, err
}
Expand All @@ -522,7 +522,7 @@ func (d *DriverCore) getUsedLunsFromVolumeAttachments(ctx context.Context, nodeN
klog.V(2).Infof("volumeAttachments count: %d, nodeName: %s", len(volumeAttachments.Items), nodeName)
for _, va := range volumeAttachments.Items {
klog.V(6).Infof("attacher: %s, nodeName: %s, Status: %v, PV: %s, attachmentMetadata: %v", va.Spec.Attacher, va.Spec.NodeName,
va.Status.Attached, pointer.StringDeref(va.Spec.Source.PersistentVolumeName, ""), va.Status.AttachmentMetadata)
va.Status.Attached, ptr.Deref(va.Spec.Source.PersistentVolumeName, ""), va.Status.AttachmentMetadata)
if va.Spec.Attacher == d.Name && strings.EqualFold(va.Spec.NodeName, nodeName) && va.Status.Attached {
if k, ok := va.Status.AttachmentMetadata[consts.LUN]; ok {
lun, err := strconv.Atoi(k)
Expand Down
12 changes: 6 additions & 6 deletions pkg/azuredisk/azuredisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ 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"
"google.golang.org/grpc/status"
"k8s.io/apimachinery/pkg/types"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/diskclient/mockdiskclient"
"sigs.k8s.io/cloud-provider-azure/pkg/azureclients/snapshotclient/mocksnapshotclient"
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestWaitForSnapshot(t *testing.T) {
ProvisioningState: &provisioningState,
DiskSizeGB: &DiskSize,
CreationData: &compute.CreationData{SourceResourceID: &volumeID},
CompletionPercent: pointer.Float64(0.0),
CompletionPercent: ptr.To(0.0),
},
Location: &location,
ID: &snapshotID}
Expand Down Expand Up @@ -394,7 +394,7 @@ func TestWaitForSnapshot(t *testing.T) {
ProvisioningState: &provisioningState,
DiskSizeGB: &DiskSize,
CreationData: &compute.CreationData{SourceResourceID: &volumeID},
CompletionPercent: pointer.Float64(100.0),
CompletionPercent: ptr.To(100.0),
},
Location: &location,
ID: &snapshotID}
Expand Down Expand Up @@ -495,8 +495,8 @@ func TestGetUsedLunsFromNode(t *testing.T) {
d, _ := NewFakeDriver(t)
vm := compute.VirtualMachine{}
dataDisks := make([]compute.DataDisk, 2)
dataDisks[0] = compute.DataDisk{Lun: pointer.Int32(int32(0)), Name: &testVolumeName}
dataDisks[1] = compute.DataDisk{Lun: pointer.Int32(int32(2)), Name: &testVolumeName}
dataDisks[0] = compute.DataDisk{Lun: ptr.To(int32(0)), Name: &testVolumeName}
dataDisks[1] = compute.DataDisk{Lun: ptr.To(int32(2)), Name: &testVolumeName}
vm.VirtualMachineProperties = &compute.VirtualMachineProperties{
StorageProfile: &compute.StorageProfile{
DataDisks: &dataDisks,
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
26 changes: 13 additions & 13 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 All @@ -37,7 +37,7 @@ import (
cloudprovider "k8s.io/cloud-provider"
volerr "k8s.io/cloud-provider/volume/errors"
"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
"sigs.k8s.io/azuredisk-csi-driver/pkg/azureutils"
Expand Down Expand Up @@ -299,7 +299,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 @@ -391,7 +391,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 @@ -432,7 +432,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
}
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)
}

occupiedLuns := d.getOccupiedLunsFromNode(ctx, nodeName, diskURI)
Expand Down Expand Up @@ -467,7 +467,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 @@ -499,7 +499,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 @@ -519,7 +519,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 @@ -633,7 +633,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 @@ -934,7 +934,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ

customTagsMap, err := volumehelper.ConvertTagsToMap(customTags, tagValueDelimiter)
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 All @@ -957,7 +957,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
if d.cloud.HasExtendedLocation() {
klog.V(2).Infof("extended location Name:%s Type:%s is set on snapshot %s, source volume %s", d.cloud.ExtendedLocationName, d.cloud.ExtendedLocationType, snapshotName, sourceVolumeID)
snapshot.ExtendedLocation = &compute.ExtendedLocation{
Name: pointer.String(d.cloud.ExtendedLocationName),
Name: ptr.To(d.cloud.ExtendedLocationName),
Type: compute.ExtendedLocationTypes(d.cloud.ExtendedLocationType),
}
}
Expand Down Expand Up @@ -1079,7 +1079,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 @@ -1136,7 +1136,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
26 changes: 13 additions & 13 deletions 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 All @@ -31,7 +31,7 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/timestamppb"
v1 "k8s.io/api/core/v1"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
consts "sigs.k8s.io/azuredisk-csi-driver/pkg/azureconstants"
"sigs.k8s.io/azuredisk-csi-driver/pkg/azuredisk/mockcorev1"
"sigs.k8s.io/azuredisk-csi-driver/pkg/azuredisk/mockkubeclient"
Expand Down Expand Up @@ -740,14 +740,14 @@ func TestControllerPublishVolume(t *testing.T) {
}
vmstatus := []compute.InstanceViewStatus{
{
Code: pointer.String("PowerState/Running"),
Code: ptr.To("PowerState/Running"),
},
{
Code: pointer.String("ProvisioningState/succeeded"),
Code: ptr.To("ProvisioningState/succeeded"),
},
}
vm.VirtualMachineProperties = &compute.VirtualMachineProperties{
ProvisioningState: pointer.String("Failed"),
ProvisioningState: ptr.To("Failed"),
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.StandardA0,
},
Expand All @@ -759,7 +759,7 @@ func TestControllerPublishVolume(t *testing.T) {
},
}
dataDisks := make([]compute.DataDisk, 1)
dataDisks[0] = compute.DataDisk{Lun: pointer.Int32(int32(0)), Name: &testVolumeName}
dataDisks[0] = compute.DataDisk{Lun: ptr.To(int32(0)), Name: &testVolumeName}
vm.StorageProfile.DataDisks = &dataDisks
mockVMsClient := d.getCloud().VirtualMachinesClient.(*mockvmclient.MockInterface)
mockVMsClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(vm, nil).AnyTimes()
Expand Down Expand Up @@ -798,14 +798,14 @@ func TestControllerPublishVolume(t *testing.T) {
}
vmstatus := []compute.InstanceViewStatus{
{
Code: pointer.String("PowerState/Running"),
Code: ptr.To("PowerState/Running"),
},
{
Code: pointer.String("ProvisioningState/succeeded"),
Code: ptr.To("ProvisioningState/succeeded"),
},
}
vm.VirtualMachineProperties = &compute.VirtualMachineProperties{
ProvisioningState: pointer.String("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.StandardA0,
},
Expand All @@ -817,7 +817,7 @@ func TestControllerPublishVolume(t *testing.T) {
},
}
dataDisks := make([]compute.DataDisk, 1)
dataDisks[0] = compute.DataDisk{Lun: pointer.Int32(int32(0)), Name: &testVolumeName}
dataDisks[0] = compute.DataDisk{Lun: ptr.To(int32(0)), Name: &testVolumeName}
vm.StorageProfile.DataDisks = &dataDisks
mockVMsClient := d.getCloud().VirtualMachinesClient.(*mockvmclient.MockInterface)
mockVMsClient.EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(vm, nil).AnyTimes()
Expand Down Expand Up @@ -856,14 +856,14 @@ func TestControllerPublishVolume(t *testing.T) {
}
vmstatus := []compute.InstanceViewStatus{
{
Code: pointer.String("PowerState/Running"),
Code: ptr.To("PowerState/Running"),
},
{
Code: pointer.String("ProvisioningState/succeeded"),
Code: ptr.To("ProvisioningState/succeeded"),
},
}
vm.VirtualMachineProperties = &compute.VirtualMachineProperties{
ProvisioningState: pointer.String("Succeeded"),
ProvisioningState: ptr.To("Succeeded"),
HardwareProfile: &compute.HardwareProfile{
VMSize: compute.StandardA0,
},
Expand Down
Loading

0 comments on commit 8c99f35

Please sign in to comment.