Skip to content

Commit

Permalink
test: upgrade golint version in github action
Browse files Browse the repository at this point in the history
fix golint

fix golint

fix golint

fix

fix
  • Loading branch information
andyzhangx committed Sep 1, 2024
1 parent e98134c commit 8ab0074
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 51 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@v6
with:
version: v1.54
version: v1.60
args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
2 changes: 1 addition & 1 deletion pkg/azurefile/azurefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func NewDriver(options *DriverOptions) *Driver {
driver.endpoint = options.Endpoint

var err error
getter := func(key string) (interface{}, error) { return nil, nil }
getter := func(_ string) (interface{}, error) { return nil, nil }

if driver.secretCacheMap, err = azcache.NewTimedCache(time.Minute, getter, false); err != nil {
klog.Fatalf("%v", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/azurefile/azurefile_options_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
42 changes: 21 additions & 21 deletions pkg/azurefile/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case selectRandomMatchingAccountField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", selectRandomMatchingAccountField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", selectRandomMatchingAccountField, v)
}
selectRandomMatchingAccount = value
case secretNameField:
Expand All @@ -194,15 +194,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case enableLargeFileSharesField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", enableLargeFileSharesField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", enableLargeFileSharesField, v)
}
enableLFS = &value
case useDataPlaneAPIField:
useDataPlaneAPI = strings.EqualFold(v, trueValue)
case disableDeleteRetentionPolicyField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", disableDeleteRetentionPolicyField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", disableDeleteRetentionPolicyField, v)
}
disableDeleteRetentionPolicy = &value
case pvcNamespaceKey:
Expand All @@ -223,13 +223,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case allowBlobPublicAccessField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowBlobPublicAccessField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowBlobPublicAccessField, v)
}
allowBlobPublicAccess = &value
case allowSharedKeyAccessField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", allowSharedKeyAccessField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", allowSharedKeyAccessField, v)
}
allowSharedKeyAccess = &value
case pvcNameKey:
Expand All @@ -245,7 +245,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case mountPermissionsField:
// only do validations here, used in NodeStageVolume, NodePublishVolume
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 vnetResourceGroupField:
vnetResourceGroup = v
Expand All @@ -258,41 +258,41 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
case requireInfraEncryptionField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", requireInfraEncryptionField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", requireInfraEncryptionField, v)
}
requireInfraEncryption = &value
case enableMultichannelField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", enableMultichannelField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", enableMultichannelField, v)
}
isMultichannelEnabled = &value
case getLatestAccountKeyField:
value, err := strconv.ParseBool(v)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid %s: %s in storage class", getLatestAccountKeyField, v))
return nil, status.Errorf(codes.InvalidArgument, "invalid %s: %s in storage class", getLatestAccountKeyField, v)
}
getLatestAccountKey = value
case accountQuotaField:
value, err := strconv.ParseInt(v, 10, 32)
if err != nil || value < minimumAccountQuota {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid accountQuota %s in storage class, minimum quota: %d", v, minimumAccountQuota))
return nil, status.Errorf(codes.InvalidArgument, "invalid accountQuota %s in storage class, minimum quota: %d", v, minimumAccountQuota)
}
accountQuota = int32(value)
case tagValueDelimiterField:
tagValueDelimiter = v
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)
}
}

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 resourceGroup == "" {
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("resourceGroup must be provided in cross subscription(%s)", subsID))
return nil, status.Errorf(codes.InvalidArgument, "resourceGroup must be provided in cross subscription(%s)", subsID)
}
}

Expand Down Expand Up @@ -433,7 +433,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)

