Skip to content

Commit 100d28f

Browse files
authored
Merge pull request #2110 from Zhupku/release-1.28
[release-1.28] cleanup: upgrade golint version and fix golint errors
2 parents 34dec0e + b55bddf commit 100d28f

9 files changed

+49
-49
lines changed

.github/workflows/static.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ jobs:
1515
- name: Run linter
1616
uses: golangci/golangci-lint-action@v3
1717
with:
18-
version: v1.54
18+
version: v1.60
1919
args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s

pkg/azurefile/azurefile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ func NewDriver(options *DriverOptions) *Driver {
315315
driver.volumeLocks = newVolumeLocks()
316316

317317
var err error
318-
getter := func(key string) (interface{}, error) { return nil, nil }
318+
getter := func(_ string) (interface{}, error) { return nil, nil }
319319

320320
if driver.secretCacheMap, err = azcache.NewTimedCache(time.Minute, getter, false); err != nil {
321321
klog.Fatalf("%v", err)

pkg/azurefile/controllerserver.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
160160
case selectRandomMatchingAccountField:
161161
value, err := strconv.ParseBool(v)
162162
if err != nil {
163-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", selectRandomMatchingAccountField, v))
163+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", selectRandomMatchingAccountField, v)
164164
}
165165
selectRandomMatchingAccount = value
166166
case secretNameField:
@@ -180,15 +180,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
180180
case enableLargeFileSharesField:
181181
value, err := strconv.ParseBool(v)
182182
if err != nil {
183-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", enableLargeFileSharesField, v))
183+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", enableLargeFileSharesField, v)
184184
}
185185
enableLFS = &value
186186
case useDataPlaneAPIField:
187187
useDataPlaneAPI = strings.EqualFold(v, trueValue)
188188
case disableDeleteRetentionPolicyField:
189189
value, err := strconv.ParseBool(v)
190190
if err != nil {
191-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", disableDeleteRetentionPolicyField, v))
191+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", disableDeleteRetentionPolicyField, v)
192192
}
193193
disableDeleteRetentionPolicy = &value
194194
case pvcNamespaceKey:
@@ -209,13 +209,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
209209
case allowBlobPublicAccessField:
210210
value, err := strconv.ParseBool(v)
211211
if err != nil {
212-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowBlobPublicAccessField, v))
212+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowBlobPublicAccessField, v)
213213
}
214214
allowBlobPublicAccess = &value
215215
case allowSharedKeyAccessField:
216216
value, err := strconv.ParseBool(v)
217217
if err != nil {
218-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowSharedKeyAccessField, v))
218+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowSharedKeyAccessField, v)
219219
}
220220
allowSharedKeyAccess = &value
221221
case pvcNameKey:
@@ -231,7 +231,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
231231
case mountPermissionsField:
232232
// only do validations here, used in NodeStageVolume, NodePublishVolume
233233
if _, err := strconv.ParseUint(v, 8, 32); err != nil {
234-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s in storage class", v))
234+
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s in storage class", v)
235235
}
236236
case vnetResourceGroupField:
237237
vnetResourceGroup = v
@@ -244,39 +244,39 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
244244
case requireInfraEncryptionField:
245245
value, err := strconv.ParseBool(v)
246246
if err != nil {
247-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", requireInfraEncryptionField, v))
247+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", requireInfraEncryptionField, v)
248248
}
249249
requireInfraEncryption = &value
250250
case enableMultichannelField:
251251
value, err := strconv.ParseBool(v)
252252
if err != nil {
253-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", enableMultichannelField, v))
253+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", enableMultichannelField, v)
254254
}
255255
isMultichannelEnabled = &value
256256
case getLatestAccountKeyField:
257257
value, err := strconv.ParseBool(v)
258258
if err != nil {
259-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", getLatestAccountKeyField, v))
259+
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", getLatestAccountKeyField, v)
260260
}
261261
getLatestAccountKey = value
262262
case accountQuotaField:
263263
value, err := strconv.ParseInt(v, 10, 32)
264264
if err != nil || value < minimumAccountQuota {
265-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid accountQuota %s in storage class, minimum quota: %d", v, minimumAccountQuota))
265+
return nil, status.Errorf(codes.InvalidArgument, "invalid accountQuota %s in storage class, minimum quota: %d", v, minimumAccountQuota)
266266
}
267267
accountQuota = int32(value)
268268
default:
269-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", k))
269+
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
270270
}
271271
}
272272

