Skip to content

Commit 4f1879a

Browse files
authored
Merge pull request #1600 from Zhupku/release-1.22
[release-1.22] cleanup: upgrade golint version and fix golint errors
2 parents 229fe2a + e01133a commit 4f1879a

File tree

8 files changed

+33
-33
lines changed

8 files changed

+33
-33
lines changed

.github/workflows/static.yaml

Lines changed: 1 addition & 1 deletion
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,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s

pkg/blob/blob.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func NewDriver(options *DriverOptions) *Driver {
243243
d.NodeID = options.NodeID
244244

245245
var err error
246-
getter := func(key string) (interface{}, error) { return nil, nil }
246+
getter := func(_ string) (interface{}, error) { return nil, nil }
247247
if d.accountSearchCache, err = azcache.NewTimedCache(time.Minute, getter, false); err != nil {
248248
klog.Fatalf("%v", err)
249249
}

pkg/blob/controllerserver.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
181181
// only do validations here, used in NodeStageVolume, NodePublishVolume
182182
if v != "" {
183183
if _, err := strconv.ParseUint(v, 8, 32); err != nil {
184-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s in storage class", v))
184+
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s in storage class", v)
185185
}
186186
}
187187
case useDataPlaneAPIField:
188188
useDataPlaneAPI = strings.EqualFold(v, trueValue)
189189
default:
190-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", k))
190+
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
191191
}
192192
}
193193

@@ -198,15 +198,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
198198
}
199199

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

204204
if subsID != "" && subsID != d.cloud.SubscriptionID {
205205
if isNFSProtocol(protocol) {
206-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("NFS protocol is not supported in cross subscription(%s)", subsID))
206+
return nil, status.Errorf(codes.InvalidArgument, "NFS protocol is not supported in cross subscription(%s)", subsID)
207207
}
208208
if !storeAccountKey {
209-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("storeAccountKey must set as true in cross subscription(%s)", subsID))
209+
return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey must set as true in cross subscription(%s)", subsID)
210210
}
211211
}
212212

@@ -271,13 +271,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
271271
if IsAzureStackCloud(d.cloud) {
272272
accountKind = string(storage.KindStorage)
273273
if storageAccountType != "" && storageAccountType != string(storage.SkuNameStandardLRS) && storageAccountType != string(storage.SkuNamePremiumLRS) {
274-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("Invalid skuName value: %s, as Azure Stack only supports %s and %s Storage Account types.", storageAccountType, storage.SkuNamePremiumLRS, storage.SkuNameStandardLRS))
274+
return nil, status.Errorf(codes.InvalidArgument, "Invalid skuName value: %s, as Azure Stack only supports %s and %s Storage Account types.", storageAccountType, storage.SkuNamePremiumLRS, storage.SkuNameStandardLRS)
275275
}
276276
}
277277

278278
tags, err := util.ConvertTagsToMap(customTags)
279279
if err != nil {
280-
return nil, status.Errorf(codes.InvalidArgument, err.Error())
280+
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
281281
}
282282

283283
if strings.TrimSpace(storageEndpointSuffix) == "" {
@@ -330,7 +330,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
330330
// search in cache first
331331
cache, err := d.accountSearchCache.Get(lockKey, azcache.CacheReadTypeDefault)
332332
if err != nil {
333-
return nil, status.Errorf(codes.Internal, err.Error())
333+
return nil, status.Errorf(codes.Internal, "%v", err)
334334
}
335335
if cache != nil {
336336
accountName = cache.(string)
@@ -691,10 +691,10 @@ func isValidVolumeCapabilities(volCaps []*csi.VolumeCapability) error {
691691
func parseDays(dayStr string) (int32, error) {
692692
days, err := strconv.Atoi(dayStr)
693693
if err != nil {
694-
return 0, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s:%s in storage class", softDeleteBlobsField, dayStr))
694+
return 0, status.Errorf(codes.InvalidArgument, "invalid %s:%s in storage class", softDeleteBlobsField, dayStr)
695695
}
696696
if days <= 0 || days > 365 {
697-
return 0, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s:%s in storage class, should be in range [1, 365]", softDeleteBlobsField, dayStr))
697+
return 0, status.Errorf(codes.InvalidArgument, "invalid %s:%s in storage class, should be in range [1, 365]", softDeleteBlobsField, dayStr)
698698
}
699699

700700
return int32(days), nil

pkg/blob/controllerserver_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (c *mockBlobClient) CreateContainer(_ context.Context, _, _, _, _ string, _
6565
case MANAGEMENT:
6666
return retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedManagementAPIError))
6767
case CUSTOM:
68-
return retry.GetError(&http.Response{}, fmt.Errorf(*c.custom))
68+
return retry.GetError(&http.Response{}, fmt.Errorf("%v", *c.custom))
6969
}
7070
return nil
7171
}
@@ -76,7 +76,7 @@ func (c *mockBlobClient) DeleteContainer(_ context.Context, _, _, _, _ string) *
7676
case MANAGEMENT:
7777
return retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedManagementAPIError))
7878
case CUSTOM:
79-
return retry.GetError(&http.Response{}, fmt.Errorf(*c.custom))
79+
return retry.GetError(&http.Response{}, fmt.Errorf("%v", *c.custom))
8080
}
8181
return nil
8282
}
@@ -87,7 +87,7 @@ func (c *mockBlobClient) GetContainer(_ context.Context, _, _, _, _ string) (sto
8787
case MANAGEMENT:
8888
return storage.BlobContainer{ContainerProperties: c.conProp}, retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedManagementAPIError))
8989
case CUSTOM:
90-
return storage.BlobContainer{ContainerProperties: c.conProp}, retry.GetError(&http.Response{}, fmt.Errorf(*c.custom))
90+
return storage.BlobContainer{ContainerProperties: c.conProp}, retry.GetError(&http.Response{}, fmt.Errorf("%v", *c.custom))
9191
}
9292
return storage.BlobContainer{ContainerProperties: c.conProp}, nil
9393
}
@@ -420,7 +420,7 @@ func TestCreateVolume(t *testing.T) {
420420
controllerServiceCapability,
421421
}
422422

