Skip to content

Commit

Permalink
add golang lint (#3154)
Browse files Browse the repository at this point in the history
* add golang lint
  • Loading branch information
changluyi authored and bobz965 committed Sep 13, 2023
1 parent 545d64d commit 87779e1
Show file tree
Hide file tree
Showing 201 changed files with 3,460 additions and 3,520 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/build-x86-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,19 @@ jobs:
working-directory: ${{ env.E2E_DIR }}
run: make iptables-vpc-nat-gw-conformance-e2e

- name: kubectl ko log
if: failure()
run: |
make kubectl-ko-log
mv kubectl-ko-log.tar.gz iptables-vpc-nat-gw-conformance-e2e-ko-log.tar.gz
- name: upload kubectl ko log
uses: actions/upload-artifact@v3
if: failure()
with:
name: iptables-vpc-nat-gw-conformance-e2e-ko-log
path: iptables-vpc-nat-gw-conformance-e2e-ko-log.tar.gz

ovn-vpc-nat-gw-conformance-e2e:
name: OVN VPC NAT Gateway E2E
needs:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ jobs:
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --timeout 20m

args: --timeout 20m --verbose
# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true
44 changes: 44 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
run:
timeout: 15m

output:
sort-results: true

linters:
enable:
- gocritic
- gofumpt
- goimports
- misspell
- predeclared
- revive
- unconvert
- unused
- errcheck

issues:
max-same-issues: 0
exclude-rules:
- linters:
- gocritic
text: "appendAssign"
- linters:
- revive
text: "don't use an underscore in package name" # package name not change
- path: test/unittest/
linters:
- revive
text: "should not use dot imports" # ginkgo coding style
- linters:
- revive
text: "VpcDns should be VpcDNS" # api param not change
- linters:
- revive
text: "VpcDnsList should be VpcDNSList" # api param not change

linters-settings:
goimports:
local-prefixes: github.com/kubeovn/kube-ovn
gofumpt:
extra-rules: true

4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,10 @@ lint:
@GOOS=linux go vet ./...
@GOOS=linux gosec -exclude=G204,G306,G404,G601,G301 -exclude-dir=test -exclude-dir=pkg/client ./...

.PHONY: gofumpt
gofumpt: gofumpt
gofumpt -w -extra .

.PHONY: lint-windows
lint-windows:
@GOOS=windows go vet ./cmd/windows/...
Expand Down
8 changes: 4 additions & 4 deletions cmd/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
}
switch cniResponse.Protocol {
case kubeovnv1.ProtocolIPv4:
ip, route := assignV4Address(cniResponse.IpAddress, cniResponse.Gateway, mask)
ip, route := assignV4Address(cniResponse.IPAddress, cniResponse.Gateway, mask)
result.IPs = []*current.IPConfig{ip}
if route != nil {
result.Routes = []*types.Route{route}
}
result.Interfaces = []*current.Interface{&podIface}
case kubeovnv1.ProtocolIPv6:
ip, route := assignV6Address(cniResponse.IpAddress, cniResponse.Gateway, mask)
ip, route := assignV6Address(cniResponse.IPAddress, cniResponse.Gateway, mask)
result.IPs = []*current.IPConfig{ip}
if route != nil {
result.Routes = []*types.Route{route}
Expand All @@ -102,7 +102,7 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
_, netMask, _ = net.ParseCIDR(cidrBlock)
gwStr = ""
if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv4 {
ipStr := strings.Split(cniResponse.IpAddress, ",")[0]
ipStr := strings.Split(cniResponse.IPAddress, ",")[0]
if cniResponse.Gateway != "" {
gwStr = strings.Split(cniResponse.Gateway, ",")[0]
}
Expand All @@ -113,7 +113,7 @@ func generateCNIResult(cniResponse *request.CniResponse, netns string) current.R
result.Routes = append(result.Routes, route)
}
} else if util.CheckProtocol(cidrBlock) == kubeovnv1.ProtocolIPv6 {
ipStr := strings.Split(cniResponse.IpAddress, ",")[1]
ipStr := strings.Split(cniResponse.IPAddress, ",")[1]
if cniResponse.Gateway != "" {
gwStr = strings.Split(cniResponse.Gateway, ",")[1]
}
Expand Down
10 changes: 4 additions & 6 deletions cmd/daemon/cniserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ func mvCNIConf(configDir, configFile, confName string) error {
}

cniConfPath := filepath.Join(configDir, confName)
return os.WriteFile(cniConfPath, data, 0644)
return os.WriteFile(cniConfPath, data, 0o644)
}

func Retry(attempts int, sleep int, f func(configuration *daemon.Configuration) error, ctrl *daemon.Configuration) (err error) {
func Retry(attempts, sleep int, f func(configuration *daemon.Configuration) error, ctrl *daemon.Configuration) (err error) {
for i := 0; ; i++ {
err = f(ctrl)
if err == nil {
Expand Down Expand Up @@ -174,13 +174,11 @@ func initChassisAnno(cfg *daemon.Configuration) error {
if annoChassesName, ok := node.Annotations[util.ChassisAnnotation]; ok {
if annoChassesName == chassesName {
return nil
} else {
klog.Infof("chassis id changed, old: %s, new: %s", annoChassesName, chassesName)
}
klog.Infof("chassis id changed, old: %s, new: %s", annoChassesName, chassesName)
}
node.Annotations[util.ChassisAnnotation] = chassesName
patchPayloadTemplate :=
`[{
patchPayloadTemplate := `[{
"op": "%s",
"path": "/metadata/annotations",
"value": %s
Expand Down
Loading

0 comments on commit 87779e1

Please sign in to comment.