Skip to content

Commit 6052fe5

Browse files
committed
chore: update Go version and lint
Signed-off-by: Fred Rolland <frolland@nvidia.com>
1 parent 835d981 commit 6052fe5

File tree

20 files changed

+249
-104
lines changed

20 files changed

+249
-104
lines changed

.golangci.yml

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
# Tested with golangci-lint ver. 2.x
2+
version: "2"
3+
4+
run:
5+
timeout: 10m
6+
7+
linters:
8+
default: none
9+
enable:
10+
- asciicheck # checks for non-ASCII identifiers
11+
- bidichk # checks for dangerous unicode sequences (security)
12+
- bodyclose
13+
- copyloopvar
14+
- depguard
15+
- dogsled
16+
# TODO fix issues- dupl
17+
- errcheck
18+
- errname # checks error naming conventions
19+
- exhaustive
20+
# TODO fix issues- funlen
21+
- gocheckcompilerdirectives # validates go compiler directives
22+
#- gochecknoinits
23+
- goconst
24+
# TODO fix issues- gocritic
25+
# TODO fix issues- gocyclo
26+
# gofmt and goimports are now formatters in v2, not linters
27+
# TODO fix issues- mnd (formerly gomnd)
28+
- goprintffuncname
29+
# TODO fix issues- gosec
30+
# gosimple and stylecheck are now part of staticcheck in v2
31+
- staticcheck
32+
#- govet
33+
- ineffassign
34+
# TODO fix issues- intrange (2 issues - use integer ranges Go 1.22+)
35+
# TODO fix issues- lll
36+
- makezero # finds slice declarations with non-zero initial length
37+
- misspell
38+
- nakedret
39+
# TODO fix issues- nilerr (3 issues - returns nil when error is not nil)
40+
# TODO fix issues- noctx (4 issues - missing context.Context)
41+
# TODO fix issues- prealloc
42+
- reassign # checks package variable reassignment
43+
- unconvert
44+
# TODO fix issues- unparam
45+
- unused
46+
- whitespace
47+
48+
settings:
49+
depguard:
50+
rules:
51+
main:
52+
deny:
53+
- pkg: github.com/sirupsen/logrus
54+
desc: "logging is allowed only by logutils.Log"
55+
dupl:
56+
threshold: 100
57+
funlen:
58+
lines: 100
59+
statements: 50
60+
goconst:
61+
min-len: 2
62+
min-occurrences: 2
63+
gocritic:
64+
enabled-tags:
65+
- diagnostic
66+
- experimental
67+
- opinionated
68+
- performance
69+
- style
70+
disabled-checks:
71+
- ifElseChain # style preference - suggests switch over if-else
72+
- whyNoLint # requires explanation for nolint directives
73+
- unnamedResult # style preference - named return values
74+
settings:
75+
hugeParam:
76+
sizeThreshold: 512
77+
rangeValCopy:
78+
sizeThreshold: 512
79+
gocyclo:
80+
min-complexity: 15
81+
mnd:
82+
# don't include the "operation" and "assign"
83+
checks:
84+
- argument
85+
- case
86+
- condition
87+
- return
88+
lll:
89+
line-length: 140
90+
misspell:
91+
locale: US
92+
prealloc:
93+
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
94+
# True by default.
95+
simple: true
96+
range-loops: true # Report preallocation suggestions on range loops, true by default
97+
for-loops: false # Report preallocation suggestions on for loops, false by default
98+
staticcheck:
99+
checks:
100+
- all
101+
- -QF1001 # De Morgan's law suggestions
102+
- -QF1003 # tagged switch suggestions
103+
- -QF1008 # embedded field selector suggestions
104+
dot-import-whitelist:
105+
- github.com/onsi/ginkgo/v2
106+
- github.com/onsi/gomega
107+
- github.com/onsi/gomega/gstruct
108+
109+
exclusions:
110+
generated: lax
111+
presets:
112+
- comments
113+
- std-error-handling
114+
paths:
115+
- vendor/
116+
- .github/
117+
- manifests/
118+
- docs/
119+
- cluster/
120+
- hack/
121+
- automation/
122+
- examples/
123+
rules:
124+
# Exclude various linters from test files
125+
- path: _test\.go
126+
linters:
127+
- mnd
128+
- gosec
129+
- dupl
130+
- lll
131+
- goconst
132+
# Exclude linters from tests/ directory
133+
- path: ^tests/
134+
linters:
135+
- goconst
136+
137+
formatters:
138+
enable:
139+
- gofmt
140+
- goimports
141+
settings:
142+
goimports:
143+
local-prefixes:
144+
- github.com/k8snetworkplumbingwg/ovs-cni

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ $(BASE): ; $(info setting GOPATH...)
4242

