Skip to content

Commit

Permalink
Merge pull request #1600 from Zhupku/release-1.22
Browse files Browse the repository at this point in the history
[release-1.22] cleanup: upgrade golint version and fix golint errors
  • Loading branch information
k8s-ci-robot committed Sep 18, 2024
2 parents 229fe2a + e01133a commit 4f1879a
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .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
version: v1.60
args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
2 changes: 1 addition & 1 deletion pkg/blob/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func NewDriver(options *DriverOptions) *Driver {
d.NodeID = options.NodeID

var err error
getter := func(key string) (interface{}, error) { return nil, nil }
getter := func(_ string) (interface{}, error) { return nil, nil }
if d.accountSearchCache, err = azcache.NewTimedCache(time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/blob/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
// only do validations here, used in NodeStageVolume, NodePublishVolume
if v != "" {
if _, err := strconv.ParseUint(v, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s in storage class", v))
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s in storage class", v)
}
}
case useDataPlaneAPIField:
useDataPlaneAPI = strings.EqualFold(v, trueValue)
default:
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid parameter %q in storage class", k))
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in storage class", k)
}
}

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

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

if subsID != "" && subsID != d.cloud.SubscriptionID {
if isNFSProtocol(protocol) {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("NFS protocol is not supported in cross subscription(%s)", subsID))
return nil, status.Errorf(codes.InvalidArgument, "NFS protocol is not supported in cross subscription(%s)", subsID)
}
if !storeAccountKey {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("storeAccountKey must set as true in cross subscription(%s)", subsID))
return nil, status.Errorf(codes.InvalidArgument, "storeAccountKey must set as true in cross subscription(%s)", subsID)
}
}

Expand Down Expand Up @@ -271,13 +271,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
if IsAzureStackCloud(d.cloud) {
accountKind = string(storage.KindStorage)
if storageAccountType != "" && storageAccountType != string(storage.SkuNameStandardLRS) && storageAccountType != string(storage.SkuNamePremiumLRS) {
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))
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)
}
}

tags, err := util.ConvertTagsToMap(customTags)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, err.Error())
return nil, status.Errorf(codes.InvalidArgument, "%v", err)
}

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

return int32(days), nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/blob/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (c *mockBlobClient) CreateContainer(_ context.Context, _, _, _, _ string, _
case MANAGEMENT:
return retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedManagementAPIError))
case CUSTOM:
return retry.GetError(&http.Response{}, fmt.Errorf(*c.custom))
return retry.GetError(&http.Response{}, fmt.Errorf("%v", *c.custom))
}
return nil
}
Expand All @@ -76,7 +76,7 @@ func (c *mockBlobClient) DeleteContainer(_ context.Context, _, _, _, _ string) *
case MANAGEMENT:
return retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedManagementAPIError))
case CUSTOM:
return retry.GetError(&http.Response{}, fmt.Errorf(*c.custom))
return retry.GetError(&http.Response{}, fmt.Errorf("%v", *c.custom))
}
return nil
}
Expand All @@ -87,7 +87,7 @@ func (c *mockBlobClient) GetContainer(_ context.Context, _, _, _, _ string) (sto
case MANAGEMENT:
return storage.BlobContainer{ContainerProperties: c.conProp}, retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedManagementAPIError))
case CUSTOM:
return storage.BlobContainer{ContainerProperties: c.conProp}, retry.GetError(&http.Response{}, fmt.Errorf(*c.custom))
return storage.BlobContainer{ContainerProperties: c.conProp}, retry.GetError(&http.Response{}, fmt.Errorf("%v", *c.custom))
}
return storage.BlobContainer{ContainerProperties: c.conProp}, nil
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func TestCreateVolume(t *testing.T) {
controllerServiceCapability,
}

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

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

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

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

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))
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)
_, err := d.CreateVolume(context.Background(), req)
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("Unexpected error: %v", err)
Expand Down Expand Up @@ -1029,7 +1029,7 @@ func TestValidateVolumeCapabilities(t *testing.T) {
clientErr: NULL,
containerProp: &storage.ContainerProperties{},
expectedRes: nil,
expectedErr: status.Errorf(codes.Internal, retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedDataplaneAPIError)).Error().Error()),
expectedErr: status.Errorf(codes.Internal, "%v", retry.GetError(&http.Response{}, fmt.Errorf(containerBeingDeletedDataplaneAPIError)).Error()),
},
/*{ //Volume being shown as not existing. ContainerProperties.Deleted not setting correctly??
name: "Successful I/O",
Expand Down
12 changes: 6 additions & 6 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
var err error
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", perm)
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
klog.Warningf("NodePublishVolume: mock mount on volumeID(%s), this is only for TESTING!!!", volumeID)
if err := volumehelper.MakeDir(target, os.FileMode(mountPermissions)); err != nil {
klog.Errorf("MakeDir failed on target: %s (%v)", target, err)
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
return &csi.NodePublishVolumeResponse{}, nil
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
var err error
var perm uint64
if perm, err = strconv.ParseUint(v, 8, 32); err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", v))
return nil, status.Errorf(codes.InvalidArgument, "invalid mountPermissions %s", v)
}
if perm == 0 {
performChmodOp = false
Expand All @@ -291,7 +291,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe

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

// replace pv/pvc name namespace metadata in subDir
Expand Down Expand Up @@ -372,7 +372,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
klog.Warningf("NodeStageVolume: mock mount on volumeID(%s), this is only for TESTING!!!", volumeID)
if err := volumehelper.MakeDir(targetPath, os.FileMode(mountPermissions)); err != nil {
klog.Errorf("MakeDir failed on target: %s (%v)", targetPath, err)
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
return &csi.NodeStageVolumeResponse{}, nil
}
Expand Down Expand Up @@ -484,7 +484,7 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
// check if the volume stats is cached
cache, err := d.volStatsCache.Get(req.VolumeId, azcache.CacheReadTypeDefault)
if err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
if cache != nil {
resp := cache.(csi.NodeGetVolumeStatsResponse)
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi-common/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestLogGRPC(t *testing.T) {
klog.SetOutput(buf)
defer klog.SetOutput(io.Discard)

handler := func(ctx context.Context, req interface{}) (interface{}, error) { return nil, nil }
handler := func(_ context.Context, _ interface{}) (interface{}, error) { return nil, nil }
info := grpc.UnaryServerInfo{
FullMethod: "fake",
}
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var _ = ginkgo.Describe("[blob-csi-e2e] Dynamic Provisioning", func() {
testDriver driver.PVTestDriver
)

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

ginkgo.It("[blob.csi.azure.com] verify examples", ginkgo.Label("flaky"), func(ctx ginkgo.SpecContext) {
ginkgo.It("[blob.csi.azure.com] verify examples", ginkgo.Label("flaky"), func(_ ginkgo.SpecContext) {
createExampleDeployment := testCmd{
command: "bash",
args: []string{"hack/verify-examples.sh"},
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx ginkgo.SpecContext) []byte {
}
execTestCmd([]testCmd{e2eBootstrap, createMetricsSVC})
return nil
}, func(ctx ginkgo.SpecContext, data []byte) {
}, func(_ ginkgo.SpecContext, _ []byte) {
// k8s.io/kubernetes/test/e2e/framework requires env KUBECONFIG to be set
// it does not fall back to defaults
if os.Getenv(kubeconfigEnvVar) == "" {
Expand All @@ -126,7 +126,7 @@ var _ = ginkgo.SynchronizedBeforeSuite(func(ctx ginkgo.SpecContext) []byte {
}()
})

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

0 comments on commit 4f1879a

Please sign in to comment.