tags, err := ConvertTagsToMap(customTags, tagValueDelimiter)
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 @@ -497,7 +497,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 @@ -553,7 +553,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
// skip validating file share quota if useDataPlaneAPI
} else {
if quota, err := d.getFileShareQuota(ctx, subsID, resourceGroup, accountName, validFileShareName, secret); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
} else if quota != -1 && quota < fileShareSize {
return nil, status.Errorf(codes.AlreadyExists, "request file share(%s) already exists, but its capacity %d is smaller than %d", validFileShareName, quota, fileShareSize)
}
Expand Down Expand Up @@ -581,7 +581,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
d.volumeLocks.Release(volName)
// clean search cache
if err := d.accountSearchCache.Delete(lockKey); err != nil {
return nil, status.Errorf(codes.Internal, err.Error())
return nil, status.Errorf(codes.Internal, "%v", err)
}
// remove the volName from the volMap to stop matching the same storage account
d.volMap.Delete(volName)
Expand Down Expand Up @@ -857,7 +857,7 @@ func (d *Driver) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequ
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 Down Expand Up @@ -1358,7 +1358,7 @@ func (d *Driver) authorizeAzcopyWithIdentity() ([]string, error) {
authAzcopyEnv = append(authAzcopyEnv, fmt.Sprintf("%s=%s", azcopySPAApplicationID, azureAuthConfig.AADClientID))
authAzcopyEnv = append(authAzcopyEnv, fmt.Sprintf("%s=%s", azcopySPAClientSecret, azureAuthConfig.AADClientSecret))
authAzcopyEnv = append(authAzcopyEnv, fmt.Sprintf("%s=%s", azcopyTenantID, azureAuthConfig.TenantID))
klog.V(2).Infof(fmt.Sprintf("set AZCOPY_SPA_APPLICATION_ID=%s, AZCOPY_TENANT_ID=%s successfully", azureAuthConfig.AADClientID, azureAuthConfig.TenantID))
klog.V(2).Infof("set AZCOPY_SPA_APPLICATION_ID=%s, AZCOPY_TENANT_ID=%s successfully", azureAuthConfig.AADClientID, azureAuthConfig.TenantID)

return authAzcopyEnv, nil
}
Expand Down Expand Up @@ -1411,13 +1411,13 @@ func (d *Driver) generateSASToken(accountName, accountKey, storageEndpointSuffix

credential, err := service.NewSharedKeyCredential(accountName, accountKey)
if err != nil {
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()))
return "", status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", accountName, err.Error())
}
clientOptions := service.ClientOptions{}
clientOptions.InsecureAllowCredentialWithHTTP = true
serviceClient, err := service.NewClientWithSharedKeyCredential(fmt.Sprintf("https://%s.file.%s/", accountName, storageEndpointSuffix), credential, &clientOptions)
if err != nil {
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()))
return "", status.Errorf(codes.Internal, "failed to generate sas token in creating new client with shared key credential, accountName: %s, err: %s", accountName, err.Error())
}
nowTime := time.Now()
sasURL, err := serviceClient.GetSASURL(
Expand Down
16 changes: 8 additions & 8 deletions pkg/azurefile/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func TestCreateVolume(t *testing.T) {

d := NewFakeDriver()

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

d := NewFakeDriver()

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

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(ctx, req)
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("Unexpected error: %v", err)
Expand Down Expand Up @@ -1290,7 +1290,7 @@ func TestCreateVolume(t *testing.T) {
mockStorageAccountsClient.EXPECT().Create(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
mockFileClient.EXPECT().GetFileShare(context.TODO(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(storage.FileShare{FileShareProperties: &storage.FileShareProperties{ShareQuota: &fakeShareQuota}}, nil).AnyTimes()

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(ctx, req)
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("Unexpected error: %v", err)
Expand Down Expand Up @@ -1625,7 +1625,7 @@ func TestDeleteVolume(t *testing.T) {
},
},
}
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1")
d.cloud = &azure.Cloud{}

Expand Down Expand Up @@ -2426,7 +2426,7 @@ func TestControllerExpandVolume(t *testing.T) {
ResourceGroup: "vol_2",
},
}
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(key string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache, _ = azcache.NewTimedCache(10*time.Minute, func(_ string) (interface{}, error) { return nil, nil }, false)
d.dataPlaneAPIAccountCache.Set("f5713de20cde511e8ba4900", "1")
ctrl := gomock.NewController(t)
defer ctrl.Finish()
Expand Down Expand Up @@ -2799,7 +2799,7 @@ func TestGenerateSASToken(t *testing.T) {
accountName: "unit-test",
accountKey: "fakeValue",
want: "",
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")),
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"),
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -2986,7 +2986,7 @@ func TestGetAzcopyAuth(t *testing.T) {

ctx := context.Background()
expectedAccountSASToken := ""
expectedErr := status.Errorf(codes.Internal, fmt.Sprintf("failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "accountName", "decode account key: illegal base64 data at input byte 8"))
expectedErr := status.Errorf(codes.Internal, "failed to generate sas token in creating new shared key credential, accountName: %s, err: %s", "accountName", "decode account key: illegal base64 data at input byte 8")
accountSASToken, authAzcopyEnv, err := d.getAzcopyAuth(ctx, "accountName", "", "core.windows.net", &azure.AccountOptions{}, secrets, "secretsName", "secretsNamespace", false)
if !reflect.DeepEqual(err, expectedErr) || authAzcopyEnv != nil || !reflect.DeepEqual(accountSASToken, expectedAccountSASToken) {
t.Errorf("Unexpected accountSASToken: %s, Unexpected authAzcopyEnv: %v, Unexpected error: %v", accountSASToken, authAzcopyEnv, err)
Expand Down
8 changes: 4 additions & 4 deletions pkg/azurefile/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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 @@ -237,7 +237,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 Down Expand Up @@ -472,7 +472,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 All @@ -494,7 +494,7 @@ func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeSta
}

if cache, err = d.volStatsCache.Get(newVolID, azcache.CacheReadTypeDefault); 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
Loading

0 comments on commit 8ab0074

Please sign in to comment.