From 728f85f512dadad24d7e6effdbd55f1ea55e1ed8 Mon Sep 17 00:00:00 2001 From: umagnus Date: Mon, 20 Nov 2023 02:41:31 +0000 Subject: [PATCH] upgrade golangci/golangci-lint-action to v1.54 --- .github/workflows/static.yaml | 2 +- .golangci.yml | 12 ++++++++++++ pkg/azurefileplugin/main.go | 2 +- pkg/csi-common/server_test.go | 6 +++--- pkg/mounter/safe_mounter_unix.go | 2 +- pkg/os/filesystem/filesystem.go | 2 +- pkg/util/util.go | 6 +++--- pkg/util/util_test.go | 3 +-- test/e2e/driver/azurefile_driver.go | 4 ++-- test/utils/azure/azure_helpers.go | 4 ++-- 10 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/static.yaml b/.github/workflows/static.yaml index dcb7c407e9..ff59ae1b9f 100644 --- a/.github/workflows/static.yaml +++ b/.github/workflows/static.yaml @@ -15,5 +15,5 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v3 with: - version: v1.51 + version: v1.54 args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..a7102ad339 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,12 @@ +linters-settings: + depguard: + rules: + main: + files: + - $all + - "!$test" + allow: + - $gostd + - k8s.io + - sigs.k8s.io + - github.com diff --git a/pkg/azurefileplugin/main.go b/pkg/azurefileplugin/main.go index 31aa0bfb2f..c262911ef0 100644 --- a/pkg/azurefileplugin/main.go +++ b/pkg/azurefileplugin/main.go @@ -131,7 +131,7 @@ func exportMetrics() { serve(context.Background(), l, serveMetrics) } -func serve(ctx context.Context, l net.Listener, serveFunc func(net.Listener) error) { +func serve(_ context.Context, l net.Listener, serveFunc func(net.Listener) error) { path := l.Addr().String() klog.V(2).Infof("set up prometheus server on %v", path) go func() { diff --git a/pkg/csi-common/server_test.go b/pkg/csi-common/server_test.go index aa1b2d0441..49f77d83e8 100644 --- a/pkg/csi-common/server_test.go +++ b/pkg/csi-common/server_test.go @@ -30,7 +30,7 @@ func TestNewNonBlockingGRPCServer(t *testing.T) { assert.NotNil(t, s) } -func TestStart(t *testing.T) { +func TestStart(_ *testing.T) { s := NewNonBlockingGRPCServer() // sleep a while to avoid race condition in unit test time.Sleep(time.Millisecond * 500) @@ -38,7 +38,7 @@ func TestStart(t *testing.T) { time.Sleep(time.Millisecond * 500) } -func TestServe(t *testing.T) { +func TestServe(_ *testing.T) { s := nonBlockingGRPCServer{} s.server = grpc.NewServer() s.wg = sync.WaitGroup{} @@ -47,7 +47,7 @@ func TestServe(t *testing.T) { s.serve("tcp://127.0.0.1:0", nil, nil, nil, true) } -func TestWait(t *testing.T) { +func TestWait(_ *testing.T) { s := nonBlockingGRPCServer{} s.server = grpc.NewServer() s.wg = sync.WaitGroup{} diff --git a/pkg/mounter/safe_mounter_unix.go b/pkg/mounter/safe_mounter_unix.go index 38b94b2a0c..36a386d806 100644 --- a/pkg/mounter/safe_mounter_unix.go +++ b/pkg/mounter/safe_mounter_unix.go @@ -24,7 +24,7 @@ import ( utilexec "k8s.io/utils/exec" ) -func NewSafeMounter(enableWindowsHostProcess bool) (*mount.SafeFormatAndMount, error) { +func NewSafeMounter(_ bool) (*mount.SafeFormatAndMount, error) { return &mount.SafeFormatAndMount{ Interface: mount.New(""), Exec: utilexec.New(), diff --git a/pkg/os/filesystem/filesystem.go b/pkg/os/filesystem/filesystem.go index 2cef6384bd..8a821369f0 100644 --- a/pkg/os/filesystem/filesystem.go +++ b/pkg/os/filesystem/filesystem.go @@ -80,7 +80,7 @@ func PathExists(path string) (bool, error) { return pathExists(path) } -func PathValid(ctx context.Context, path string) (bool, error) { +func PathValid(_ context.Context, path string) (bool, error) { cmd := `Test-Path $Env:remotepath` cmdEnv := fmt.Sprintf("remotepath=%s", path) output, err := util.RunPowershellCmd(cmd, cmdEnv) diff --git a/pkg/util/util.go b/pkg/util/util.go index 34936d8e8c..aaa4529779 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -126,7 +126,7 @@ func (ac *Azcopy) GetAzcopyJob(dstFileshare string) (AzcopyJobState, string, err klog.Warningf("failed to get azcopy job with error: %v, jobState: %v", err, AzcopyJobError) return AzcopyJobError, "", fmt.Errorf("couldn't list jobs in azcopy %v", err) } - jobid, jobState, err := parseAzcopyJobList(out, dstFileshare) + jobid, jobState, err := parseAzcopyJobList(out) if err != nil || jobState == AzcopyJobError { klog.Warningf("failed to get azcopy job with error: %v, jobState: %v", err, jobState) return AzcopyJobError, "", fmt.Errorf("couldn't parse azcopy job list in azcopy %v", err) @@ -153,8 +153,8 @@ func (ac *Azcopy) GetAzcopyJob(dstFileshare string) (AzcopyJobState, string, err return jobState, percent, nil } -// parseAzcopyJobList parse command azcopy jobs list, get jobid and state from joblist containing dstFileShareName -func parseAzcopyJobList(joblist string, dstFileShareName string) (string, AzcopyJobState, error) { +// parseAzcopyJobList parse command azcopy jobs list, get jobid and state from joblist +func parseAzcopyJobList(joblist string) (string, AzcopyJobState, error) { jobid := "" jobSegments := strings.Split(joblist, "JobId: ") if len(jobSegments) < 2 { diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index 56354f90f9..5d8af52686 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -222,8 +222,7 @@ func TestParseAzcopyJobList(t *testing.T) { } for _, test := range tests { - dstFileShare := "dstFileShare" - jobid, jobState, err := parseAzcopyJobList(test.str, dstFileShare) + jobid, jobState, err := parseAzcopyJobList(test.str) if jobid != test.expectedJobid || jobState != test.expectedJobState || !reflect.DeepEqual(err, test.expectedErr) { t.Errorf("test[%s]: unexpected jobid: %v, jobState: %v, err: %v, expected jobid: %v, jobState: %v, err: %v", test.desc, jobid, jobState, err, test.expectedJobid, test.expectedJobState, test.expectedErr) } diff --git a/test/e2e/driver/azurefile_driver.go b/test/e2e/driver/azurefile_driver.go index efc19103e1..6ad82aa422 100644 --- a/test/e2e/driver/azurefile_driver.go +++ b/test/e2e/driver/azurefile_driver.go @@ -58,13 +58,13 @@ func normalizeProvisioner(provisioner string) string { return strings.ToLower(strings.ReplaceAll(provisioner, "/", "-")) } -func (d *AzureFileDriver) GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass { +func (d *AzureFileDriver) GetDynamicProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, _ []string, namespace string) *storagev1.StorageClass { provisioner := d.driverName generateName := fmt.Sprintf("%s-%s-dynamic-sc-", namespace, normalizeProvisioner(provisioner)) return getStorageClass(generateName, provisioner, parameters, mountOptions, reclaimPolicy, bindingMode, nil) } -func (d *AzureFileDriver) GetPreProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, allowedTopologyValues []string, namespace string) *storagev1.StorageClass { +func (d *AzureFileDriver) GetPreProvisionStorageClass(parameters map[string]string, mountOptions []string, reclaimPolicy *v1.PersistentVolumeReclaimPolicy, bindingMode *storagev1.VolumeBindingMode, _ []string, namespace string) *storagev1.StorageClass { provisioner := d.driverName generateName := fmt.Sprintf("%s-%s-pre-provisioned-sc-", namespace, provisioner) return getStorageClass(generateName, provisioner, parameters, mountOptions, reclaimPolicy, bindingMode, nil) diff --git a/test/utils/azure/azure_helpers.go b/test/utils/azure/azure_helpers.go index cc1ab1fe5f..ebd6b395b2 100644 --- a/test/utils/azure/azure_helpers.go +++ b/test/utils/azure/azure_helpers.go @@ -72,7 +72,7 @@ func (az *Client) GetAzureFilesClient() (storage.FileSharesClient, error) { return az.filesharesClient, nil } -func (az *Client) EnsureSSHPublicKey(ctx context.Context, subscriptionID, resourceGroupName, location, keyName string) (publicKey string, err error) { +func (az *Client) EnsureSSHPublicKey(ctx context.Context, _, resourceGroupName, location, keyName string) (publicKey string, err error) { _, err = az.sshPublicKeysClient.Create(ctx, resourceGroupName, keyName, compute.SSHPublicKeyResource{Location: &location}) if err != nil { return "", err @@ -313,7 +313,7 @@ func getCloudConfig(env azure.Environment) cloud.Configuration { } } -func getClient(env azure.Environment, subscriptionID, tenantID string, cred *azidentity.ClientSecretCredential, scope string) *Client { +func getClient(env azure.Environment, subscriptionID, _ string, cred *azidentity.ClientSecretCredential, scope string) *Client { c := &Client{ environment: env, subscriptionID: subscriptionID,