From ef565c7619933dabba877fc17c5b720740a36fce Mon Sep 17 00:00:00 2001 From: umagnus Date: Mon, 20 Nov 2023 02:41:31 +0000 Subject: [PATCH 1/2] upgrade golangci/golangci-lint-action to v1.54 --- .github/workflows/static.yaml | 4 ++-- .golangci.yml | 12 ++++++++++++ pkg/azurefile/azure_common_linux.go | 8 ++++---- pkg/azurefile/azurefile.go | 2 +- pkg/azurefile/controllerserver.go | 8 ++++---- pkg/azurefile/fake_mounter.go | 4 ++-- pkg/azurefile/identityserver.go | 6 +++--- pkg/azurefile/nodeserver.go | 12 ++++++------ pkg/azurefile/utils.go | 4 ++-- pkg/azurefile/utils_test.go | 2 +- pkg/azurefileplugin/main.go | 2 +- pkg/csi-common/server_test.go | 10 +++++----- 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/e2e/testsuites/specs.go | 4 ++-- test/utils/azure/azure_helpers.go | 4 ++-- 19 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 .golangci.yml diff --git a/.github/workflows/static.yaml b/.github/workflows/static.yaml index dcb7c407e9..3ea84162d1 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 - args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,dupl,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s + version: v1.54 + args: -E=gofmt,unused,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/azurefile/azure_common_linux.go b/pkg/azurefile/azure_common_linux.go index cfbdf5704c..43be1a3999 100644 --- a/pkg/azurefile/azure_common_linux.go +++ b/pkg/azurefile/azure_common_linux.go @@ -33,20 +33,20 @@ func SMBMount(m *mount.SafeFormatAndMount, source, target, fsType string, option return m.MountSensitive(source, target, fsType, options, sensitiveMountOptions) } -func CleanupMountPoint(m *mount.SafeFormatAndMount, target string, extensiveMountCheck bool) error { +func CleanupMountPoint(m *mount.SafeFormatAndMount, target string, _ bool) error { return mount.CleanupMountPoint(target, m.Interface, true /*extensiveMountPointCheck*/) } -func preparePublishPath(path string, m *mount.SafeFormatAndMount) error { +func preparePublishPath(_ string, _ *mount.SafeFormatAndMount) error { return nil } -func prepareStagePath(path string, m *mount.SafeFormatAndMount) error { +func prepareStagePath(_ string, _ *mount.SafeFormatAndMount) error { return nil } // GetVolumeStats returns volume stats based on the given path. -func GetVolumeStats(path string, enableWindowsHostProcess bool) (*csi.NodeGetVolumeStatsResponse, error) { +func GetVolumeStats(path string, _ bool) (*csi.NodeGetVolumeStatsResponse, error) { volumeMetrics, err := volume.NewMetricsStatFS(path).GetMetrics() if err != nil { return nil, status.Errorf(codes.Internal, "failed to get metrics: %v", err) diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index a8d0d141e3..b258807d69 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -904,7 +904,7 @@ func (d *Driver) ResizeFileShare(ctx context.Context, subsID, resourceGroup, acc } // CopyFileShare copies a fileshare in the same storage account -func (d *Driver) copyFileShare(ctx context.Context, req *csi.CreateVolumeRequest, accountKey string, shareOptions *fileclient.ShareOptions, storageEndpointSuffix string) error { +func (d *Driver) copyFileShare(_ context.Context, req *csi.CreateVolumeRequest, accountKey string, shareOptions *fileclient.ShareOptions, storageEndpointSuffix string) error { if shareOptions.Protocol == storage.EnabledProtocolsNFS { return fmt.Errorf("protocol nfs is not supported for volume cloning") } diff --git a/pkg/azurefile/controllerserver.go b/pkg/azurefile/controllerserver.go index 2eb251eed9..907364450b 100644 --- a/pkg/azurefile/controllerserver.go +++ b/pkg/azurefile/controllerserver.go @@ -783,19 +783,19 @@ func (d *Driver) ValidateVolumeCapabilities(ctx context.Context, req *csi.Valida } // ControllerGetCapabilities returns the capabilities of the Controller plugin -func (d *Driver) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { +func (d *Driver) ControllerGetCapabilities(_ context.Context, _ *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) { return &csi.ControllerGetCapabilitiesResponse{ Capabilities: d.Cap, }, nil } // GetCapacity returns the capacity of the total available storage pool -func (d *Driver) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { +func (d *Driver) GetCapacity(_ context.Context, _ *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) { return nil, status.Error(codes.Unimplemented, "") } // ListVolumes return all available volumes -func (d *Driver) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { +func (d *Driver) ListVolumes(_ context.Context, _ *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) { return nil, status.Error(codes.Unimplemented, "") } @@ -1083,7 +1083,7 @@ func (d *Driver) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequ } // ListSnapshots list all snapshots (todo) -func (d *Driver) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { +func (d *Driver) ListSnapshots(_ context.Context, _ *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) { return nil, status.Error(codes.Unimplemented, "") } diff --git a/pkg/azurefile/fake_mounter.go b/pkg/azurefile/fake_mounter.go index 730ae87022..1e076eb262 100644 --- a/pkg/azurefile/fake_mounter.go +++ b/pkg/azurefile/fake_mounter.go @@ -30,7 +30,7 @@ type fakeMounter struct { } // Mount overrides mount.FakeMounter.Mount. -func (f *fakeMounter) Mount(source string, target string, fstype string, options []string) error { +func (f *fakeMounter) Mount(source string, target string, _ string, _ []string) error { if strings.Contains(source, "error_mount") { return fmt.Errorf("fake Mount: source error") } else if strings.Contains(target, "error_mount") { @@ -41,7 +41,7 @@ func (f *fakeMounter) Mount(source string, target string, fstype string, options } // MountSensitive overrides mount.FakeMounter.MountSensitive. -func (f *fakeMounter) MountSensitive(source string, target string, fstype string, options []string, sensitiveOptions []string) error { +func (f *fakeMounter) MountSensitive(source string, target string, _ string, _ []string, _ []string) error { if strings.Contains(source, "error_mount_sens") { return fmt.Errorf("fake MountSensitive: source error") } else if strings.Contains(target, "error_mount_sens") { diff --git a/pkg/azurefile/identityserver.go b/pkg/azurefile/identityserver.go index 01acd61a9c..c503dacb1d 100644 --- a/pkg/azurefile/identityserver.go +++ b/pkg/azurefile/identityserver.go @@ -27,7 +27,7 @@ import ( ) // GetPluginInfo return the version and name of the plugin -func (f *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) { +func (f *Driver) GetPluginInfo(_ context.Context, _ *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) { if f.Name == "" { return nil, status.Error(codes.Unavailable, "Driver name not configured") } @@ -46,12 +46,12 @@ func (f *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoReques // This method does not need to return anything. // Currently the spec does not dictate what you should return either. // Hence, return an empty response -func (f *Driver) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) { +func (f *Driver) Probe(_ context.Context, _ *csi.ProbeRequest) (*csi.ProbeResponse, error) { return &csi.ProbeResponse{Ready: &wrappers.BoolValue{Value: true}}, nil } // GetPluginCapabilities returns the capabilities of the plugin -func (f *Driver) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) { +func (f *Driver) GetPluginCapabilities(_ context.Context, _ *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) { return &csi.GetPluginCapabilitiesResponse{ Capabilities: []*csi.PluginCapability{ { diff --git a/pkg/azurefile/nodeserver.go b/pkg/azurefile/nodeserver.go index 38a175aad5..fad80f0f8c 100644 --- a/pkg/azurefile/nodeserver.go +++ b/pkg/azurefile/nodeserver.go @@ -120,7 +120,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu } // NodeUnpublishVolume unmount the volume from the target path -func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { +func (d *Driver) NodeUnpublishVolume(_ context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { if len(req.GetVolumeId()) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") } @@ -382,7 +382,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe } // NodeUnstageVolume unmount the volume from the staging path -func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) { +func (d *Driver) NodeUnstageVolume(_ context.Context, req *csi.NodeUnstageVolumeRequest) (*csi.NodeUnstageVolumeResponse, error) { volumeID := req.GetVolumeId() if len(volumeID) == 0 { return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request") @@ -420,21 +420,21 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu } // NodeGetCapabilities return the capabilities of the Node plugin -func (d *Driver) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) { +func (d *Driver) NodeGetCapabilities(_ context.Context, _ *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) { return &csi.NodeGetCapabilitiesResponse{ Capabilities: d.NSCap, }, nil } // NodeGetInfo return info of the node on which this plugin is running -func (d *Driver) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) { +func (d *Driver) NodeGetInfo(_ context.Context, _ *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) { return &csi.NodeGetInfoResponse{ NodeId: d.NodeID, }, nil } // NodeGetVolumeStats get volume stats -func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) { +func (d *Driver) NodeGetVolumeStats(_ context.Context, req *csi.NodeGetVolumeStatsRequest) (*csi.NodeGetVolumeStatsResponse, error) { if len(req.VolumeId) == 0 { return nil, status.Error(codes.InvalidArgument, "NodeGetVolumeStats volume ID was empty") } @@ -513,7 +513,7 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS // NodeExpandVolume node expand volume // N/A for azure file -func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) { +func (d *Driver) NodeExpandVolume(_ context.Context, _ *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) { return nil, status.Error(codes.Unimplemented, "") } diff --git a/pkg/azurefile/utils.go b/pkg/azurefile/utils.go index abad8259c6..65ba279624 100644 --- a/pkg/azurefile/utils.go +++ b/pkg/azurefile/utils.go @@ -197,11 +197,11 @@ func (l *VolumeMounter) CanMount() error { return nil } -func (l *VolumeMounter) SetUp(mounterArgs volume.MounterArgs) error { +func (l *VolumeMounter) SetUp(_ volume.MounterArgs) error { return nil } -func (l *VolumeMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) error { +func (l *VolumeMounter) SetUpAt(_ string, _ volume.MounterArgs) error { return nil } diff --git a/pkg/azurefile/utils_test.go b/pkg/azurefile/utils_test.go index 7d24ab9d28..2db9be1590 100644 --- a/pkg/azurefile/utils_test.go +++ b/pkg/azurefile/utils_test.go @@ -62,7 +62,7 @@ func TestConcurrentLockEntry(t *testing.T) { testLockMap.UnlockEntry("entry1") } -func (lm *lockMap) lockAndCallback(t *testing.T, entry string, callbackChan chan<- interface{}) { +func (lm *lockMap) lockAndCallback(_ *testing.T, entry string, callbackChan chan<- interface{}) { lm.LockEntry(entry) callbackChan <- true } 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..18e07712c4 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,20 +47,20 @@ 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{} s.Wait() } -func TestStop(t *testing.T) { +func TestStop(_ *testing.T) { s := nonBlockingGRPCServer{} s.server = grpc.NewServer() s.Stop() } -func TestForceStop(t *testing.T) { +func TestForceStop(_ *testing.T) { s := nonBlockingGRPCServer{} s.server = grpc.NewServer() s.ForceStop() 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/e2e/testsuites/specs.go b/test/e2e/testsuites/specs.go index 26cb0ccbdc..1e4faa2569 100644 --- a/test/e2e/testsuites/specs.go +++ b/test/e2e/testsuites/specs.go @@ -141,7 +141,7 @@ func (pod *PodDetails) SetupWithDynamicVolumesWithSubpath(ctx context.Context, c return tpod, cleanupFuncs } -func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, secretName, shareName string, readOnly bool) (*TestPod, []func()) { +func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, _ driver.DynamicPVTestDriver, secretName, shareName string, readOnly bool) (*TestPod, []func()) { tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer) cleanupFuncs := make([]func(), 0) for n, v := range pod.Volumes { @@ -150,7 +150,7 @@ func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namesp return tpod, cleanupFuncs } -func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, secretName, shareName, server string, readOnly bool) (*TestPod, []func()) { +func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, _ driver.DynamicPVTestDriver, secretName, shareName, server string, readOnly bool) (*TestPod, []func()) { tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer) cleanupFuncs := make([]func(), 0) for n, v := range pod.Volumes { 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, From d341a0590e5d83acc0c8945a9b87edf1f391eaa4 Mon Sep 17 00:00:00 2001 From: umagnus Date: Mon, 20 Nov 2023 06:31:45 +0000 Subject: [PATCH 2/2] clean up parm in func --- pkg/azurefile/azurefile.go | 4 ++-- pkg/azurefile/controllerserver.go | 7 +++--- pkg/azurefile/controllerserver_test.go | 23 ++++++------------- .../dynamically_provisioned_inline_volume.go | 4 ++-- test/e2e/testsuites/specs.go | 4 ++-- test/utils/azure/azure_helpers.go | 8 +++---- 6 files changed, 21 insertions(+), 29 deletions(-) diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index b258807d69..ef7370c891 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -903,8 +903,8 @@ func (d *Driver) ResizeFileShare(ctx context.Context, subsID, resourceGroup, acc }) } -// CopyFileShare copies a fileshare in the same storage account -func (d *Driver) copyFileShare(_ context.Context, req *csi.CreateVolumeRequest, accountKey string, shareOptions *fileclient.ShareOptions, storageEndpointSuffix string) error { +// copyFileShare copies a fileshare in the same storage account +func (d *Driver) copyFileShare(req *csi.CreateVolumeRequest, accountKey string, shareOptions *fileclient.ShareOptions, storageEndpointSuffix string) error { if shareOptions.Protocol == storage.EnabledProtocolsNFS { return fmt.Errorf("protocol nfs is not supported for volume cloning") } diff --git a/pkg/azurefile/controllerserver.go b/pkg/azurefile/controllerserver.go index 907364450b..b375d33cc3 100644 --- a/pkg/azurefile/controllerserver.go +++ b/pkg/azurefile/controllerserver.go @@ -575,7 +575,7 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) if err != nil { return nil, status.Errorf(codes.Internal, "failed to GetStorageAccesskey on account(%s) rg(%s), error: %v", accountOptions.Name, accountOptions.ResourceGroup, err) } - if err := d.copyVolume(ctx, req, accountKeyCopy, shareOptions, storageEndpointSuffix); err != nil { + if err := d.copyVolume(req, accountKeyCopy, shareOptions, storageEndpointSuffix); err != nil { return nil, err } // storeAccountKey is not needed here since copy volume is only using SAS token @@ -725,13 +725,14 @@ func (d *Driver) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) return &csi.DeleteVolumeResponse{}, nil } -func (d *Driver) copyVolume(ctx context.Context, req *csi.CreateVolumeRequest, accountKey string, shareOptions *fileclient.ShareOptions, storageEndpointSuffix string) error { +// copyVolume copy an azure file +func (d *Driver) copyVolume(req *csi.CreateVolumeRequest, accountKey string, shareOptions *fileclient.ShareOptions, storageEndpointSuffix string) error { vs := req.VolumeContentSource switch vs.Type.(type) { case *csi.VolumeContentSource_Snapshot: return status.Errorf(codes.InvalidArgument, "copy volume from volumeSnapshot is not supported") case *csi.VolumeContentSource_Volume: - return d.copyFileShare(ctx, req, accountKey, shareOptions, storageEndpointSuffix) + return d.copyFileShare(req, accountKey, shareOptions, storageEndpointSuffix) default: return status.Errorf(codes.InvalidArgument, "%v is not a proper volume source", vs) } diff --git a/pkg/azurefile/controllerserver_test.go b/pkg/azurefile/controllerserver_test.go index b85da4364f..943e92a46b 100644 --- a/pkg/azurefile/controllerserver_test.go +++ b/pkg/azurefile/controllerserver_test.go @@ -1646,10 +1646,9 @@ func TestCopyVolume(t *testing.T) { } d := NewFakeDriver() - ctx := context.Background() expectedErr := status.Errorf(codes.InvalidArgument, "copy volume from volumeSnapshot is not supported") - err := d.copyVolume(ctx, req, "", nil, "core.windows.net") + err := d.copyVolume(req, "", nil, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } @@ -1679,10 +1678,9 @@ func TestCopyVolume(t *testing.T) { } d := NewFakeDriver() - ctx := context.Background() expectedErr := fmt.Errorf("protocol nfs is not supported for volume cloning") - err := d.copyVolume(ctx, req, "", &fileclient.ShareOptions{Protocol: storage.EnabledProtocolsNFS}, "core.windows.net") + err := d.copyVolume(req, "", &fileclient.ShareOptions{Protocol: storage.EnabledProtocolsNFS}, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } @@ -1712,10 +1710,9 @@ func TestCopyVolume(t *testing.T) { } d := NewFakeDriver() - ctx := context.Background() expectedErr := status.Errorf(codes.NotFound, "error parsing volume id: \"unit-test\", should at least contain two #") - err := d.copyVolume(ctx, req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") + err := d.copyVolume(req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } @@ -1745,10 +1742,9 @@ func TestCopyVolume(t *testing.T) { } d := NewFakeDriver() - ctx := context.Background() expectedErr := fmt.Errorf("srcFileShareName() or dstFileShareName(dstFileshare) is empty") - err := d.copyVolume(ctx, req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") + err := d.copyVolume(req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } @@ -1778,10 +1774,9 @@ func TestCopyVolume(t *testing.T) { } d := NewFakeDriver() - ctx := context.Background() expectedErr := fmt.Errorf("srcFileShareName(fileshare) or dstFileShareName() is empty") - err := d.copyVolume(ctx, req, "", &fileclient.ShareOptions{}, "core.windows.net") + err := d.copyVolume(req, "", &fileclient.ShareOptions{}, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } @@ -1822,10 +1817,8 @@ func TestCopyVolume(t *testing.T) { d.azcopy.ExecCmd = m - ctx := context.Background() - var expectedErr error - err := d.copyVolume(ctx, req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") + err := d.copyVolume(req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } @@ -1867,10 +1860,8 @@ func TestCopyVolume(t *testing.T) { d.azcopy.ExecCmd = m - ctx := context.Background() - var expectedErr error - err := d.copyVolume(ctx, req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") + err := d.copyVolume(req, "", &fileclient.ShareOptions{Name: "dstFileshare"}, "core.windows.net") if !reflect.DeepEqual(err, expectedErr) { t.Errorf("Unexpected error: %v", err) } diff --git a/test/e2e/testsuites/dynamically_provisioned_inline_volume.go b/test/e2e/testsuites/dynamically_provisioned_inline_volume.go index 30d8892697..7ade920e28 100644 --- a/test/e2e/testsuites/dynamically_provisioned_inline_volume.go +++ b/test/e2e/testsuites/dynamically_provisioned_inline_volume.go @@ -44,9 +44,9 @@ func (t *DynamicallyProvisionedInlineVolumeTest) Run(ctx context.Context, client var tpod *TestPod var cleanup []func() if t.CSIInlineVolume { - tpod, cleanup = pod.SetupWithCSIInlineVolumes(client, namespace, t.CSIDriver, t.SecretName, t.ShareName, t.Server, t.ReadOnly) + tpod, cleanup = pod.SetupWithCSIInlineVolumes(client, namespace, t.SecretName, t.ShareName, t.Server, t.ReadOnly) } else { - tpod, cleanup = pod.SetupWithInlineVolumes(client, namespace, t.CSIDriver, t.SecretName, t.ShareName, t.ReadOnly) + tpod, cleanup = pod.SetupWithInlineVolumes(client, namespace, t.SecretName, t.ShareName, t.ReadOnly) } // defer must be called here for resources not get removed before using them diff --git a/test/e2e/testsuites/specs.go b/test/e2e/testsuites/specs.go index 1e4faa2569..67023cb974 100644 --- a/test/e2e/testsuites/specs.go +++ b/test/e2e/testsuites/specs.go @@ -141,7 +141,7 @@ func (pod *PodDetails) SetupWithDynamicVolumesWithSubpath(ctx context.Context, c return tpod, cleanupFuncs } -func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, _ driver.DynamicPVTestDriver, secretName, shareName string, readOnly bool) (*TestPod, []func()) { +func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, secretName, shareName string, readOnly bool) (*TestPod, []func()) { tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer) cleanupFuncs := make([]func(), 0) for n, v := range pod.Volumes { @@ -150,7 +150,7 @@ func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namesp return tpod, cleanupFuncs } -func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, _ driver.DynamicPVTestDriver, secretName, shareName, server string, readOnly bool) (*TestPod, []func()) { +func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, secretName, shareName, server string, readOnly bool) (*TestPod, []func()) { tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer) cleanupFuncs := make([]func(), 0) for n, v := range pod.Volumes { diff --git a/test/utils/azure/azure_helpers.go b/test/utils/azure/azure_helpers.go index ebd6b395b2..919c815ea4 100644 --- a/test/utils/azure/azure_helpers.go +++ b/test/utils/azure/azure_helpers.go @@ -65,14 +65,14 @@ func GetAzureClient(cloud, subscriptionID, clientID, tenantID, clientSecret stri return nil, err } - return getClient(env, subscriptionID, tenantID, cred, env.TokenAudience), nil + return getClient(env, subscriptionID, cred, env.TokenAudience), nil } func (az *Client) GetAzureFilesClient() (storage.FileSharesClient, error) { return az.filesharesClient, nil } -func (az *Client) EnsureSSHPublicKey(ctx context.Context, _, 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 @@ -135,7 +135,7 @@ func (az *Client) EnsureVirtualMachine(ctx context.Context, groupName, location, return vm, err } - publicKey, err := az.EnsureSSHPublicKey(ctx, az.subscriptionID, groupName, location, "test-key") + publicKey, err := az.EnsureSSHPublicKey(ctx, groupName, location, "test-key") if err != nil { return vm, err } @@ -313,7 +313,7 @@ func getCloudConfig(env azure.Environment) cloud.Configuration { } } -func getClient(env azure.Environment, subscriptionID, _ 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,