Skip to content

Commit d93081d

Browse files
committed
common: update linter
- align with harvester/harvester repo - fix linter warning - update vendor/generated code Signed-off-by: Vicente Cheng <[email protected]>
1 parent f06a1c9 commit d93081d

File tree

9 files changed

+37
-84
lines changed

9 files changed

+37
-84
lines changed

.golangci.yaml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version: 2
1+
version: "2"
22
linters:
3-
disable-all: true
3+
default: none
44
enable:
55
- errcheck
66
- govet
@@ -10,9 +10,6 @@ linters:
1010
- unused
1111
- misspell
1212
- prealloc
13-
formatters:
14-
enable:
15-
- gofmt
1613
settings:
1714
gosec:
1815
# https://github.com/securego/gosec#available-rules
@@ -24,12 +21,12 @@ linters:
2421
- G505 # Blocklisted import crypto/md5: weak cryptographic primitive
2522
config:
2623
G306: "0644" # Poor file permissions used when writing to a new file
27-
exclude-files:
28-
- /zz_generated_
29-
- _generated
30-
exclude-dirs:
31-
- generated
3224
exclusions:
25+
paths:
26+
- vendor
27+
- pkg/generated
28+
- .*zz_generated.*
29+
- .*_generated.*
3330
presets:
3431
- comments
3532
- common-false-positives
@@ -39,9 +36,18 @@ linters:
3936
- linters:
4037
- staticcheck
4138
text: "QF1003:" # could use tagged switch on errCode (staticcheck)
39+
- linters:
40+
- staticcheck
41+
text: "QF1007:" # could merge conditional assignment into variable declaration (staticcheck)
4242
- linters:
4343
- staticcheck
4444
text: "QF1008:" # could remove embedded field from selector (staticcheck)
45+
- linters:
46+
- staticcheck
47+
text: "QF1012:" # Use fmt.Fprint(...) instead of Write([]byte(fmt.Sprint(...)))
48+
formatters:
49+
enable:
50+
- gofmt
4551
run:
4652
timeout: 5m
47-
tests: true
53+
tests: true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ require (
5656
k8s.io/api v0.35.0
5757
k8s.io/apimachinery v0.35.0
5858
k8s.io/client-go v12.0.0+incompatible
59-
k8s.io/utils v0.0.0-20260108192941-914a6e750570
6059
)
6160

6261
require (
@@ -120,6 +119,7 @@ require (
120119
k8s.io/klog/v2 v2.130.1 // indirect
121120
k8s.io/kube-aggregator v0.35.0 // indirect
122121
k8s.io/kube-openapi v0.31.5 // indirect
122+
k8s.io/utils v0.0.0-20260108192941-914a6e750570 // indirect
123123
kubevirt.io/api v1.4.0 // indirect
124124
kubevirt.io/containerized-data-importer-api v1.61.0 // indirect
125125
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect

pkg/block/block_device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func udevInfo(paths *linuxpath.Paths, disk string) (map[string]string, error) {
170170

171171
// Look up block device in udev runtime database
172172
udevID := "b" + strings.TrimSpace(string(devNo))
173-
udevBytes, err := os.ReadFile(filepath.Join(paths.RunUdevData, udevID))
173+
udevBytes, err := os.ReadFile(filepath.Clean(filepath.Join(paths.RunUdevData, udevID)))
174174
if err != nil {
175175
return nil, err
176176
}

pkg/controller/blockdevice/scanner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
corev1 "k8s.io/api/core/v1"
1414
"k8s.io/apimachinery/pkg/api/errors"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
"k8s.io/utils/strings/slices"
16+
"slices"
1717

1818
diskv1 "github.com/harvester/node-disk-manager/pkg/apis/harvesterhci.io/v1beta1"
1919
"github.com/harvester/node-disk-manager/pkg/block"

pkg/generated/clientset/versioned/fake/clientset_generated.go

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/integration/test_0_single_disk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type ProvisionedDisk struct {
3737

3838
func (s *SingleDiskSuite) SetupSuite() {
3939
nodeName := ""
40-
f, err := os.Open(filepath.Join(os.Getenv("NDM_HOME"), "ssh-config"))
40+
f, err := os.Open(filepath.Clean(filepath.Join(os.Getenv("NDM_HOME"), "ssh-config")))
4141
require.Equal(s.T(), nil, err, "Open ssh-config should not get error")
4242
cfg, err := ssh_config.Decode(f)
4343
require.Equal(s.T(), nil, err, "Decode ssh-config should not get error")

tests/integration/test_1_disk_hotplug_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type HotPlugTestSuite struct {
5050

5151
func (s *HotPlugTestSuite) SetupSuite() {
5252
nodeName := ""
53-
f, err := os.Open(filepath.Join(os.Getenv("NDM_HOME"), "ssh-config"))
53+
f, err := os.Open(filepath.Clean(filepath.Join(os.Getenv("NDM_HOME"), "ssh-config")))
5454
require.Equal(s.T(), nil, err, "Open ssh-config should not get error")
5555
cfg, err := ssh_config.Decode(f)
5656
require.Equal(s.T(), nil, err, "Decode ssh-config should not get error")
@@ -252,7 +252,7 @@ func (s *HotPlugTestSuite) Test_4_RemoveInactiveDisk() {
252252
func doCommand(cmdString string) (string, string, error) {
253253
var stdout bytes.Buffer
254254
var stderr bytes.Buffer
255-
cmd := exec.Command("bash", "-c", cmdString)
255+
cmd := exec.Command("bash", "-c", cmdString) //nolint:gosec // G702: intentional test helper for running shell commands
256256
cmd.Stdout = &stdout
257257
cmd.Stderr = &stderr
258258
err := cmd.Run()

vendor/k8s.io/utils/strings/slices/slices.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

vendor/modules.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ k8s.io/utils/internal/third_party/forked/golang/net
801801
k8s.io/utils/net
802802
k8s.io/utils/pointer
803803
k8s.io/utils/ptr
804-
k8s.io/utils/strings/slices
805804
k8s.io/utils/trace
806805
# kubevirt.io/api v1.4.0
807806
## explicit; go 1.22.0

0 commit comments

Comments
 (0)