Skip to content

Commit

Permalink
Merge pull request #2489 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2487-to-release-1.30

[release-1.30] cleanup: upgrade golint version and fix golint errors
  • Loading branch information
andyzhangx authored Sep 5, 2024
2 parents 9d2878d + e0f1f88 commit 3ef777b
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 77 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v4
with:
version: v1.54
version: v1.60
args: --timeout 10m
4 changes: 2 additions & 2 deletions pkg/azuredisk/azure_controller_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const (
maxLUN = 64 // max number of LUNs per VM
errStatusCode400 = "statuscode=400"
errInvalidParameter = `code="invalidparameter"`
errTargetInstanceIds = `target="instanceids"`
errTargetInstanceIDs = `target="instanceids"`
sourceSnapshot = "snapshot"
sourceVolume = "volume"
attachDiskMapKeySuffix = "attachdiskmap"
Expand Down Expand Up @@ -678,5 +678,5 @@ func isInstanceNotFoundError(err error) bool {
if strings.Contains(errMsg, strings.ToLower(consts.VmssVMNotActiveErrorMessage)) {
return true
}
return strings.Contains(errMsg, errStatusCode400) && strings.Contains(errMsg, errInvalidParameter) && strings.Contains(errMsg, errTargetInstanceIds)
return strings.Contains(errMsg, errStatusCode400) && strings.Contains(errMsg, errInvalidParameter) && strings.Contains(errMsg, errTargetInstanceIDs)
}
4 changes: 2 additions & 2 deletions pkg/azuredisk/azure_controller_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var (
)

func fakeUpdateAsync(statusCode int) func(context.Context, string, string, compute.VirtualMachineUpdate, string) (*azure.Future, *retry.Error) {
return func(ctx context.Context, resourceGroup, nodeName string, parameters compute.VirtualMachineUpdate, source string) (*azure.Future, *retry.Error) {
return func(_ context.Context, _, nodeName string, parameters compute.VirtualMachineUpdate, _ string) (*azure.Future, *retry.Error) {
vm := &compute.VirtualMachine{
Name: &nodeName,
Plan: parameters.Plan,
Expand Down Expand Up @@ -818,7 +818,7 @@ func TestIsInstanceNotFoundError(t *testing.T) {
}

for i, test := range testCases {
result := isInstanceNotFoundError(fmt.Errorf(test.errMsg))
result := isInstanceNotFoundError(fmt.Errorf("%v", test.errMsg))
assert.Equal(t, test.expectedResult, result, "TestCase[%d]", i, result)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azure_managedDiskController.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (c *ManagedDiskController) CreateManagedDisk(ctx context.Context, options *
if options.SkipGetDiskOperation {
klog.Warningf("azureDisk - GetDisk(%s, StorageAccountType:%s) is throttled, unable to confirm provisioningState in poll process", options.DiskName, options.StorageAccountType)
} else {
err = kwait.ExponentialBackoffWithContext(ctx, defaultBackOff, func(ctx context.Context) (bool, error) {
err = kwait.ExponentialBackoffWithContext(ctx, defaultBackOff, func(_ context.Context) (bool, error) {
provisionState, id, err := c.GetDisk(ctx, subsID, rg, options.DiskName)
if err == nil {
if id != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azure_managedDiskController_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ func TestCreateManagedDiskWithExtendedLocation(t *testing.T) {
mockDisksClient := mock_diskclient.NewMockInterface(ctrl)
common.clientFactory.(*mock_azclient.MockClientFactory).EXPECT().GetDiskClientForSub(testCloud.SubscriptionID).Return(mockDisksClient, nil).AnyTimes()
mockDisksClient.EXPECT().CreateOrUpdate(gomock.Any(), testCloud.ResourceGroup, diskName, gomock.Any()).
Do(func(ctx interface{}, rg, dn string, disk armcompute.Disk) {
Do(func(_ interface{}, _, _ string, disk armcompute.Disk) {
assert.Equal(t, el.Name, disk.ExtendedLocation.Name, "The extended location name should match.")
assert.Equal(t, el.Type, disk.ExtendedLocation.Type, "The extended location type should match.")
}).Return(to.Ptr(diskreturned), nil)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azuredisk/azuredisk.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,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
2 changes: 1 addition & 1 deletion pkg/azuredisk/azuredisk_option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestDriverOptions_AddFlags(t *testing.T) {

got := o.AddFlags()
count := 0
got.VisitAll(func(f *flag.Flag) {
got.VisitAll(func(_ *flag.Flag) {
count++
})
if count != typeInfo.NumField() {
Expand Down
28 changes: 14 additions & 14 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,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 @@ -395,7 +395,7 @@ func (d *Driver) ControllerModifyVolume(ctx context.Context, req *csi.Controller

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

if _, err := d.checkDiskExists(ctx, diskURI); err != nil {
Expand Down Expand Up @@ -440,7 +440,7 @@ func (d *Driver) ControllerModifyVolume(ctx context.Context, req *csi.Controller
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 @@ -484,7 +484,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 @@ -525,7 +525,7 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
}
var cachingMode armcompute.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 @@ -559,7 +559,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 @@ -591,7 +591,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 @@ -611,7 +611,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 @@ -725,7 +725,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 @@ -834,7 +834,7 @@ func (d *Driver) listVolumesByResourceGroup(ctx context.Context, resourceGroup s
diskClient := d.clientFactory.GetDiskClient()
disks, derr := diskClient.List(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 @@ -932,7 +932,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, req *csi.Controller
}
result, rerr := diskClient.Get(ctx, 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.Properties == nil || result.Properties.DiskSizeGB == nil {
return nil, status.Errorf(codes.Internal, "could not get size of the disk(%s)", diskName)
Expand Down Expand Up @@ -1031,7 +1031,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 @@ -1180,7 +1180,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 @@ -1241,7 +1241,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)
}
}
snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID)
Expand Down
28 changes: 14 additions & 14 deletions pkg/azuredisk/controllerserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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 @@ -312,7 +312,7 @@ func (d *DriverV2) ControllerModifyVolume(ctx context.Context, req *csi.Controll

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

if _, err := d.checkDiskExists(ctx, diskURI); err != nil {
Expand Down Expand Up @@ -357,7 +357,7 @@ func (d *DriverV2) ControllerModifyVolume(ctx context.Context, req *csi.Controll
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 @@ -401,7 +401,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 @@ -433,11 +433,11 @@ func (d *DriverV2) ControllerPublishVolume(ctx context.Context, req *csi.Control
klog.V(2).Infof("Attach operation is successful. volume %s is already attached to node %s at lun %d.", diskURI, nodeName, lun)
} else {
if azureutils.IsThrottlingError(err) {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
var cachingMode armcompute.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 @@ -487,7 +487,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 @@ -579,7 +579,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 @@ -688,7 +688,7 @@ func (d *DriverV2) listVolumesByResourceGroup(ctx context.Context, resourceGroup
diskClient := d.clientFactory.GetDiskClient()
disks, derr := diskClient.List(ctx, resourceGroup)
if derr != nil {
return listVolumeStatus{err: status.Errorf(codes.Internal, "ListVolumes on rg(%s) failed with error: %s", 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 @@ -874,7 +874,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 @@ -950,7 +950,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 @@ -1000,7 +1000,7 @@ func (d *DriverV2) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequ
// no SnapshotId is set, return all snapshots that satisfy the request.
snapshots, err := snapshotClient.List(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 @@ -1012,7 +1012,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)
}
}
snapshotClient, err := d.clientFactory.GetSnapshotClientForSub(subsID)
Expand All @@ -1021,7 +1021,7 @@ func (d *DriverV2) getSnapshotByID(ctx context.Context, subsID, resourceGroup, s
}
snapshot, rerr := snapshotClient.Get(ctx, 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 @@ -132,7 +132,7 @@ func newFakeDriverV1(ctrl *gomock.Controller) (*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 3ef777b

Please sign in to comment.