Skip to content

Commit 3d350d8

Browse files
authored
Merge pull request kubernetes#81892 from praseodym/fix-staticcheck-pkg/volume
Fix staticcheck failures for pkg/volume/...
2 parents 2da163b + 2c61627 commit 3d350d8

28 files changed

+38
-114
lines changed

hack/.staticcheck_failures

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ pkg/registry/core/service/ipallocator
1515
pkg/registry/core/service/portallocator
1616
pkg/registry/core/service/storage
1717
pkg/util/coverage
18-
pkg/volume
19-
pkg/volume/azure_dd
20-
pkg/volume/csi
21-
pkg/volume/flexvolume
22-
pkg/volume/iscsi
23-
pkg/volume/local
24-
pkg/volume/quobyte
25-
pkg/volume/rbd
26-
pkg/volume/storageos
27-
pkg/volume/util
28-
pkg/volume/util/fsquota
29-
pkg/volume/util/fsquota/common
30-
pkg/volume/util/subpath
3118
test/e2e/apps
3219
test/e2e/autoscaling
3320
test/integration/examples

pkg/volume/azure_dd/azure_common.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ var (
6464
string(api.AzureManagedDisk))
6565

6666
// only for Windows node
67-
winDiskNumRE = regexp.MustCompile(`/dev/disk(.+)`)
68-
winDiskNumFormat = "/dev/disk%d"
67+
winDiskNumRE = regexp.MustCompile(`/dev/disk(.+)`)
6968
)
7069