273273
if matchTags && account != "" {
274-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("matchTags must set as false when storageAccount(%s) is provided", account))
274+
return nil, status.Errorf(codes.InvalidArgument, "matchTags must set as false when storageAccount(%s) is provided", account)
275275
}
276276

277277
if subsID != "" && subsID != d.cloud.SubscriptionID {
278278
if resourceGroup == "" {
279-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("resourceGroup must be provided in cross subscription(%s)", subsID))
279+
return nil, status.Errorf(codes.InvalidArgument, "resourceGroup must be provided in cross subscription(%s)", subsID)
280280
}
281281
}
282282

@@ -402,7 +402,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
402402

403403
tags, err := ConvertTagsToMap(customTags)
404404
if err != nil {
405-
return nil, status.Errorf(codes.InvalidArgument, err.Error())
405+
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
406406
}
407407

408408
if strings.TrimSpace(storageEndpointSuffix) == "" {
@@ -469,7 +469,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
469469
// search in cache first
470470
cache, err := d.accountSearchCache.Get(lockKey, azcache.CacheReadTypeDefault)
471471
if err != nil {
472-
return nil, status.Errorf(codes.Internal, err.Error())
472+
return nil, status.Errorf(codes.Internal, "%v", err)
473473
}
474474
if cache != nil {
475475
accountName = cache.(string)
@@ -525,7 +525,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
525525
// skip validating file share quota if useDataPlaneAPI
526526
} else {
527527
if quota, err := d.getFileShareQuota(ctx, subsID, resourceGroup, accountName, validFileShareName, secret); err != nil {
528-
return nil, status.Errorf(codes.Internal, err.Error())
528+
return nil, status.Errorf(codes.Internal, "%v", err)
529529
} else if quota != -1 && quota < fileShareSize {
530530
return nil, status.Errorf(codes.AlreadyExists, "request file share(%s) already exists, but its capacity %d is smaller than %d", validFileShareName, quota, fileShareSize)
531531
}
@@ -552,7 +552,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
552552
d.volumeLocks.Release(volName)
553553
// clean search cache
554554
if err := d.accountSearchCache.Delete(lockKey); err != nil {
555-
return nil, status.Errorf(codes.Internal, err.Error())
555+
return nil, status.Errorf(codes.Internal, "%v", err)
556556
}
557557
// remove the volName from the volMap to stop matching the same storage account
558558
d.volMap.Delete(volName)
@@ -935,7 +935,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
935935
case useDataPlaneAPIField:
936936
useDataPlaneAPI = strings.EqualFold(v, trueValue)
937937
default:
938-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", k))
938+
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
939939
}
940940
}
941941

