Skip to content

Commit 024ba92

Browse files
Enabled a few more linters
1 parent cf66a5c commit 024ba92

File tree

9 files changed

+29
-34
lines changed

9 files changed

+29
-34
lines changed

.golangci.yml

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ linters:
1212
- errchkjson
1313
- execinquery
1414
# - gci
15-
# - goconst
15+
- goconst
1616
# - gocritic
1717
- gocyclo
1818
- godot
@@ -30,17 +30,17 @@ linters:
3030
- noctx
3131
- nolintlint
3232
- nosprintfhostport
33-
# - prealloc
34-
# - predeclared
33+
- prealloc
34+
- predeclared
3535
- reassign
3636
# - revive
3737
- rowserrcheck
3838
- staticcheck
3939
# - stylecheck
4040
# - thelper
4141
- typecheck
42-
# - unconvert
43-
# - unparam
42+
- unconvert
43+
- unparam
4444
- unused
4545
- usestdlibvars
4646
- whitespace
@@ -63,8 +63,6 @@ linters-settings:
6363
- prefix(github.com/IBM)
6464
- prefix(k8s.io)
6565
- prefix(sigs.k8s.io)
66-
- prefix(sigs.k8s.io/cluster-api)
67-
- prefix(sigs.k8s.io/cluster-api-provider-ibmcloud)
6866
- blank
6967
- dot
7068
importas:
@@ -88,10 +86,6 @@ linters-settings:
8886
allow-unused: false
8987
# allow-leading-space: false
9088
require-specific: true
91-
staticcheck:
92-
go: "1.22"
93-
stylecheck:
94-
go: "1.22"
9589
gosec:
9690
excludes:
9791
- G307 # Deferring unsafe method "Close" on type "\*os.File"
@@ -116,6 +110,8 @@ linters-settings:
116110
unused:
117111
go: "1.22"
118112
issues:
113+
exclude-files:
114+
- "zz_generated.*\\.go$"
119115
max-same-issues: 0
120116
max-issues-per-linter: 0
121117
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
@@ -202,6 +198,5 @@ run:
202198
build-tags:
203199
- tools
204200
- e2e
205-
skip-files:
206-
- "zz_generated.*\\.go$"
207-
allow-parallel-runners: true
201+
allow-parallel-runners: true
202+
go: "1.22"

