Skip to content

Commit

Permalink
Merge pull request #2073 from umagnus/upgrade_golangci_1.54
Browse files Browse the repository at this point in the history
test: upgrade golangci/golangci-lint-action to v1.54
  • Loading branch information
k8s-ci-robot authored Nov 21, 2023
2 parents 880cb52 + e3bd289 commit 66d09eb
Show file tree
Hide file tree
Showing 24 changed files with 58 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .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.51
args: -E=gofmt,deadcode,unused,varcheck,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
version: v1.54
args: -E=gofmt,unused,ineffassign,revive,misspell,exportloopref,asciicheck,bodyclose,depguard,dogsled,durationcheck,errname,forbidigo -D=staticcheck --timeout=30m0s
13 changes: 13 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,16 @@ linters:
- structcheck
enable:
- golint

linters-settings:
depguard:
rules:
main:
files:
- $all
- "!$test"
allow:
- $gostd
- k8s.io
- sigs.k8s.io
- github.com
8 changes: 4 additions & 4 deletions pkg/azuredisk/azure_common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func getDiskLinkByDevName(io azureutils.IOHandler, devLinkPath, devName string)
return "", fmt.Errorf("read %s error: %v", devLinkPath, err)
}

func scsiHostRescan(io azureutils.IOHandler, m *mount.SafeFormatAndMount) {
func scsiHostRescan(io azureutils.IOHandler, _ *mount.SafeFormatAndMount) {
scsiPath := "/sys/class/scsi_host/"
if dirs, err := io.ReadDir(scsiPath); err == nil {
for _, f := range dirs {
Expand All @@ -96,7 +96,7 @@ func scsiHostRescan(io azureutils.IOHandler, m *mount.SafeFormatAndMount) {
}
}

func findDiskByLun(lun int, io azureutils.IOHandler, m *mount.SafeFormatAndMount) (string, error) {
func findDiskByLun(lun int, io azureutils.IOHandler, _ *mount.SafeFormatAndMount) (string, error) {
azureDisks := listAzureDiskPath(io)
return findDiskByLunWithConstraint(lun, io, azureDisks)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func findDiskByLunWithConstraint(lun int, io azureutils.IOHandler, azureDisks []
return "", err
}

func preparePublishPath(path string, m *mount.SafeFormatAndMount) error {
func preparePublishPath(_ string, _ *mount.SafeFormatAndMount) error {
return nil
}

Expand Down Expand Up @@ -269,7 +269,7 @@ func rescanAllVolumes(io azureutils.IOHandler) error {
return nil
}

func GetVolumeStats(ctx context.Context, m *mount.SafeFormatAndMount, target string, hostutil hostUtil) ([]*csi.VolumeUsage, error) {
func GetVolumeStats(_ context.Context, m *mount.SafeFormatAndMount, target string, hostutil hostUtil) ([]*csi.VolumeUsage, error) {
var volUsages []*csi.VolumeUsage
_, err := os.Stat(target)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions pkg/azuredisk/azuredisk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func TestWaitForSnapshot(t *testing.T) {
}
},
},
//nolint:dupl
{
name: "timeout for waiting snapshot copy cross region",
testFunc: func(t *testing.T) {
Expand Down Expand Up @@ -336,6 +337,7 @@ func TestWaitForSnapshot(t *testing.T) {
}
},
},
//nolint:dupl
{
name: "succeed for waiting snapshot copy cross region",
testFunc: func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,14 @@ 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, "")
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/azuredisk/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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")
}
Expand All @@ -47,12 +47,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) {
capabilities := []*csi.PluginCapability{
{
Type: &csi.PluginCapability_Service_{
Expand Down
14 changes: 7 additions & 7 deletions pkg/azuredisk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func getDefaultFsType() string {
}

// NodeStageVolume mount disk device to a staging path
func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
func (d *Driver) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
diskURI := req.GetVolumeId()
if len(diskURI) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
Expand Down Expand Up @@ -182,7 +182,7 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
}

// NodeUnstageVolume unmount disk device from a 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 not provided")
Expand All @@ -209,7 +209,7 @@ func (d *Driver) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstageVolu
}

// NodePublishVolume mount the volume from staging to target path
func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
func (d *Driver) NodePublishVolume(_ context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in the request")
Expand Down Expand Up @@ -287,7 +287,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) {
targetPath := req.GetTargetPath()
volumeID := req.GetVolumeId()

Expand All @@ -310,14 +310,14 @@ func (d *Driver) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublish
}

// 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(ctx context.Context, _ *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
topology := &csi.Topology{
Segments: map[string]string{topologyKey: ""},
}
Expand Down Expand Up @@ -451,7 +451,7 @@ func (d *Driver) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVolumeS
}

// NodeExpandVolume node expand volume
func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
func (d *Driver) NodeExpandVolume(_ context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
volumeID := req.GetVolumeId()
if len(volumeID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume ID not provided")
Expand Down
2 changes: 1 addition & 1 deletion pkg/azurediskplugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,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() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/azureutils/fake_iohandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ func (handler *fakeIOHandler) ReadDir(dirname string) ([]os.DirEntry, error) {
return nil, fmt.Errorf("bad dir")
}

func (handler *fakeIOHandler) WriteFile(filename string, data []byte, perm os.FileMode) error {
func (handler *fakeIOHandler) WriteFile(_ string, _ []byte, _ os.FileMode) error {
return nil
}

func (handler *fakeIOHandler) Readlink(name string) (string, error) {
func (handler *fakeIOHandler) Readlink(_ string) (string, error) {
return "/dev/azure/disk/sda", nil
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/csi-common/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ 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)
s.Start("tcp://127.0.0.1:0", nil, nil, nil, true, false)
time.Sleep(time.Millisecond * 500)
}

func TestStartWithOtelTracing(t *testing.T) {
func TestStartWithOtelTracing(_ *testing.T) {
s := NewNonBlockingGRPCServer()
// sleep a while to avoid race condition in unit test
time.Sleep(time.Millisecond * 500)
s.Start("tcp://127.0.0.1:0", nil, nil, nil, true, true)
time.Sleep(time.Millisecond * 500)
}

func TestServe(t *testing.T) {
func TestServe(_ *testing.T) {
s := nonBlockingGRPCServer{}
s.server = grpc.NewServer()
s.wg = sync.WaitGroup{}
Expand All @@ -55,20 +55,20 @@ func TestServe(t *testing.T) {
s.serve("tcp://127.0.0.1:0", nil, nil, nil, true, false)
}

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()
Expand Down
4 changes: 2 additions & 2 deletions pkg/mounter/fake_safe_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewFakeSafeMounter() (*mount.SafeFormatAndMount, error) {
}

// Mount overrides mount.FakeMounter.Mount.
func (f *FakeSafeMounter) Mount(source, target, fstype string, options []string) error {
func (f *FakeSafeMounter) Mount(source, target, _ string, _ []string) error {
if strings.Contains(source, "error_mount") {
return fmt.Errorf("fake Mount: source error")
} else if strings.Contains(target, "error_mount") {
Expand All @@ -59,7 +59,7 @@ func (f *FakeSafeMounter) Mount(source, target, fstype string, options []string)
}

// MountSensitive overrides mount.FakeMounter.MountSensitive.
func (f *FakeSafeMounter) MountSensitive(source, target, fstype string, options, sensitiveOptions []string) error {
func (f *FakeSafeMounter) MountSensitive(source, target, _ 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") {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mounter/safe_mounter_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
utilexec "k8s.io/utils/exec"
)

func NewSafeMounter(enableWindowsHostProcess, useCSIProxyGAInterface bool) (*mount.SafeFormatAndMount, error) {
func NewSafeMounter(_, _ bool) (*mount.SafeFormatAndMount, error) {
return &mount.SafeFormatAndMount{
Interface: mount.New(""),
Exec: utilexec.New(),
Expand Down
1 change: 1 addition & 0 deletions pkg/optimization/azure_skus_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

package optimization

//nolint:dupl
var (
DiskSkuMap = map[string]map[string]DiskSkuInfo{
"premium_lrs": {
Expand Down
2 changes: 1 addition & 1 deletion pkg/optimization/skus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type fakeCloud struct {
fakecloud.Cloud
}

func (fake *fakeCloud) InstanceType(ctx context.Context, nodeName types.NodeName) (string, error) {
func (fake *fakeCloud) InstanceType(_ context.Context, nodeName types.NodeName) (string, error) {
if instanceType, ok := fake.InstanceTypes[nodeName]; ok {
return instanceType, nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/os/filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
output, err := util.RunPowershellCmd(cmd, fmt.Sprintf("remotepath=%s", path))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/dynamic_provisioning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
test.Run(ctx, cs, snapshotrcs, ns)
})

//nolint:dupl
ginkgo.It("should create a pod with small storage size, take a volume snapshot cross region, and restore disk in another region [disk.csi.azure.com]", func(ctx ginkgo.SpecContext) {
skipIfUsingInTreeVolumePlugin()
skipIfTestingInWindowsCluster()
Expand Down Expand Up @@ -856,6 +857,7 @@ func (t *dynamicProvisioningTestSuite) defineTests(isMultiZone bool) {
test.Run(ctx, cs, snapshotrcs, ns)
})

//nolint:dupl
ginkgo.It("should create a pod with large storage size, take a volume snapshot cross region, and restore disk in another region [disk.csi.azure.com]", func(ctx ginkgo.SpecContext) {
skipIfUsingInTreeVolumePlugin()
skipIfTestingInWindowsCluster()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type PodExecCheck struct {
ExpectedString string
}

//nolint:dupl
func (t *DynamicallyProvisionedDeletePodTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
tDeployment, cleanup := t.Pod.SetupDeployment(ctx, client, namespace, t.CSIDriver, driver.GetParameters())
// defer must be called here for resources not get removed before using them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:dupl
package testsuites

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:dupl
package testsuites

import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type DynamicallyProvisionedStatefulSetTest struct {
PodCheck *PodExecCheck
}

//nolint:dupl
func (t *DynamicallyProvisionedStatefulSetTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
tStatefulSet, cleanup := t.Pod.SetupStatefulset(ctx, client, namespace, t.CSIDriver, driver.GetParameters())
// defer must be called here for resources not get removed before using them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type PreProvisionedInlineVolumeTest struct {

func (t *PreProvisionedInlineVolumeTest) Run(ctx context.Context, client clientset.Interface, namespace *v1.Namespace) {
for _, pod := range t.Pods {
tpod, cleanup := pod.SetupWithInlineVolumes(client, namespace, t.CSIDriver, t.DiskURI, t.ReadOnly)
tpod, cleanup := pod.SetupWithInlineVolumes(client, namespace, t.DiskURI, t.ReadOnly)
// defer must be called here for resources not get removed before using them
for i := range cleanup {
defer cleanup[i](ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:dupl
package testsuites

import (
Expand Down
1 change: 1 addition & 0 deletions test/e2e/testsuites/pre_provisioned_shared_disk_tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

//nolint:dupl
package testsuites

import (
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/testsuites/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (pod *PodDetails) SetupWithDynamicVolumesWithSubpath(ctx context.Context, c
return tpod, cleanupFuncs
}

func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.PreProvisionedVolumeTestDriver, diskURI string, readOnly bool) (*TestPod, []func(context.Context)) {
func (pod *PodDetails) SetupWithInlineVolumes(client clientset.Interface, namespace *v1.Namespace, diskURI string, readOnly bool) (*TestPod, []func(context.Context)) {
tpod := NewTestPod(client, namespace, pod.Cmd, pod.IsWindows, pod.WinServerVer)
cleanupFuncs := make([]func(context.Context), 0)
for n, v := range pod.Volumes {
Expand Down

0 comments on commit 66d09eb

Please sign in to comment.