@@ -1300,11 +1300,11 @@ func isValidVolumeCapabilities(volCaps []*csi.VolumeCapability) error {
13001300
func generateSASToken(accountName, accountKey, storageEndpointSuffix string, expiryTime int) (string, error) {
13011301
credential, err := service.NewSharedKeyCredential(accountName, accountKey)
13021302
if err != nil {
1303-
return "", status.Errorf(codes.Internal, fmt.Sprintf("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", accountName, err.Error()))
1303+
return "", status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %v", accountName, err)
13041304
}
13051305
serviceClient, err := service.NewClientWithSharedKeyCredential(fmt.Sprintf("https://%s.file.%s/", accountName, storageEndpointSuffix), credential, nil)
13061306
if err != nil {
1307-
return "", status.Errorf(codes.Internal, fmt.Sprintf("failed to generate sas token in creating new client with shared key credential, accountName: %s, err: %s", accountName, err.Error()))
1307+
return "", status.Errorf(codes.Internal, "failed to generate sas token in creating new client with shared key credential, accountName: %s, err: %v", accountName, err)
13081308
}
13091309
nowTime := time.Now()
13101310
sasURL, err := serviceClient.GetSASURL(

pkg/azurefile/controllerserver_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func TestCreateVolume(t *testing.T) {
371371

372372
d := NewFakeDriver()
373373

374-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid accountQuota %d in storage class, minimum quota: %d", 10, minimumAccountQuota))
374+
expectedErr := status.Errorf(codes.InvalidArgument, "invalid accountQuota %d in storage class, minimum quota: %d", 10, minimumAccountQuota)
375375
_, err := d.CreateVolume(ctx, req)
376376
if !reflect.DeepEqual(err, expectedErr) {
377377
t.Errorf("Unexpected error: %v", err)
@@ -403,7 +403,7 @@ func TestCreateVolume(t *testing.T) {
403403

404404
d := NewFakeDriver()
405405

406-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Errorf("Tags 'tags' are invalid, the format should like: 'key1=value1,key2=value2'").Error())
406+
expectedErr := status.Errorf(codes.InvalidArgument, "%v", "Tags 'tags' are invalid, the format should like: 'key1=value1,key2=value2'")
407407
_, err := d.CreateVolume(ctx, req)
408408
if !reflect.DeepEqual(err, expectedErr) {
409409
t.Errorf("Unexpected error: %v", err)
@@ -1184,7 +1184,7 @@ func TestCreateVolume(t *testing.T) {
11841184
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
11851185
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()
11861186

1187-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s %s in storage class", "mountPermissions", "0abc"))
1187+
expectedErr := status.Errorf(codes.InvalidArgument, "invalid %s %s in storage class", "mountPermissions", "0abc")
11881188
_, err := d.CreateVolume(ctx, req)
11891189
if !reflect.DeepEqual(err, expectedErr) {
11901190
t.Errorf("Unexpected error: %v", err)
@@ -1239,7 +1239,7 @@ func TestCreateVolume(t *testing.T) {
12391239
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
12401240
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()
12411241

1242-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", "invalidparameter"))
1242+
expectedErr := status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", "invalidparameter")
12431243
_, err := d.CreateVolume(ctx, req)
12441244
if !reflect.DeepEqual(err, expectedErr) {
12451245
t.Errorf("Unexpected error: %v", err)
@@ -1400,7 +1400,7 @@ func TestDeleteVolume(t *testing.T) {
14001400
},
14011401
},
14021402
}
1403-
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
1403+
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
14041404
d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1")
14051405
d.cloud = &azure.Cloud{}
14061406

@@ -1825,7 +1825,7 @@ func TestControllerPublishVolume(t *testing.T) {
18251825
d.cloud = azure.GetTestCloud(ctrl)
18261826
d.cloud.Location = "centralus"
18271827
d.cloud.ResourceGroup = "rg"
1828-
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
1828+
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
18291829
nodeName := "vm1"
18301830
instanceID := fmt.Sprintf("/subscriptions/subscription/resourceGroups/rg/providers/Microsoft.Compute/virtualMachines/%s", nodeName)
18311831
vm := compute.VirtualMachine{
@@ -1937,7 +1937,7 @@ func TestControllerPublishVolume(t *testing.T) {
19371937
VolumeCapability: &stdVolCap,
19381938
NodeId: "vm3",
19391939
},
1940-
expectedErr: status.Error(codes.Internal, fmt.Sprintf("getFileURL(^f5713de20cde511e8ba4900,abc,fileshare,diskname.vhd) returned with error: %v", fmt.Errorf("parse fileURLTemplate error: %v", &url.Error{Op: "parse", URL: "https://^f5713de20cde511e8ba4900.file.abc/fileshare/diskname.vhd", Err: url.InvalidHostError("^")}))),
1940+
expectedErr: status.Error(codes.Internal, fmt.Sprintf("getFileURL(^f5713de20cde511e8ba4900,abc,fileshare,diskname.vhd) returned with error: parse fileURLTemplate error: %v", &url.Error{Op: "parse", URL: "https://^f5713de20cde511e8ba4900.file.abc/fileshare/diskname.vhd", Err: url.InvalidHostError("^")})),
19411941
},
19421942
}
19431943

@@ -2017,7 +2017,7 @@ func TestControllerUnpublishVolume(t *testing.T) {
20172017
NodeId: fakeNodeID,
20182018
Secrets: map[string]string{},
20192019
},
2020-
expectedErr: status.Error(codes.Internal, fmt.Sprintf("getFileURL(^f5713de20cde511e8ba4900,abc,fileshare,diskname.vhd) returned with error: %v", fmt.Errorf("parse fileURLTemplate error: %v", &url.Error{Op: "parse", URL: "https://^f5713de20cde511e8ba4900.file.abc/fileshare/diskname.vhd", Err: url.InvalidHostError("^")}))),
2020+
expectedErr: status.Error(codes.Internal, fmt.Sprintf("getFileURL(^f5713de20cde511e8ba4900,abc,fileshare,diskname.vhd) returned with error: parse fileURLTemplate error: %v", &url.Error{Op: "parse", URL: "https://^f5713de20cde511e8ba4900.file.abc/fileshare/diskname.vhd", Err: url.InvalidHostError("^")})),
20212021
},
20222022
}
20232023

@@ -2293,7 +2293,7 @@ func TestControllerExpandVolume(t *testing.T) {
22932293
ResourceGroup: "vol_2",
22942294
},
22952295
}
2296-
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
2296+
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
22972297
d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1")
22982298
ctrl := gomock.NewController(t)
22992299
defer ctrl.Finish()
@@ -2665,7 +2665,7 @@ func TestGenerateSASToken(t *testing.T) {
26652665
accountName: "unit-test",
26662666
accountKey: "fakeValue",
26672667
want: "",
2668-
expectedErr: status.Errorf(codes.Internal, fmt.Sprintf("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "unit-test", "decode account key: illegal base64 data at input byte 8")),
2668+
expectedErr: status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "unit-test", "decode account key: illegal base64 data at input byte 8"),
26692669
},
26702670
}
26712671
for _, tt := range tests {

pkg/azurefile/nodeserver.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
7979
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
8080
var err error
8181
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
82-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))
82+
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", perm)
8383
}
8484
}
8585
}
@@ -213,7 +213,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
213213
var err error
214214
var perm uint64
215215
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
216-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
216+
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", v)
217217
}
218218
if perm == 0 {
219219
performChmodOp = false
@@ -446,7 +446,7 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
446446
// check if the volume stats is cached
447447
cache, err := d.volStatsCache.Get(req.VolumeId, azcache.CacheReadTypeDefault)
448448
if err != nil {
449-
return nil, status.Errorf(codes.Internal, err.Error())
449+
return nil, status.Errorf(codes.Internal, "%v", err)
450450
}
451451
if cache != nil {
452452
resp := cache.(csi.NodeGetVolumeStatsResponse)
@@ -468,7 +468,7 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
468468
}
469469

470470
if cache, err = d.volStatsCache.Get(newVolID, azcache.CacheReadTypeDefault); err != nil {
471-
return nil, status.Errorf(codes.Internal, err.Error())
471+
return nil, status.Errorf(codes.Internal, "%v", err)
472472
}
473473
if cache != nil {
474474
resp := cache.(csi.NodeGetVolumeStatsResponse)

0 commit comments

Comments
 (0)