7170
func getPath(uid types.UID, volName string, host volume.VolumeHost) string {

pkg/volume/azure_dd/azure_common_windows.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import (
3030
"k8s.io/utils/mount"
3131
)
3232

33+
var winDiskNumFormat = "/dev/disk%d"
34+
3335
func scsiHostRescan(io ioHandler, exec utilexec.Interface) {
3436
cmd := "Update-HostStorageCache"
3537
output, err := exec.Command("powershell", "/c", cmd).CombinedOutput()

pkg/volume/csi/csi_block.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ type csiBlockMapper struct {
9494
readOnly bool
9595
spec *volume.Spec
9696
podUID types.UID
97-
volumeInfo map[string]string
9897
}
9998

10099
var _ volume.BlockVolumeMapper = &csiBlockMapper{}

pkg/volume/csi/csi_block_test.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,6 @@ func prepareBlockMapperTest(plug *csiPlugin, specVolumeName string, t *testing.T
5353
return csiMapper, spec, pv, nil
5454
}
5555

56-
func prepareBlockUnmapperTest(plug *csiPlugin, specVolumeName string, t *testing.T) (*csiBlockMapper, *volume.Spec, *api.PersistentVolume, error) {
57-
registerFakePlugin(testDriver, "endpoint", []string{"1.0.0"}, t)
58-
pv := makeTestPV(specVolumeName, 10, testDriver, testVol)
59-
spec := volume.NewSpecFromPersistentVolume(pv, pv.Spec.PersistentVolumeSource.CSI.ReadOnly)
60-
61-
// save volume data
62-
dir := getVolumeDeviceDataDir(pv.ObjectMeta.Name, plug.host)
63-
if err := os.MkdirAll(dir, 0755); err != nil && !os.IsNotExist(err) {
64-
t.Errorf("failed to create dir [%s]: %v", dir, err)
65-
}
66-
67-
if err := saveVolumeData(
68-
dir,
69-
volDataFileName,
70-
map[string]string{
71-
volDataKey.specVolID: pv.ObjectMeta.Name,
72-
volDataKey.driverName: testDriver,
73-
volDataKey.volHandle: testVol,
74-
},
75-
); err != nil {
76-
t.Fatalf("failed to save volume data: %v", err)
77-
}
78-
79-
unmapper, err := plug.NewBlockVolumeUnmapper(pv.ObjectMeta.Name, testPodUID)
80-
if err != nil {
81-
t.Fatalf("failed to make a new Unmapper: %v", err)
82-
}
83-
84-
csiUnmapper := unmapper.(*csiBlockMapper)
85-
csiUnmapper.csiClient = setupClient(t, true)
86-
87-
return csiUnmapper, spec, pv, nil
88-
}
89-
9056
func TestBlockMapperGetGlobalMapPath(t *testing.T) {
9157
defer featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIBlockVolume, true)()
9258

pkg/volume/csi/csi_client.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"io"
2424
"net"
2525
"sync"
26-
"time"
2726

2827
csipbv1 "github.com/container-storage-interface/spec/lib/go/csi"
2928
"google.golang.org/grpc"
@@ -104,12 +103,6 @@ type nodeV1ClientCreator func(addr csiAddr) (
104103
err error,
105104
)
106105

107-
const (
108-
initialDuration = 1 * time.Second
109-
factor = 2.0
110-
steps = 5
111-
)
112-
113106
// newV1NodeClient creates a new NodeClient with the internally used gRPC
114107
// connection set up. It also returns a closer which must to be called to close
115108
// the gRPC connection when the NodeClient is not used anymore.

pkg/volume/csi/csi_client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func (c *fakeCsiDriverClient) NodeGetVolumeStats(ctx context.Context, volID stri
8181
VolumePath: targetPath,
8282
}
8383
resp, err := c.nodeClient.NodeGetVolumeStats(ctx, req)
84+
if err != nil {
85+
return nil, err
86+
}
8487
usages := resp.GetUsage()
8588
metrics := &volume.Metrics{}
8689
if usages == nil {

pkg/volume/csi/csi_mounter.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ type csiMountMgr struct {
7373
spec *volume.Spec
7474
pod *api.Pod
7575
podUID types.UID
76-
options volume.VolumeOptions
7776
publishContext map[string]string
7877
kubeVolHost volume.KubeletVolumeHost
7978
volume.MetricsProvider

pkg/volume/csi/csi_mounter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ func TestMounterSetupWithStatusTracking(t *testing.T) {
456456
&api.Pod{ObjectMeta: meta.ObjectMeta{UID: tc.podUID, Namespace: testns}},
457457
volume.VolumeOptions{},
458458
)
459-
if mounter == nil {
460-
t.Fatal("failed to create CSI mounter")
459+
if err != nil {
460+
t.Fatalf("failed to create CSI mounter: %v", err)
461461
}
462462

463463
csiMounter := mounter.(*csiMountMgr)

pkg/volume/csi/csi_plugin_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ func TestPluginNewMounter(t *testing.T) {
623623
}
624624
csiClient, err := csiMounter.csiClientGetter.Get()
625625
if csiClient == nil {
626-
t.Error("mounter csiClient is nil")
626+
t.Errorf("mounter csiClient is nil: %v", err)
627627
}
628628
if err != nil {
629629
t.Fatal(err)
@@ -765,7 +765,7 @@ func TestPluginNewMounterWithInline(t *testing.T) {
765765
}
766766
csiClient, err := csiMounter.csiClientGetter.Get()
767767
if csiClient == nil {
768-
t.Error("mounter csiClient is nil")
768+
t.Errorf("mounter csiClient is nil: %v", err)
769769
}
770770
if csiMounter.volumeLifecycleMode != test.volumeLifecycleMode {
771771
t.Error("unexpected driver mode:", csiMounter.volumeLifecycleMode)
@@ -860,7 +860,7 @@ func TestPluginNewUnmounter(t *testing.T) {
860860

861861
csiClient, err := csiUnmounter.csiClientGetter.Get()
862862
if csiClient == nil {
863-
t.Error("mounter csiClient is nil")
863+
t.Errorf("mounter csiClient is nil: %v", err)
864864
}
865865
}
866866

@@ -1185,7 +1185,7 @@ func TestPluginNewBlockMapper(t *testing.T) {
11851185
}
11861186
csiClient, err := csiMapper.csiClientGetter.Get()
11871187
if csiClient == nil {
1188-
t.Error("mapper csiClient is nil")
1188+
t.Errorf("mapper csiClient is nil: %v", err)
11891189
}
11901190

11911191
// ensure data file is created
@@ -1248,7 +1248,7 @@ func TestPluginNewUnmapper(t *testing.T) {
12481248

12491249
csiClient, err := csiUnmapper.csiClientGetter.Get()
12501250
if csiClient == nil {
1251-
t.Error("unmapper csiClient is nil")
1251+
t.Errorf("unmapper csiClient is nil: %v", err)
12521252
}
12531253

12541254
// test loaded vol data

0 commit comments

Comments
 (0)