From 2c61627f8ccf72e37bbdc3c2f10344d71d45c8bd Mon Sep 17 00:00:00 2001 From: Mark Janssen Date: Sat, 24 Aug 2019 21:55:16 +0200 Subject: [PATCH] Fix staticcheck failures for pkg/volume/... Errors from staticcheck: pkg/volume/azure_dd/azure_common.go:68:2: var winDiskNumFormat is unused (U1000) pkg/volume/csi/csi_block.go:97:2: field volumeInfo is unused (U1000) pkg/volume/csi/csi_block_test.go:56:6: func prepareBlockUnmapperTest is unused (U1000) pkg/volume/csi/csi_client.go:108:2: const initialDuration is unused (U1000) pkg/volume/csi/csi_client.go:109:2: const factor is unused (U1000) pkg/volume/csi/csi_client.go:110:2: const steps is unused (U1000) pkg/volume/csi/csi_client_test.go:83:8: this value of err is never used (SA4006) pkg/volume/csi/csi_mounter.go:76:2: field options is unused (U1000) pkg/volume/csi/csi_mounter_test.go:454:13: this value of err is never used (SA4006) pkg/volume/csi/csi_plugin_test.go:766:16: this value of err is never used (SA4006) pkg/volume/csi/csi_plugin_test.go:861:13: this value of err is never used (SA4006) pkg/volume/csi/csi_plugin_test.go:1186:13: this value of err is never used (SA4006) pkg/volume/csi/csi_plugin_test.go:1249:13: this value of err is never used (SA4006) pkg/volume/csi/csi_test.go:305:5: the goroutine calls T.Fatalf, which must be called in the same goroutine as the test (SA2002) pkg/volume/flexvolume/probe_test.go:67:10: this value of err is never used (SA4006) pkg/volume/iscsi/iscsi_test.go:95:2: field attachCalled is unused (U1000) pkg/volume/iscsi/iscsi_test.go:96:2: field detachCalled is unused (U1000) pkg/volume/iscsi/iscsi_test.go:501:24: this value of err is never used (SA4006) pkg/volume/iscsi/iscsi_util_test.go:159:2: this value of exist is never used (SA4006) pkg/volume/local/local.go:351:57: argument devicePath is overwritten before first use (SA4009) pkg/volume/plugins_test.go:119:2: this value of plug is never used (SA4006) pkg/volume/plugins_test.go:125:2: this value of plug is never used (SA4006) pkg/volume/quobyte/quobyte.go:474:23: this result of append is never used, except maybe in other appends (SA4010) pkg/volume/quobyte/quobyte.go:477:23: this result of append is never used, except maybe in other appends (SA4010) pkg/volume/quobyte/quobyte.go:480:23: this result of append is never used, except maybe in other appends (SA4010) pkg/volume/rbd/rbd.go:886:2: field adminSecret is unused (U1000) pkg/volume/rbd/rbd.go:887:2: field adminID is unused (U1000) pkg/volume/rbd/rbd.go:888:2: field imageFormat is unused (U1000) pkg/volume/rbd/rbd.go:889:2: field imageFeatures is unused (U1000) pkg/volume/storageos/storageos.go:302:2: field secretName is unused (U1000) pkg/volume/storageos/storageos_util_test.go:43:2: field apiAddr is unused (U1000) pkg/volume/storageos/storageos_util_test.go:44:2: field apiUser is unused (U1000) pkg/volume/storageos/storageos_util_test.go:45:2: field apiPass is unused (U1000) pkg/volume/storageos/storageos_util_test.go:46:2: field apiVersion is unused (U1000) pkg/volume/util/atomic_writer_test.go:756:49: argument err is overwritten before first use (SA4009) pkg/volume/util/fsquota/common/quota_linux_common.go:37:2: const acct is unused (U1000) pkg/volume/util/fsquota/common/quota_linux_common.go:38:2: const enforcing is unused (U1000) pkg/volume/util/fsquota/project.go:168:31: identical expressions on the left and right side of the '==' operator (SA4000) pkg/volume/util/fsquota/quota_linux.go:306:50: argument poduid is overwritten before first use (SA4009) pkg/volume/util/fsquota/quota_linux_test.go:558:16: this value of err is never used (SA4006) pkg/volume/util/subpath/subpath_linux.go:232:81: argument err is overwritten before first use (SA4009) pkg/volume/util/subpath/subpath_linux_test.go:579:73: argument err is overwritten before first use (SA4009) --- hack/.staticcheck_failures | 13 ------- pkg/volume/azure_dd/azure_common.go | 3 +- pkg/volume/azure_dd/azure_common_windows.go | 2 ++ pkg/volume/csi/csi_block.go | 1 - pkg/volume/csi/csi_block_test.go | 34 ------------------- pkg/volume/csi/csi_client.go | 7 ---- pkg/volume/csi/csi_client_test.go | 3 ++ pkg/volume/csi/csi_mounter.go | 1 - pkg/volume/csi/csi_mounter_test.go | 4 +-- pkg/volume/csi/csi_plugin_test.go | 10 +++--- pkg/volume/csi/csi_test.go | 3 +- pkg/volume/flexvolume/probe_test.go | 1 + pkg/volume/iscsi/iscsi_test.go | 8 ++--- pkg/volume/iscsi/iscsi_util_test.go | 2 +- pkg/volume/local/local.go | 3 +- pkg/volume/plugins_test.go | 4 +-- pkg/volume/quobyte/quobyte.go | 5 --- pkg/volume/rbd/rbd.go | 12 +++---- pkg/volume/storageos/storageos.go | 1 - pkg/volume/storageos/storageos_test.go | 3 +- pkg/volume/storageos/storageos_util_test.go | 12 ++----- pkg/volume/util/atomic_writer_test.go | 2 +- .../util/fsquota/common/quota_linux_common.go | 5 --- pkg/volume/util/fsquota/project.go | 2 +- pkg/volume/util/fsquota/quota_linux.go | 3 +- pkg/volume/util/fsquota/quota_linux_test.go | 2 +- pkg/volume/util/subpath/subpath_linux.go | 2 +- pkg/volume/util/subpath/subpath_linux_test.go | 4 +-- 28 files changed, 38 insertions(+), 114 deletions(-) diff --git a/hack/.staticcheck_failures b/hack/.staticcheck_failures index d1999f082b2..0a1639f694b 100644 --- a/hack/.staticcheck_failures +++ b/hack/.staticcheck_failures @@ -15,19 +15,6 @@ pkg/registry/core/service/ipallocator pkg/registry/core/service/portallocator pkg/registry/core/service/storage pkg/util/coverage -pkg/volume -pkg/volume/azure_dd -pkg/volume/csi -pkg/volume/flexvolume -pkg/volume/iscsi -pkg/volume/local -pkg/volume/quobyte -pkg/volume/rbd -pkg/volume/storageos -pkg/volume/util -pkg/volume/util/fsquota -pkg/volume/util/fsquota/common -pkg/volume/util/subpath test/e2e/apps test/e2e/autoscaling test/integration/examples diff --git a/pkg/volume/azure_dd/azure_common.go b/pkg/volume/azure_dd/azure_common.go index 10068a81deb..72af23e9d61 100644 --- a/pkg/volume/azure_dd/azure_common.go +++ b/pkg/volume/azure_dd/azure_common.go @@ -64,8 +64,7 @@ var ( string(api.AzureManagedDisk)) // only for Windows node - winDiskNumRE = regexp.MustCompile(`/dev/disk(.+)`) - winDiskNumFormat = "/dev/disk%d" + winDiskNumRE = regexp.MustCompile(`/dev/disk(.+)`) ) func getPath(uid types.UID, volName string, host volume.VolumeHost) string { diff --git a/pkg/volume/azure_dd/azure_common_windows.go b/pkg/volume/azure_dd/azure_common_windows.go index 0b8f9004d68..397ce831435 100644 --- a/pkg/volume/azure_dd/azure_common_windows.go +++ b/pkg/volume/azure_dd/azure_common_windows.go @@ -30,6 +30,8 @@ import ( "k8s.io/utils/mount" ) +var winDiskNumFormat = "/dev/disk%d" + func scsiHostRescan(io ioHandler, exec utilexec.Interface) { cmd := "Update-HostStorageCache" output, err := exec.Command("powershell", "/c", cmd).CombinedOutput() diff --git a/pkg/volume/csi/csi_block.go b/pkg/volume/csi/csi_block.go index 2d8d31fd897..75ded23632e 100644 --- a/pkg/volume/csi/csi_block.go +++ b/pkg/volume/csi/csi_block.go @@ -94,7 +94,6 @@ type csiBlockMapper struct { readOnly bool spec *volume.Spec podUID types.UID - volumeInfo map[string]string } var _ volume.BlockVolumeMapper = &csiBlockMapper{} diff --git a/pkg/volume/csi/csi_block_test.go b/pkg/volume/csi/csi_block_test.go index 6b8707e8620..ccc8d6faf5c 100644 --- a/pkg/volume/csi/csi_block_test.go +++ b/pkg/volume/csi/csi_block_test.go @@ -53,40 +53,6 @@ func prepareBlockMapperTest(plug *csiPlugin, specVolumeName string, t *testing.T return csiMapper, spec, pv, nil } -func prepareBlockUnmapperTest(plug *csiPlugin, specVolumeName string, t *testing.T) (*csiBlockMapper, *volume.Spec, *api.PersistentVolume, error) { - registerFakePlugin(testDriver, "endpoint", []string{"1.0.0"}, t) - pv := makeTestPV(specVolumeName, 10, testDriver, testVol) - spec := volume.NewSpecFromPersistentVolume(pv, pv.Spec.PersistentVolumeSource.CSI.ReadOnly) - - // save volume data - dir := getVolumeDeviceDataDir(pv.ObjectMeta.Name, plug.host) - if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) { - t.Errorf("failed to create dir [%s]: %v", dir, err) - } - - if err := saveVolumeData( - dir, - volDataFileName, - map[string]string{ - volDataKey.specVolID: pv.ObjectMeta.Name, - volDataKey.driverName: testDriver, - volDataKey.volHandle: testVol, - }, - ); err != nil { - t.Fatalf("failed to save volume data: %v", err) - } - - unmapper, err := plug.NewBlockVolumeUnmapper(pv.ObjectMeta.Name, testPodUID) - if err != nil { - t.Fatalf("failed to make a new Unmapper: %v", err) - } - - csiUnmapper := unmapper.(*csiBlockMapper) - csiUnmapper.csiClient = setupClient(t, true) - - return csiUnmapper, spec, pv, nil -} - func TestBlockMapperGetGlobalMapPath(t *testing.T) { defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIBlockVolume, true)() diff --git a/pkg/volume/csi/csi_client.go b/pkg/volume/csi/csi_client.go index c1d548c9f53..cb55119ab8e 100644 --- a/pkg/volume/csi/csi_client.go +++ b/pkg/volume/csi/csi_client.go @@ -23,7 +23,6 @@ import ( "io" "net" "sync" - "time" csipbv1 "github.com/container-storage-interface/spec/lib/go/csi" "google.golang.org/grpc" @@ -104,12 +103,6 @@ type nodeV1ClientCreator func(addr csiAddr) ( err error, ) -const ( - initialDuration = 1 * time.Second - factor = 2.0 - steps = 5 -) - // newV1NodeClient creates a new NodeClient with the internally used gRPC // connection set up. It also returns a closer which must to be called to close // the gRPC connection when the NodeClient is not used anymore. diff --git a/pkg/volume/csi/csi_client_test.go b/pkg/volume/csi/csi_client_test.go index 97c6da7dea7..50f869d45c3 100644 --- a/pkg/volume/csi/csi_client_test.go +++ b/pkg/volume/csi/csi_client_test.go @@ -81,6 +81,9 @@ func (c *fakeCsiDriverClient) NodeGetVolumeStats(ctx context.Context, volID stri VolumePath: targetPath, } resp, err := c.nodeClient.NodeGetVolumeStats(ctx, req) + if err != nil { + return nil, err + } usages := resp.GetUsage() metrics := &volume.Metrics{} if usages == nil { diff --git a/pkg/volume/csi/csi_mounter.go b/pkg/volume/csi/csi_mounter.go index 87c5c3dc050..1b9e5aac23c 100644 --- a/pkg/volume/csi/csi_mounter.go +++ b/pkg/volume/csi/csi_mounter.go @@ -73,7 +73,6 @@ type csiMountMgr struct { spec *volume.Spec pod *api.Pod podUID types.UID - options volume.VolumeOptions publishContext map[string]string kubeVolHost volume.KubeletVolumeHost volume.MetricsProvider diff --git a/pkg/volume/csi/csi_mounter_test.go b/pkg/volume/csi/csi_mounter_test.go index ef5e613335f..c5421e6a27e 100644 --- a/pkg/volume/csi/csi_mounter_test.go +++ b/pkg/volume/csi/csi_mounter_test.go @@ -456,8 +456,8 @@ func TestMounterSetupWithStatusTracking(t *testing.T) { &api.Pod{ObjectMeta: meta.ObjectMeta{UID: tc.podUID, Namespace: testns}}, volume.VolumeOptions{}, ) - if mounter == nil { - t.Fatal("failed to create CSI mounter") + if err != nil { + t.Fatalf("failed to create CSI mounter: %v", err) } csiMounter := mounter.(*csiMountMgr) diff --git a/pkg/volume/csi/csi_plugin_test.go b/pkg/volume/csi/csi_plugin_test.go index 2f72e5c1c29..df2f7da1e70 100644 --- a/pkg/volume/csi/csi_plugin_test.go +++ b/pkg/volume/csi/csi_plugin_test.go @@ -623,7 +623,7 @@ func TestPluginNewMounter(t *testing.T) { } csiClient, err := csiMounter.csiClientGetter.Get() if csiClient == nil { - t.Error("mounter csiClient is nil") + t.Errorf("mounter csiClient is nil: %v", err) } if err != nil { t.Fatal(err) @@ -765,7 +765,7 @@ func TestPluginNewMounterWithInline(t *testing.T) { } csiClient, err := csiMounter.csiClientGetter.Get() if csiClient == nil { - t.Error("mounter csiClient is nil") + t.Errorf("mounter csiClient is nil: %v", err) } if csiMounter.volumeLifecycleMode != test.volumeLifecycleMode { t.Error("unexpected driver mode:", csiMounter.volumeLifecycleMode) @@ -860,7 +860,7 @@ func TestPluginNewUnmounter(t *testing.T) { csiClient, err := csiUnmounter.csiClientGetter.Get() if csiClient == nil { - t.Error("mounter csiClient is nil") + t.Errorf("mounter csiClient is nil: %v", err) } } @@ -1185,7 +1185,7 @@ func TestPluginNewBlockMapper(t *testing.T) { } csiClient, err := csiMapper.csiClientGetter.Get() if csiClient == nil { - t.Error("mapper csiClient is nil") + t.Errorf("mapper csiClient is nil: %v", err) } // ensure data file is created @@ -1248,7 +1248,7 @@ func TestPluginNewUnmapper(t *testing.T) { csiClient, err := csiUnmapper.csiClientGetter.Get() if csiClient == nil { - t.Error("unmapper csiClient is nil") + t.Errorf("unmapper csiClient is nil: %v", err) } // test loaded vol data diff --git a/pkg/volume/csi/csi_test.go b/pkg/volume/csi/csi_test.go index df7b783fb83..0675b8ebde4 100644 --- a/pkg/volume/csi/csi_test.go +++ b/pkg/volume/csi/csi_test.go @@ -305,7 +305,8 @@ func TestCSI_VolumeAll(t *testing.T) { go func(spec *volume.Spec, nodeName types.NodeName) { attachID, err := volAttacher.Attach(spec, nodeName) if err != nil { - t.Fatalf("csiTest.VolumeAll attacher.Attach failed: %s", err) + t.Errorf("csiTest.VolumeAll attacher.Attach failed: %s", err) + return } t.Logf("csiTest.VolumeAll got attachID %s", attachID) diff --git a/pkg/volume/flexvolume/probe_test.go b/pkg/volume/flexvolume/probe_test.go index c28f7215200..9a421c8e9cf 100644 --- a/pkg/volume/flexvolume/probe_test.go +++ b/pkg/volume/flexvolume/probe_test.go @@ -65,6 +65,7 @@ func TestProberAddRemoveDriver(t *testing.T) { _, fs, watcher, prober := initTestEnvironment(t) prober.Probe() events, err := prober.Probe() + assert.NoError(t, err) assert.Equal(t, 0, len(events)) // Call probe after a file is added. Should return 1 event. diff --git a/pkg/volume/iscsi/iscsi_test.go b/pkg/volume/iscsi/iscsi_test.go index a062067e123..8c058f782d3 100644 --- a/pkg/volume/iscsi/iscsi_test.go +++ b/pkg/volume/iscsi/iscsi_test.go @@ -91,9 +91,7 @@ func TestGetAccessModes(t *testing.T) { } type fakeDiskManager struct { - tmpDir string - attachCalled bool - detachCalled bool + tmpDir string } func NewFakeDiskManager() *fakeDiskManager { @@ -498,11 +496,11 @@ func TestGetISCSICHAP(t *testing.T) { }, } for _, testcase := range tests { - resultDiscoveryCHAP, err := getISCSIDiscoveryCHAPInfo(testcase.spec) + resultDiscoveryCHAP, _ := getISCSIDiscoveryCHAPInfo(testcase.spec) resultSessionCHAP, err := getISCSISessionCHAPInfo(testcase.spec) switch testcase.name { case "no volume": - if err.Error() != testcase.expectedError.Error() || resultDiscoveryCHAP != testcase.expectedDiscoveryCHAP || resultSessionCHAP != testcase.expectedSessionCHAP { + if err == nil || err.Error() != testcase.expectedError.Error() || resultDiscoveryCHAP != testcase.expectedDiscoveryCHAP || resultSessionCHAP != testcase.expectedSessionCHAP { t.Errorf("%s failed: expected err=%v DiscoveryCHAP=%v SessionCHAP=%v, got %v/%v/%v", testcase.name, testcase.expectedError, testcase.expectedDiscoveryCHAP, testcase.expectedSessionCHAP, err, resultDiscoveryCHAP, resultSessionCHAP) diff --git a/pkg/volume/iscsi/iscsi_util_test.go b/pkg/volume/iscsi/iscsi_util_test.go index 200e6e2bf78..8aa3a2bce54 100644 --- a/pkg/volume/iscsi/iscsi_util_test.go +++ b/pkg/volume/iscsi/iscsi_util_test.go @@ -156,7 +156,7 @@ func TestWaitForPathToExist(t *testing.T) { t.Errorf("waitForPathToExist: wrong code path called for %s", devicePath[1]) } - exist = waitForPathToExistInternal(&devicePath[1], 1, "fake_iface", os.Stat, fakeFilepathGlob2) + _ = waitForPathToExistInternal(&devicePath[1], 1, "fake_iface", os.Stat, fakeFilepathGlob2) if devicePath[1] != fpath { t.Errorf("waitForPathToExist: wrong code path called for %s", devicePath[1]) } diff --git a/pkg/volume/local/local.go b/pkg/volume/local/local.go index f5e27f3c9f9..aea490f9a61 100644 --- a/pkg/volume/local/local.go +++ b/pkg/volume/local/local.go @@ -360,8 +360,7 @@ func (dm *deviceMounter) MountDevice(spec *volume.Spec, devicePath string, devic switch fileType { case hostutil.FileTypeBlockDev: // local volume plugin does not implement AttachableVolumePlugin interface, so set devicePath to Path in PV spec directly - devicePath = spec.PersistentVolume.Spec.Local.Path - return dm.mountLocalBlockDevice(spec, devicePath, deviceMountPath) + return dm.mountLocalBlockDevice(spec, spec.PersistentVolume.Spec.Local.Path, deviceMountPath) case hostutil.FileTypeDirectory: // if the given local volume path is of already filesystem directory, return directly return nil diff --git a/pkg/volume/plugins_test.go b/pkg/volume/plugins_test.go index 167a47e6fa3..7471c00cf71 100644 --- a/pkg/volume/plugins_test.go +++ b/pkg/volume/plugins_test.go @@ -116,13 +116,13 @@ func TestVolumePluginMgrFunc(t *testing.T) { t.Errorf("Wrong name: %s", plug.GetPluginName()) } - plug, err = vpm.FindPluginBySpec(nil) + _, err = vpm.FindPluginBySpec(nil) if err == nil { t.Errorf("Should return error if volume spec is nil") } volumeSpec := &Spec{} - plug, err = vpm.FindPluginBySpec(volumeSpec) + _, err = vpm.FindPluginBySpec(volumeSpec) if err != nil { t.Errorf("Should return test plugin if volume spec is not nil") } diff --git a/pkg/volume/quobyte/quobyte.go b/pkg/volume/quobyte/quobyte.go index a25ccaa6b4a..77d050f2dc5 100644 --- a/pkg/volume/quobyte/quobyte.go +++ b/pkg/volume/quobyte/quobyte.go @@ -465,19 +465,14 @@ func parseAPIConfig(plugin *quobytePlugin, params map[string]string) (*quobyteAP var apiServer, secretName string secretNamespace := "default" - deleteKeys := []string{} - for k, v := range params { switch gostrings.ToLower(k) { case "adminsecretname": secretName = v - deleteKeys = append(deleteKeys, k) case "adminsecretnamespace": secretNamespace = v - deleteKeys = append(deleteKeys, k) case "quobyteapiserver": apiServer = v - deleteKeys = append(deleteKeys, k) } } diff --git a/pkg/volume/rbd/rbd.go b/pkg/volume/rbd/rbd.go index 72a63bd41ca..a72a12a8031 100644 --- a/pkg/volume/rbd/rbd.go +++ b/pkg/volume/rbd/rbd.go @@ -879,14 +879,10 @@ var _ volume.BlockVolumeMapper = &rbdDiskMapper{} type rbdDiskMapper struct { *rbd - mon []string - id string - keyring string - secret string - adminSecret string - adminID string - imageFormat string - imageFeatures []string + mon []string + id string + keyring string + secret string } var _ volume.BlockVolumeUnmapper = &rbdDiskUnmapper{} diff --git a/pkg/volume/storageos/storageos.go b/pkg/volume/storageos/storageos.go index 42c120469bc..f727d308612 100644 --- a/pkg/volume/storageos/storageos.go +++ b/pkg/volume/storageos/storageos.go @@ -299,7 +299,6 @@ type storageos struct { pvName string volName string volNamespace string - secretName string readOnly bool description string pool string diff --git a/pkg/volume/storageos/storageos_test.go b/pkg/volume/storageos/storageos_test.go index 610bfefe15d..727c568675a 100644 --- a/pkg/volume/storageos/storageos_test.go +++ b/pkg/volume/storageos/storageos_test.go @@ -373,8 +373,7 @@ func TestPersistentClaimReadOnlyFlag(t *testing.T) { spec := volume.NewSpecFromPersistentVolume(pv, true) pod := &v1.Pod{ObjectMeta: metav1.ObjectMeta{Namespace: "nsA", UID: types.UID("poduid")}} fakeManager := &fakePDManager{} - fakeConfig := &fakeConfig{} - apiCfg := fakeConfig.GetAPIConfig() + apiCfg := GetAPIConfig() mounter, err := plug.(*storageosPlugin).newMounterInternal(spec, pod, apiCfg, fakeManager, mount.NewFakeMounter(nil), &testingexec.FakeExec{}) if err != nil { t.Fatalf("error creating a new internal mounter:%v", err) diff --git a/pkg/volume/storageos/storageos_util_test.go b/pkg/volume/storageos/storageos_util_test.go index 2475c8e6870..2c00adce646 100644 --- a/pkg/volume/storageos/storageos_util_test.go +++ b/pkg/volume/storageos/storageos_util_test.go @@ -39,14 +39,7 @@ var testPool = "testpool" var testFSType = "ext2" var testVolUUID = "01c43d34-89f8-83d3-422b-43536a0f25e6" -type fakeConfig struct { - apiAddr string - apiUser string - apiPass string - apiVersion string -} - -func (c fakeConfig) GetAPIConfig() *storageosAPIConfig { +func GetAPIConfig() *storageosAPIConfig { return &storageosAPIConfig{ apiAddr: "http://5.6.7.8:9999", apiUser: "abc", @@ -57,8 +50,7 @@ func (c fakeConfig) GetAPIConfig() *storageosAPIConfig { func TestClient(t *testing.T) { util := storageosUtil{} - cfg := fakeConfig{} - err := util.NewAPI(cfg.GetAPIConfig()) + err := util.NewAPI(GetAPIConfig()) if err != nil { t.Fatalf("error getting api config: %v", err) } diff --git a/pkg/volume/util/atomic_writer_test.go b/pkg/volume/util/atomic_writer_test.go index b57f41c5871..7382672fdac 100644 --- a/pkg/volume/util/atomic_writer_test.go +++ b/pkg/volume/util/atomic_writer_test.go @@ -753,7 +753,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec dataDirPath := filepath.Join(targetDir, dataDirName) // use filepath.Walk to reconstruct the payload, then deep equal observedPayload := make(map[string]FileProjection) - visitor := func(path string, info os.FileInfo, err error) error { + visitor := func(path string, info os.FileInfo, _ error) error { if info.IsDir() { return nil } diff --git a/pkg/volume/util/fsquota/common/quota_linux_common.go b/pkg/volume/util/fsquota/common/quota_linux_common.go index f73e7c7b8b1..c7232e8de63 100644 --- a/pkg/volume/util/fsquota/common/quota_linux_common.go +++ b/pkg/volume/util/fsquota/common/quota_linux_common.go @@ -33,11 +33,6 @@ const ( BadQuotaID QuotaID = 0 ) -const ( - acct = iota - enforcing = iota -) - // QuotaType -- type of quota to be applied type QuotaType int diff --git a/pkg/volume/util/fsquota/project.go b/pkg/volume/util/fsquota/project.go index 9f2b5460bca..42122436042 100644 --- a/pkg/volume/util/fsquota/project.go +++ b/pkg/volume/util/fsquota/project.go @@ -165,7 +165,7 @@ func readProjectFiles(projects *os.File, projid *os.File) projectsList { func findAvailableQuota(path string, idMap map[common.QuotaID]bool) (common.QuotaID, error) { unusedQuotasSearched := 0 - for id := common.FirstQuota; id == id; id++ { + for id := common.FirstQuota; true; id++ { if _, ok := idMap[id]; !ok { isInUse, err := getApplier(path).QuotaIDIsInUse(id) if err != nil { diff --git a/pkg/volume/util/fsquota/quota_linux.go b/pkg/volume/util/fsquota/quota_linux.go index 319ae0e0829..b3364e2eae6 100644 --- a/pkg/volume/util/fsquota/quota_linux.go +++ b/pkg/volume/util/fsquota/quota_linux.go @@ -303,6 +303,7 @@ func SupportsQuotas(m mount.Interface, path string) (bool, error) { // AssignQuota chooses the quota ID based on the pod UID and path. // If the pod UID is identical to another one known, it may (but presently // doesn't) choose the same quota ID as other volumes in the pod. +//lint:ignore SA4009 poduid is overwritten by design, see comment below func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resource.Quantity) error { if bytes == nil { return fmt.Errorf("Attempting to assign null quota to %s", path) @@ -316,7 +317,7 @@ func AssignQuota(m mount.Interface, path string, poduid types.UID, bytes *resour // Current policy is to set individual quotas on each volumes. // If we decide later that we want to assign one quota for all // volumes in a pod, we can simply remove this line of code. - // If and when we decide permanently that we're going to adop + // If and when we decide permanently that we're going to adopt // one quota per volume, we can rip all of the pod code out. poduid = types.UID(uuid.NewUUID()) if pod, ok := dirPodMap[path]; ok && pod != poduid { diff --git a/pkg/volume/util/fsquota/quota_linux_test.go b/pkg/volume/util/fsquota/quota_linux_test.go index d429f395903..dd69c8979d8 100644 --- a/pkg/volume/util/fsquota/quota_linux_test.go +++ b/pkg/volume/util/fsquota/quota_linux_test.go @@ -555,7 +555,7 @@ func runCaseDisabled(t *testing.T, testcase quotaTestCase, seq int) bool { var supports bool switch testcase.op { case "Supports": - if supports, err = fakeSupportsQuotas(testcase.path); supports { + if supports, _ = fakeSupportsQuotas(testcase.path); supports { t.Errorf("Case %v (%s, %v) supports quotas but shouldn't", seq, testcase.path, false) return true } diff --git a/pkg/volume/util/subpath/subpath_linux.go b/pkg/volume/util/subpath/subpath_linux.go index 0663a72c50d..7dbfa48ec52 100644 --- a/pkg/volume/util/subpath/subpath_linux.go +++ b/pkg/volume/util/subpath/subpath_linux.go @@ -229,7 +229,7 @@ func doCleanSubPaths(mounter mount.Interface, podDir string, volumeName string) // scan /var/lib/kubelet/pods//volume-subpaths///* fullContainerDirPath := filepath.Join(subPathDir, containerDir.Name()) - err = filepath.Walk(fullContainerDirPath, func(path string, info os.FileInfo, err error) error { + err = filepath.Walk(fullContainerDirPath, func(path string, info os.FileInfo, _ error) error { if path == fullContainerDirPath { // Skip top level directory return nil diff --git a/pkg/volume/util/subpath/subpath_linux_test.go b/pkg/volume/util/subpath/subpath_linux_test.go index 154d761e6bf..0cb8e18f820 100644 --- a/pkg/volume/util/subpath/subpath_linux_test.go +++ b/pkg/volume/util/subpath/subpath_linux_test.go @@ -576,13 +576,13 @@ func TestCleanSubPaths(t *testing.T) { return mounts, nil }, unmount: func(mountpath string) error { - err := filepath.Walk(mountpath, func(path string, info os.FileInfo, err error) error { + err := filepath.Walk(mountpath, func(path string, info os.FileInfo, _ error) error { if path == mountpath { // Skip top level directory return nil } - if err = os.Remove(path); err != nil { + if err := os.Remove(path); err != nil { return err } return filepath.SkipDir