4343
GOLANGCI = $(GOBIN)/golangci-lint
4444
$(GOBIN)/golangci-lint: $(GO) | $(BASE) ; $(info building golangci-lint...)
45-
$Q $(GO) install -mod=mod github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.6
45+
$Q $(GO) install -mod=mod github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.6.2
4646

4747
build: format $(patsubst %, build-%, $(COMPONENTS))
4848

cmd/marker/main.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/golang/glog"
2627
"k8s.io/apimachinery/pkg/util/wait"
2728

28-
"github.com/golang/glog"
2929
"github.com/k8snetworkplumbingwg/ovs-cni/pkg/cache"
3030
"github.com/k8snetworkplumbingwg/ovs-cni/pkg/marker"
3131
)
3232

3333
const (
3434
UnixSocketType = "unix"
35-
TcpSocketType = "tcp"
35+
TCPSocketType = "tcp"
3636
SocketConnectionTimeout = time.Minute
3737
)
3838

@@ -98,7 +98,6 @@ func main() {
9898
if err != nil {
9999
glog.Fatalf("Update failed: %v", err)
100100
}
101-
102101
}, time.Duration(*updateInterval)*time.Second, 1.2, true, wait.NeverStop)
103102
}
104103

@@ -119,7 +118,6 @@ func keepAlive(healthCheckFile string, healthCheckInterval int) {
119118
healthCheckFile, err)
120119
}
121120
}
122-
123121
}, time.Duration(healthCheckInterval)*time.Second)
124122
}
125123