cmd/options_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ func TestGetOptions(t *testing.T) {
2727
t *testing.T,
2828
additionalArgs []string,
2929
withServerOptions bool,
30-
withControllerOptions bool,
3130
withNodeOptions bool,
3231
) *Options {
3332
flagSet := flag.NewFlagSet("test-flagset", flag.ContinueOnError)
@@ -85,7 +84,7 @@ func TestGetOptions(t *testing.T) {
8584
{
8685
name: "no controller mode given - expect all mode",
8786
testFunc: func(t *testing.T) {
88-
options := testFunc(t, nil, true, true, true)
87+
options := testFunc(t, nil, true, true)
8988

9089
if options.DriverMode != driver.AllMode {
9190
t.Fatalf("expected driver mode to be %q but it is %q", driver.AllMode, options.DriverMode)
@@ -96,7 +95,7 @@ func TestGetOptions(t *testing.T) {
9695
{
9796
name: "all mode given - expect all mode",
9897
testFunc: func(t *testing.T) {
99-
options := testFunc(t, []string{"all"}, true, true, true)
98+
options := testFunc(t, []string{"all"}, true, true)
10099

101100
if options.DriverMode != driver.AllMode {
102101
t.Fatalf("expected driver mode to be %q but it is %q", driver.AllMode, options.DriverMode)
@@ -106,7 +105,7 @@ func TestGetOptions(t *testing.T) {
106105
{
107106
name: "controller mode given - expect controller mode",
108107
testFunc: func(t *testing.T) {
109-
options := testFunc(t, []string{"controller"}, true, true, false)
108+
options := testFunc(t, []string{"controller"}, true, false)
110109

111110
if options.DriverMode != driver.ControllerMode {
112111
t.Fatalf("expected driver mode to be %q but it is %q", driver.ControllerMode, options.DriverMode)
@@ -116,7 +115,7 @@ func TestGetOptions(t *testing.T) {
116115
{
117116
name: "node mode given - expect node mode",
118117
testFunc: func(t *testing.T) {
119-
options := testFunc(t, []string{"node"}, true, false, true)
118+
options := testFunc(t, []string{"node"}, true, true)
120119

121120
if options.DriverMode != driver.NodeMode {
122121
t.Fatalf("expected driver mode to be %q but it is %q", driver.NodeMode, options.DriverMode)

pkg/driver/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (d *controllerService) ControllerUnpublishVolume(ctx context.Context, req *
323323

324324
func (d *controllerService) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
325325
klog.V(4).Infof("ControllerGetCapabilities: called with args %+v", req)
326-
var caps []*csi.ControllerServiceCapability
326+
caps := make([]*csi.ControllerServiceCapability, 0, len(controllerCaps))
327327
for _, cap := range controllerCaps {
328328
c := &csi.ControllerServiceCapability{
329329
Type: &csi.ControllerServiceCapability_Rpc{

pkg/driver/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ func (d *nodeService) NodeGetVolumeStats(ctx context.Context, req *csi.NodeGetVo
569569

570570
func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetCapabilitiesRequest) (*csi.NodeGetCapabilitiesResponse, error) {
571571
klog.V(4).Infof("NodeGetCapabilities: called with args %+v", req)
572-
var caps []*csi.NodeServiceCapability
572+
caps := make([]*csi.NodeServiceCapability, 0, len(nodeCaps))
573573
for _, cap := range nodeCaps {
574574
c := &csi.NodeServiceCapability{
575575
Type: &csi.NodeServiceCapability_Rpc{

pkg/driver/node_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const (
4343
// VolumeAttributePartition represents key for partition config in VolumeContext.
4444
// It represents the partition number on a device used to mount.
4545
VolumeAttributePartition = "partition"
46+
testDir = "./test"
4647
)
4748

4849
var (
@@ -1136,7 +1137,7 @@ func TestNodeGetVolumeStats(t *testing.T) {
11361137
defer mockCtl.Finish()
11371138
mockStatUtils := mocks.NewMockStatsUtils(mockCtl)
11381139

1139-
volumePath := "./test"
1140+
volumePath := testDir
11401141
var mockCapacity int64 = 100
11411142
mockStatUtils.EXPECT().IsPathNotExist(volumePath).Return(false)
11421143
mockStatUtils.EXPECT().IsBlockDevice(volumePath).Return(true, nil)
@@ -1161,7 +1162,7 @@ func TestNodeGetVolumeStats(t *testing.T) {
11611162
defer mockCtl.Finish()
11621163
mockStatUtils := mocks.NewMockStatsUtils(mockCtl)
11631164

1164-
volumePath := "./test"
1165+
volumePath := testDir
11651166
mockStatUtils.EXPECT().IsPathNotExist(volumePath).Return(true)
11661167
driver := &nodeService{stats: mockStatUtils}
11671168

@@ -1177,7 +1178,7 @@ func TestNodeGetVolumeStats(t *testing.T) {
11771178
defer mockCtl.Finish()
11781179
mockStatUtils := mocks.NewMockStatsUtils(mockCtl)
11791180

1180-
volumePath := "./test"
1181+
volumePath := testDir
11811182
mockStatUtils.EXPECT().IsPathNotExist(volumePath).Return(false)
11821183
mockStatUtils.EXPECT().IsBlockDevice(volumePath).Return(false, errors.New("Error checking for block device"))
11831184
driver := &nodeService{stats: mockStatUtils}
@@ -1194,7 +1195,7 @@ func TestNodeGetVolumeStats(t *testing.T) {
11941195
defer mockCtl.Finish()
11951196
mockStatUtils := mocks.NewMockStatsUtils(mockCtl)
11961197

1197-
volumePath := "./test"
1198+
volumePath := "testDir"
11981199
mockStatUtils.EXPECT().IsPathNotExist(volumePath).Return(false)
11991200
mockStatUtils.EXPECT().IsBlockDevice(volumePath).Return(true, nil)
12001201
mockStatUtils.EXPECT().DeviceInfo(volumePath).Return(int64(0), errors.New("Error collecting block device info"))
@@ -1214,7 +1215,7 @@ func TestNodeGetVolumeStats(t *testing.T) {
12141215
defer mockCtl.Finish()
12151216
mockStatUtils := mocks.NewMockStatsUtils(mockCtl)
12161217

1217-
volumePath := "./test"
1218+
volumePath := "testDir"
12181219
mockStatUtils.EXPECT().IsPathNotExist(volumePath).Return(false)
12191220
mockStatUtils.EXPECT().IsBlockDevice(volumePath).Return(false, nil)
12201221
var statUnit int64 = 0

pkg/driver/sanity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (c *fakeCloudProvider) WaitForVolumeState(volumeID, expectedState string) e
212212
}
213213

214214
func (c *fakeCloudProvider) GetDiskByName(name string) (*cloud.Disk, error) {
215-
var disks []*fakeDisk
215+
disks := make([]*fakeDisk, 0, len(c.disks))
216216
for _, d := range c.disks {
217217
disks = append(disks, d)
218218
}

tests/e2e/driver/powervs_csi_driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (d *powervsCSIDriver) GetPersistentVolume(volumeID string, fsType string, s
8484
Spec: v1.PersistentVolumeSpec{
8585
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
8686
Capacity: v1.ResourceList{
87-
v1.ResourceName(v1.ResourceStorage): resource.MustParse(size),
87+
v1.ResourceStorage: resource.MustParse(size),
8888
},
8989
PersistentVolumeReclaimPolicy: pvReclaimPolicy,
9090
PersistentVolumeSource: v1.PersistentVolumeSource{

tests/e2e/testsuites/dynamically_provisioned_resize_volume_tester.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func (t *DynamicallyProvisionedResizeVolumeTest) Run(client clientset.Interface,
6868

6969
updatedSize := updatedPvc.Spec.Resources.Requests["storage"]
7070
By("checking the resizing PV result")
71-
error := WaitForPvToResize(client, namespace, updatedPvc.Spec.VolumeName, updatedSize, 10*time.Minute, 5*time.Second)
72-
framework.ExpectNoError(error)
71+
resizeErr := WaitForPvToResize(client, namespace, updatedPvc.Spec.VolumeName, updatedSize, 10*time.Minute, 5*time.Second)
72+
framework.ExpectNoError(resizeErr)
7373
By("Validate volume can be attached")
7474
tpod := NewTestPod(client, namespace, t.Pod.Cmd)
7575
tpod.SetupVolume(tpvc.persistentVolumeClaim, volume.VolumeMount.NameGenerate+"1", volume.VolumeMount.MountPathGenerate+"1", volume.VolumeMount.ReadOnly)

tests/e2e/testsuites/testsuites.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func generatePVC(namespace, storageClassName, claimSize string, volumeMode v1.Pe
203203
},
204204
Resources: v1.VolumeResourceRequirements{
205205
Requests: v1.ResourceList{
206-
v1.ResourceName(v1.ResourceStorage): resource.MustParse(claimSize),
206+
v1.ResourceStorage: resource.MustParse(claimSize),
207207
},
208208
},
209209
VolumeMode: &volumeMode,
@@ -221,11 +221,11 @@ func (t *TestPersistentVolumeClaim) ValidateProvisionedPersistentVolume() {
221221
framework.ExpectNoError(err)
222222

223223
// Check sizes
224-
expectedCapacity := t.requestedPersistentVolumeClaim.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
225-
claimCapacity := t.persistentVolumeClaim.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]
224+
expectedCapacity := t.requestedPersistentVolumeClaim.Spec.Resources.Requests[v1.ResourceStorage]
225+
claimCapacity := t.persistentVolumeClaim.Spec.Resources.Requests[v1.ResourceStorage]
226226
Expect(claimCapacity.Value()).To(Equal(expectedCapacity.Value()), "claimCapacity is not equal to requestedCapacity")
227227

228-
pvCapacity := t.persistentVolume.Spec.Capacity[v1.ResourceName(v1.ResourceStorage)]
228+
pvCapacity := t.persistentVolume.Spec.Capacity[v1.ResourceStorage]
229229
Expect(pvCapacity.Value()).To(Equal(expectedCapacity.Value()), "pvCapacity is not equal to requestedCapacity")
230230

231231
// Check PV properties

0 commit comments

Comments
 (0)