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 12, 2024
1 parent a06a5e2 commit 600d484
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 65 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
2 changes: 1 addition & 1 deletion pkg/azuredisk/azuredisk.go
Original file line number Diff line number Diff line change
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
24 changes: 12 additions & 12 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
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 @@ -741,7 +741,7 @@ func (d *Driver) listVolumesInNodeResourceGroup(ctx context.Context, start, maxE
func (d *Driver) listVolumesByResourceGroup(ctx context.Context, resourceGroup string, entries []*csi.ListVolumesResponse_Entry, start, maxEntries int, volSet map[string]bool) listVolumeStatus {
disks, derr := d.cloud.DisksClient.ListByResourceGroup(ctx, "", resourceGroup)
if derr != nil {
return listVolumeStatus{err: status.Errorf(codes.Internal, "ListVolumes on rg(%s) failed with error: %v", resourceGroup, derr.Error())}
return listVolumeStatus{err: status.Errorf(codes.Internal, "ListVolumes on rg(%s) failed with error: %v", resourceGroup, derr)}
}
// if volSet is initialized but is empty, return
if volSet != nil && len(volSet) == 0 {
Expand Down Expand Up @@ -835,7 +835,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
subsID := azureutils.GetSubscriptionIDFromURI(diskURI)
result, rerr := d.cloud.DisksClient.Get(ctx, subsID, resourceGroup, diskName)
if rerr != nil {
return nil, status.Errorf(codes.Internal, "could not get the disk(%s) under rg(%s) with error(%v)", diskName, resourceGroup, rerr.Error())
return nil, status.Errorf(codes.Internal, "could not get the disk(%s) under rg(%s) with error(%v)", diskName, resourceGroup, rerr)
}
if result.DiskProperties.DiskSizeGB == nil {
return nil, status.Errorf(codes.Internal, "could not get size of the disk(%s)", diskName)
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 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
22 changes: 11 additions & 11 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 @@ -801,7 +801,7 @@ func (d *DriverV2) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRe

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 Down Expand Up @@ -874,7 +874,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 @@ -920,7 +920,7 @@ func (d *DriverV2) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequ
// no SnapshotId is set, return all snapshots that satisfy the request.
snapshots, err := d.cloud.SnapshotsClient.ListByResourceGroup(ctx, "", d.cloud.ResourceGroup)
if err != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("Unknown list snapshot error: %v", err.Error()))
return nil, status.Error(codes.Internal, fmt.Sprintf("Unknown list snapshot error: %v", err))
}

return azureutils.GetEntriesAndNextToken(req, snapshots)
Expand All @@ -932,13 +932,13 @@ 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)
}
}

snapshot, rerr := d.cloud.SnapshotsClient.Get(ctx, subsID, resourceGroup, snapshotName)
if rerr != nil {
return nil, status.Error(codes.Internal, fmt.Sprintf("get snapshot %s from rg(%s) error: %v", snapshotName, resourceGroup, rerr.Error()))
return nil, status.Error(codes.Internal, fmt.Sprintf("get snapshot %s from rg(%s) error: %v", snapshotName, resourceGroup, rerr))
}

return azureutils.GenerateCSISnapshot(sourceVolumeID, &snapshot)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/fake_azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,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
4 changes: 2 additions & 2 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
Loading

0 comments on commit 600d484

Please sign in to comment.