Skip to content

Commit 87779e1

Browse files
changluyizbb88888
authored andcommitted
add golang lint (#3154)
* add golang lint
1 parent 545d64d commit 87779e1

File tree

201 files changed

+3460
-3520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+3460
-3520
lines changed

.github/workflows/build-x86-image.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -1942,6 +1942,19 @@ jobs:
19421942
working-directory: ${{ env.E2E_DIR }}
19431943
run: make iptables-vpc-nat-gw-conformance-e2e
19441944

1945+
- name: kubectl ko log
1946+
if: failure()
1947+
run: |
1948+
make kubectl-ko-log
1949+
mv kubectl-ko-log.tar.gz iptables-vpc-nat-gw-conformance-e2e-ko-log.tar.gz
1950+
1951+
- name: upload kubectl ko log
1952+
uses: actions/upload-artifact@v3
1953+
if: failure()
1954+
with:
1955+
name: iptables-vpc-nat-gw-conformance-e2e-ko-log
1956+
path: iptables-vpc-nat-gw-conformance-e2e-ko-log.tar.gz
1957+
19451958
ovn-vpc-nat-gw-conformance-e2e:
19461959
name: OVN VPC NAT Gateway E2E
19471960
needs:

.github/workflows/lint.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
# working-directory: somedir
3939

4040
# Optional: golangci-lint command line arguments.
41-
args: --timeout 20m
42-
41+
args: --timeout 20m --verbose
4342
# Optional: show only new issues if it's a pull request. The default value is `false`.
4443
# only-new-issues: true

.golangci.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
run:
2+
timeout: 15m
3+
4+
output:
5+
sort-results: true
6+
7+
linters:
8+
enable:
9+
- gocritic
10+
- gofumpt
11+
- goimports
12+
- misspell
13+
- predeclared
14+
- revive
15+
- unconvert
16+
- unused
17+
- errcheck
18+
19+
issues:
20+
max-same-issues: 0
21+
exclude-rules:
22+
- linters:
23+
- gocritic
24+
text: "appendAssign"
25+
- linters:
26+
- revive
27+
text: "don't use an underscore in package name" # package name not change
28+
- path: test/unittest/
29+
linters:
30+
- revive
31+
text: "should not use dot imports" # ginkgo coding style
32+
- linters:
33+
- revive
34+
text: "VpcDns should be VpcDNS" # api param not change
35+
- linters:
36+
- revive
37+
text: "VpcDnsList should be VpcDNSList" # api param not change
38+
39+
linters-settings:
40+
goimports:
41+
local-prefixes: github.com/kubeovn/kube-ovn
42+
gofumpt:
43+
extra-rules: true
44+

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,10 @@ lint:
827827
@GOOS=linux go vet ./...
828828
@GOOS=linux gosec -exclude=G204,G306,G404,G601,G301 -exclude-dir=test -exclude-dir=pkg/client ./...
829829

830+
.PHONY: gofumpt
831+
gofumpt: gofumpt
832+
gofumpt -w -extra .
833+
830834
.PHONY: lint-windows
831835
lint-windows:
832836
@GOOS=windows go vet ./cmd/windows/...

cmd/cni/cni.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
8282
}
8383
switch cniResponse.Protocol {
8484
case kubeovnv1.ProtocolIPv4:
85-
ip, route := assignV4Address(cniResponse.IpAddress, cniResponse.Gateway, mask)
85+
ip, route := assignV4Address(cniResponse.IPAddress, cniResponse.Gateway, mask)
8686
result.IPs = []*current.IPConfig{ip}
8787
if route != nil {
8888
result.Routes = []*types.Route{route}
8989
}
9090
result.Interfaces = []*current.Interface{&podIface}
9191
case kubeovnv1.ProtocolIPv6:
92-
ip, route := assignV6Address(cniResponse.IpAddress, cniResponse.Gateway, mask)
92+
ip, route := assignV6Address(cniResponse.IPAddress, cniResponse.Gateway, mask)
9393
result.IPs = []*current.IPConfig{ip}
9494
if route != nil {
9595
result.Routes = []*types.Route{route}
@@ -102,7 +102,7 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
102102
_, netMask, _ = net.ParseCIDR(cidrBlock)
103103
gwStr = ""
104104
if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv4 {
105-
ipStr := strings.Split(cniResponse.IpAddress, ",")[0]
105+
ipStr := strings.Split(cniResponse.IPAddress, ",")[0]
106106
if cniResponse.Gateway != "" {
107107
gwStr = strings.Split(cniResponse.Gateway, ",")[0]
108108
}
@@ -113,7 +113,7 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
113113
result.Routes = append(result.Routes, route)
114114
}
115115
} else if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv6 {
116-
ipStr := strings.Split(cniResponse.IpAddress, ",")[1]
116+
ipStr := strings.Split(cniResponse.IPAddress, ",")[1]
117117
if cniResponse.Gateway != "" {
118118
gwStr = strings.Split(cniResponse.Gateway, ",")[1]
119119
}

cmd/daemon/cniserver.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ func mvCNIConf(configDir, configFile, confName string) error {
132132
}
133133

134134
cniConfPath := filepath.Join(configDir, confName)
135-
return os.WriteFile(cniConfPath, data, 0644)
135+
return os.WriteFile(cniConfPath, data, 0o644)
136136
}
137137

138-
func Retry(attempts int, sleep int, f func(configuration *daemon.Configuration) error, ctrl *daemon.Configuration) (err error) {
138+
func Retry(attempts, sleep int, f func(configuration *daemon.Configuration) error, ctrl *daemon.Configuration) (err error) {
139139
for i := 0; ; i++ {
140140
err = f(ctrl)
141141
if err == nil {
@@ -174,13 +174,11 @@ func initChassisAnno(cfg *daemon.Configuration) error {
174174
if annoChassesName, ok := node.Annotations[util.ChassisAnnotation]; ok {
175175
if annoChassesName == chassesName {
176176
return nil
177-
} else {
178-
klog.Infof("chassis id changed, old: %s, new: %s", annoChassesName, chassesName)
179177
}
178+
klog.Infof("chassis id changed, old: %s, new: %s", annoChassesName, chassesName)
180179
}
181180
node.Annotations[util.ChassisAnnotation] = chassesName
182-
patchPayloadTemplate :=
183-
`[{
181+
patchPayloadTemplate := `[{
184182
"op": "%s",
185183
"path": "/metadata/annotations",
186184
"value": %s

0 commit comments

Comments
 (0)