423-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", "invalidparameter"))
423+
expectedErr := status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", "invalidparameter")
424424
_, err := d.CreateVolume(context.Background(), req)
425425
if !reflect.DeepEqual(err, expectedErr) {
426426
t.Errorf("Unexpected error: %v", err)
@@ -442,7 +442,7 @@ func TestCreateVolume(t *testing.T) {
442442
controllerServiceCapability,
443443
}
444444

445-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s %s in storage class", "mountPermissions", "0abc"))
445+
expectedErr := status.Errorf(codes.InvalidArgument, "invalid %s %s in storage class", "mountPermissions", "0abc")
446446
_, err := d.CreateVolume(context.Background(), req)
447447
if !reflect.DeepEqual(err, expectedErr) {
448448
t.Errorf("Unexpected error: %v", err)
@@ -474,7 +474,7 @@ func TestCreateVolume(t *testing.T) {
474474
controllerServiceCapability,
475475
}
476476

477-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("NFS protocol is not supported in cross subscription(%s)", "foo"))
477+
expectedErr := status.Errorf(codes.InvalidArgument, "NFS protocol is not supported in cross subscription(%s)", "foo")
478478
_, err := d.CreateVolume(context.Background(), req)
479479
if !reflect.DeepEqual(err, expectedErr) {
480480
t.Errorf("Unexpected error: %v", err)
@@ -507,7 +507,7 @@ func TestCreateVolume(t *testing.T) {
507507
controllerServiceCapability,
508508
}
509509

510-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("storeAccountKey must set as true in cross subscription(%s)", "foo"))
510+
expectedErr := status.Errorf(codes.InvalidArgument, "storeAccountKey must set as true in cross subscription(%s)", "foo")
511511
_, err := d.CreateVolume(context.Background(), req)
512512
if !reflect.DeepEqual(err, expectedErr) {
513513
t.Errorf("Unexpected error: %v", err)
@@ -579,7 +579,7 @@ func TestCreateVolume(t *testing.T) {
579579
controllerServiceCapability,
580580
}
581581

582-
expectedErr := status.Errorf(codes.InvalidArgument, fmt.Sprintf("Invalid skuName value: %s, as Azure Stack only supports %s and %s Storage Account types.", "unit-test", storage.SkuNamePremiumLRS, storage.SkuNameStandardLRS))
582+
expectedErr := status.Errorf(codes.InvalidArgument, "Invalid skuName value: %s, as Azure Stack only supports %s and %s Storage Account types.", "unit-test", storage.SkuNamePremiumLRS, storage.SkuNameStandardLRS)
583583
_, err := d.CreateVolume(context.Background(), req)
584584
if !reflect.DeepEqual(err, expectedErr) {
585585
t.Errorf("Unexpected error: %v", err)
@@ -1029,7 +1029,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
10291029
clientErr: NULL,
10301030
containerProp: &storage.ContainerProperties{},
10311031
expectedRes: nil,
1032-
expectedErr: status.Errorf(codes.Internal, retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedDataplaneAPIError)).Error().Error()),
1032+
expectedErr: status.Errorf(codes.Internal, "%v", retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedDataplaneAPIError)).Error()),
10331033
},
10341034
/*{ //Volume being shown as not existing. ContainerProperties.Deleted not setting correctly??
10351035
name: "Successful I/O",

pkg/blob/nodeserver.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
9999
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
100100
var err error
101101
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
102-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))
102+
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", perm)
103103
}
104104
}
105105
}
@@ -128,7 +128,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
128128
klog.Warningf("NodePublishVolume: mock mount on volumeID(%s), this is only for TESTING!!!", volumeID)
129129
if err := volumehelper.MakeDir(target, os.FileMode(mountPermissions)); err != nil {
130130
klog.Errorf("MakeDir failed on target: %s (%v)", target, err)
131-
return nil, status.Errorf(codes.Internal, err.Error())
131+
return nil, status.Errorf(codes.Internal, "%v", err)
132132
}
133133
return &csi.NodePublishVolumeResponse{}, nil
134134
}
@@ -269,7 +269,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
269269
var err error
270270
var perm uint64
271271
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
272-
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
272+
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", v)
273273
}
274274
if perm == 0 {
275275
performChmodOp = false
@@ -291,7 +291,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
291291

292292
_, accountName, _, containerName, authEnv, err := d.GetAuthEnv(ctx, volumeID, protocol, attrib, secrets)
293293
if err != nil {
294-
return nil, status.Errorf(codes.Internal, err.Error())
294+
return nil, status.Errorf(codes.Internal, "%v", err)
295295
}
296296

297297
// replace pv/pvc name namespace metadata in subDir
@@ -372,7 +372,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
372372
klog.Warningf("NodeStageVolume: mock mount on volumeID(%s), this is only for TESTING!!!", volumeID)
373373
if err := volumehelper.MakeDir(targetPath, os.FileMode(mountPermissions)); err != nil {
374374
klog.Errorf("MakeDir failed on target: %s (%v)", targetPath, err)
375-
return nil, status.Errorf(codes.Internal, err.Error())
375+
return nil, status.Errorf(codes.Internal, "%v", err)
376376
}
377377
return &csi.NodeStageVolumeResponse{}, nil
378378
}
@@ -484,7 +484,7 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
484484
// check if the volume stats is cached
485485
cache, err := d.volStatsCache.Get(req.VolumeId, azcache.CacheReadTypeDefault)
486486
if err != nil {
487-
return nil, status.Errorf(codes.Internal, err.Error())
487+
return nil, status.Errorf(codes.Internal, "%v", err)
488488
}
489489
if cache != nil {
490490
resp := cache.(csi.NodeGetVolumeStatsResponse)

pkg/csi-common/utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestLogGRPC(t *testing.T) {
8989
klog.SetOutput(buf)
9090
defer klog.SetOutput(io.Discard)
9191

92-
handler := func(ctx context.Context, req interface{}) (interface{}, error) { return nil, nil }
92+
handler := func(_ context.Context, _ interface{}) (interface{}, error) { return nil, nil }
9393
info := grpc.UnaryServerInfo{
9494
FullMethod: "fake",
9595
}

test/e2e/dynamic_provisioning_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
4040
testDriver driver.PVTestDriver
4141
)
4242

43-
ginkgo.BeforeEach(func(ctx ginkgo.SpecContext) {
43+
ginkgo.BeforeEach(func(_ ginkgo.SpecContext) {
4444
checkPodsRestart := testCmd{
4545
command: "sh",
4646
args: []string{"test/utils/check_driver_pods_restart.sh"},
@@ -826,7 +826,7 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
826826
test.Run(ctx, cs, ns)
827827
})
828828

829-
ginkgo.It("[blob.csi.azure.com] verify examples", ginkgo.Label("flaky"), func(ctx ginkgo.SpecContext) {
829+
ginkgo.It("[blob.csi.azure.com] verify examples", ginkgo.Label("flaky"), func(_ ginkgo.SpecContext) {
830830
createExampleDeployment := testCmd{
831831
command: "bash",
832832
args: []string{"hack/verify-examples.sh"},

test/e2e/suite_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx ginkgo.SpecContext) []byte {
100100
}
101101
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})
102102
return nil
103-
}, func(ctx ginkgo.SpecContext, data []byte) {
103+
}, func(_ ginkgo.SpecContext, _ []byte) {
104104
// k8s.io/kubernetes/test/e2e/framework requires env KUBECONFIG to be set
105105
// it does not fall back to defaults
106106
if os.Getenv(kubeconfigEnvVar) == "" {
@@ -126,7 +126,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx ginkgo.SpecContext) []byte {
126126
}()
127127
})
128128

129-
var _ = ginkgo.SynchronizedAfterSuite(func(ctx ginkgo.SpecContext) {},
129+
var _ = ginkgo.SynchronizedAfterSuite(func(_ ginkgo.SpecContext) {},
130130
func(ctx ginkgo.SpecContext) {
131131
blobLog := testCmd{
132132
command: "bash",
@@ -175,7 +175,7 @@ func execTestCmd(cmds []testCmd) {
175175
cmdSh.Stderr = os.Stderr
176176
err := cmdSh.Run()
177177
if err != nil {
178-
log.Printf("Failed to run command: %s %s, Error: %s\n", cmd.command, strings.Join(cmd.args, " "), err.Error())
178+
log.Printf("Failed to run command: %s %s, Error: %v\n", cmd.command, strings.Join(cmd.args, " "), err)
179179
if !cmd.ignoreError {
180180
gomega.Expect(err).NotTo(gomega.HaveOccurred())
181181
}

0 commit comments

Comments
 (0)