@@ -140,7 +138,7 @@ func parseOvsSocket(ovsSocket *string) (string, string, error) {
140138
address = *ovsSocket
141139
} else {
142140
socketType = ovsSocketTokens[0]
143-
if socketType == TcpSocketType {
141+
if socketType == TCPSocketType {
144142
if len(ovsSocketTokens) != 3 {
145143
return "", "", fmt.Errorf("failed to parse OVS %s socket, must be in this format %s:<host>:<port>", socketType, socketType)
146144
}
@@ -166,8 +164,8 @@ func getOvsSocketValidator(socketType string) (func(string) error, error) {
166164
switch socketType {
167165
case UnixSocketType:
168166
return validateOvsUnixConnection, nil
169-
case TcpSocketType:
170-
return validateOvsTcpConnection, nil
167+
case TCPSocketType:
168+
return validateOvsTCPConnection, nil
171169
default:
172170
return nil, fmt.Errorf("unsupported ovs socket type: %s", socketType)
173171
}
@@ -189,8 +187,8 @@ func validateOvsUnixConnection(address string) error {
189187
return nil
190188
}
191189

192-
func validateOvsTcpConnection(address string) error {
193-
conn, err := net.DialTimeout(TcpSocketType, address, SocketConnectionTimeout)
190+
func validateOvsTCPConnection(address string) error {
191+
conn, err := net.DialTimeout(TCPSocketType, address, SocketConnectionTimeout)
194192
if err == nil {
195193
glog.Info("Successfully connected to TCP socket")
196194
conn.Close()

pkg/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"dario.cat/mergo"
2727
current "github.com/containernetworking/cni/pkg/types/100"
2828
"github.com/containernetworking/cni/pkg/version"
29+
2930
"github.com/k8snetworkplumbingwg/ovs-cni/pkg/types"
3031
"github.com/k8snetworkplumbingwg/ovs-cni/pkg/utils"
3132
)

pkg/marker/marker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ type Marker struct {
5353
func NewMarker(nodeName string, ovsSocket string) (*Marker, error) {
5454
config, err := rest.InClusterConfig()
5555
if err != nil {
56-
return nil, fmt.Errorf("Error while obtaining cluster config: %v", err)
56+
return nil, fmt.Errorf("error while obtaining cluster config: %v", err)
5757
}
5858

5959
clientset, err := kubernetes.NewForConfig(config)
6060
if err != nil {
61-
return nil, fmt.Errorf("Error building example clientset: %v", err)
61+
return nil, fmt.Errorf("error building example clientset: %v", err)
6262
}
6363

6464
ovsDriver, err := ovsdb.NewOvsDriver(ovsSocket)
6565
if err != nil {
66-
return nil, fmt.Errorf("Error creating the ovsdb connection: %v", err)
66+
return nil, fmt.Errorf("error creating the ovsdb connection: %v", err)
6767
}
6868

6969
return &Marker{clientset: clientset, nodeName: nodeName, ovsdb: ovsDriver}, nil

pkg/mirror-consumer/consumer.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func CmdAdd(args *skel.CmdArgs) error {
109109
}
110110

111111
for _, mirror := range netconf.Mirrors {
112-
113112
err = ovsDriver.CreateMirror(netconf.BrName, mirror.Name)
114113
if err != nil {
115114
return fmt.Errorf("cannot create mirror %s: %v ", mirror.Name, err)
@@ -178,7 +177,6 @@ func CmdDel(args *skel.CmdArgs) error {
178177
}
179178

180179
for _, mirror := range netconf.Mirrors {
181-
182180
mirrorExist, err := ovsDriver.IsMirrorPresent(mirror.Name)
183181
if err != nil {
184182
return err
@@ -238,7 +236,6 @@ func CmdCheck(args *skel.CmdArgs) error {
238236
}
239237

240238
for _, mirror := range netconf.Mirrors {
241-
242239
mirrorExist, err := ovsDriver.CheckMirrorConsumerWithPorts(mirror.Name, portUUID)
243240
if err != nil {
244241
return err

pkg/mirror-consumer/consumer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ var testFunc = func(version string) {
174174
testDel := func(conf string, mirrors []types.Mirror, r cnitypes.Result, ifName string, targetNs ns.NetNS) {
175175
By("Checking that mirrors are still in ovsdb")
176176
for _, mirror := range mirrors {
177-
mirrorDb, err := GetMirrorAttribute(mirror.Name, "name")
177+
mirrorDB, err := GetMirrorAttribute(mirror.Name, "name")
178178
Expect(err).NotTo(HaveOccurred())
179-
Expect(mirrorDb).To(Equal(mirror.Name))
179+
Expect(mirrorDB).To(Equal(mirror.Name))
180180
}
181181

182182
args := &skel.CmdArgs{

pkg/mirror-producer/producer.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ func CmdAdd(args *skel.CmdArgs) error {
109109
}
110110

111111
for _, mirror := range netconf.Mirrors {
112-
113112
err = ovsDriver.CreateMirror(netconf.BrName, mirror.Name)
114113
if err != nil {
115114
return fmt.Errorf("cannot create mirror %s: %v ", mirror.Name, err)
@@ -170,7 +169,6 @@ func CmdDel(args *skel.CmdArgs) error {
170169
}
171170

172171
for _, mirror := range netconf.Mirrors {
173-
174172
mirrorExist, err := ovsDriver.IsMirrorPresent(mirror.Name)
175173
if err != nil {
176174
return err

pkg/mirror-producer/producer_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ var testFunc = func(version string) {
174174
testDel := func(conf string, mirrors []types.Mirror, r cnitypes.Result, ifName string, targetNs ns.NetNS) {
175175
By("Checking that mirrors are still in ovsdb")
176176
for _, mirror := range mirrors {
177-
mirrorDb, err := GetMirrorAttribute(mirror.Name, "name")
177+
mirrorDB, err := GetMirrorAttribute(mirror.Name, "name")
178178
Expect(err).NotTo(HaveOccurred())
179-
Expect(mirrorDb).To(Equal(mirror.Name))
179+
Expect(mirrorDB).To(Equal(mirror.Name))
180180
}
181181

182182
args := &skel.CmdArgs{

0 commit comments

Comments
 (0)