Skip to content

Commit cbfd37d

Browse files
committed
BUILD/MEDIUM: update linters, use local version
1 parent 3029b7d commit cbfd37d

File tree

21 files changed

+91
-45
lines changed

21 files changed

+91
-45
lines changed

.github/workflows/actions.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
steps:
5959
- name: Check out code into the Go module directory
6060
uses: actions/checkout@v2
61+
- name: Set up Go
62+
uses: actions/setup-go@v2
63+
with:
64+
go-version: 1.19
6165
- uses: actions/cache@v2
6266
with:
6367
path: |
@@ -66,10 +70,9 @@ jobs:
6670
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
6771
restore-keys: |
6872
${{ runner.os }}-go-
69-
- name: golangci-lint
70-
uses: docker://ghcr.io/haproxytech/go-linter:1.33
71-
with:
72-
args: --timeout 5m
73+
- name: Lint
74+
run: |
75+
make lint
7376
build:
7477
name: build
7578
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
kubernetes-ingress
44
dist/
55
.code-generator/
6+
bin/golangci-lint

.gitlab-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ golangci_lint:
4242
stage: lint
4343
needs: []
4444
image:
45-
name: $CI_REGISTRY_GO/lint:1.33
45+
name: $CI_REGISTRY_GO/golang:1.19
4646
entrypoint: [""]
4747
tags:
4848
- go
4949
script:
50-
- golangci-lint run --enable-all --timeout=10m
50+
- make lint
5151
only:
5252
- merge_requests
5353
- branches

.golangci.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ linters-settings:
77
suggest-new: true
88
dupl:
99
threshold: 200
10+
revive:
11+
rules:
12+
- name: var-naming
13+
severity: warning
14+
disabled: true
15+
arguments:
16+
- [] # AllowList
17+
- [] # DenyList
1018

1119
linters:
1220
enable-all: true
@@ -32,3 +40,15 @@ linters:
3240
- nakedret
3341
- paralleltest
3442
- testpackage
43+
- varnamelen
44+
- tagliatelle
45+
- nonamedreturns
46+
- forcetypeassert
47+
- exhaustruct
48+
- ireturn
49+
- cyclop
50+
- stylecheck
51+
- errchkjson
52+
- forbidigo
53+
- nosnakecase
54+
- interfacebloat

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
PROJECT_PATH=${PWD}
22
TARGETPLATFORM?=linux/amd64
3+
GOLANGCI_LINT_VERSION=1.50.1
34

45
.PHONY: test
56
test:
@@ -21,8 +22,12 @@ doc:
2122

2223
.PHONY: lint
2324
lint:
25+
cd bin;GOLANGCI_LINT_VERSION=${GOLANGCI_LINT_VERSION} sh lint-check.sh
26+
bin/golangci-lint run --timeout 5m --color always --max-issues-per-linter 0 --max-same-issues 0
27+
28+
.PHONY: yaml-lint
29+
yaml-lint:
2430
docker run --rm -v $(pwd):/data cytopia/yamllint .
25-
golangci-lint run --color always --timeout 240s
2631

2732
.PHONY: example
2833
example:

bin/lint-check.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
V=$(./golangci-lint --version)
3+
4+
case "$V" in
5+
*$GOLANGCI_LINT_VERSION*) echo "$V" ;;
6+
*) curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(pwd) "v$GOLANGCI_LINT_VERSION" ;;
7+
esac

deploy/tests/e2e/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"crypto/tls"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net"
2525
"net/http"
2626
"os"
@@ -67,7 +67,7 @@ func newClient(host string, port int, tls bool) (*Client, error) {
6767
if port != 0 {
6868
dstPort = port
6969
}
70-
req, err := http.NewRequest("GET", fmt.Sprintf("%s://%s", scheme, host), nil)
70+
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("%s://%s", scheme, host), nil)
7171
if err != nil {
7272
return nil, err
7373
}
@@ -112,7 +112,7 @@ func NewHTTPSClient(host string, port ...int) (*Client, error) {
112112
return client, nil
113113
}
114114

115-
func (c *Client) Do() (res *http.Response, close func() error, err error) {
115+
func (c *Client) Do() (res *http.Response, closeFunc func() error, err error) {
116116
client := &http.Client{}
117117
if c.Transport != nil {
118118
client.Transport = c.Transport
@@ -130,7 +130,7 @@ func (c *Client) Do() (res *http.Response, close func() error, err error) {
130130
if err != nil {
131131
return
132132
}
133-
close = res.Body.Close
133+
closeFunc = res.Body.Close
134134
return
135135
}
136136

@@ -177,7 +177,7 @@ func ProxyProtoConn() (result []byte, err error) {
177177
return
178178
}
179179

180-
return ioutil.ReadAll(conn)
180+
return io.ReadAll(conn)
181181
}
182182

183183
func runtimeCommand(command string) (result []byte, err error) {

deploy/tests/e2e/utils.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"flag"
66
"fmt"
7-
"io/ioutil"
87
"os"
98
"os/exec"
109
"path/filepath"
@@ -17,11 +16,15 @@ import (
1716
"k8s.io/client-go/tools/clientcmd"
1817
)
1918

20-
var WaitDuration = 60 * time.Second
21-
var TickDuration = 2 * time.Second
19+
var (
20+
WaitDuration = 60 * time.Second
21+
TickDuration = 2 * time.Second
22+
)
2223

23-
var devModeFlag = flag.Bool("dev", false, "keep test environment after finishing")
24-
var devMode bool
24+
var (
25+
devModeFlag = flag.Bool("dev", false, "keep test environment after finishing")
26+
devMode bool
27+
)
2528

2629
type Test struct {
2730
namespace string
@@ -50,7 +53,7 @@ func NewTest() (test Test, err error) {
5053
return nil
5154
}}
5255
// TemplateDir
53-
test.templateDir, err = ioutil.TempDir("/tmp/", "haproxy-ic-test-tmpl")
56+
test.templateDir, err = os.MkdirTemp("/tmp/", "haproxy-ic-test-tmpl")
5457
if err != nil {
5558
return test, fmt.Errorf("error creating template dir: %w ", err)
5659
}
@@ -69,7 +72,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
6972
return err
7073
}
7174
}
72-
if file, err = ioutil.ReadFile(path); err != nil {
75+
if file, err = os.ReadFile(path); err != nil {
7376
return fmt.Errorf("error reading yaml file: %w", err)
7477
}
7578
// kubectl -n $NS apply -f -
@@ -80,7 +83,7 @@ func (t *Test) Apply(path string, namespace string, tmplData interface{}) error
8083
}
8184

8285
func (t *Test) processTemplate(path string, tmplData interface{}) (string, error) {
83-
file, err := ioutil.ReadFile(path)
86+
file, err := os.ReadFile(path)
8487
if err != nil {
8588
return "", fmt.Errorf("error reading yaml template: %w", err)
8689
}
@@ -91,13 +94,13 @@ func (t *Test) processTemplate(path string, tmplData interface{}) (string, error
9194
return "", fmt.Errorf("error parsing yaml template: %w", err)
9295
}
9396
yaml := filepath.Join(t.templateDir, t.namespace+time.Now().Format("2006-01-02-1504051111")+".yaml")
94-
return yaml, ioutil.WriteFile(yaml, result.Bytes(), 0600)
97+
return yaml, os.WriteFile(yaml, result.Bytes(), 0o600)
9598
}
9699

97100
func (t *Test) Delete(path string) error {
98101
var err error
99102
var file []byte
100-
if file, err = ioutil.ReadFile(path); err != nil {
103+
if file, err = os.ReadFile(path); err != nil {
101104
return fmt.Errorf("error reading yaml file: %w", err)
102105
}
103106
if out, errApply := t.execute(string(file), "kubectl", "delete", "-f", "-"); errApply != nil {

deploy/tests/integration/customresources/suite_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package customresources
1616

1717
import (
18-
"io/ioutil"
18+
"os"
1919
"path/filepath"
2020
"testing"
2121

@@ -47,7 +47,7 @@ type Test struct {
4747
}
4848

4949
func (suite *CustomResourceSuite) BeforeTest(suiteName, testName string) {
50-
tempDir, err := ioutil.TempDir("", "ut-"+testName+"-*")
50+
tempDir, err := os.MkdirTemp("", "ut-"+testName+"-*")
5151
if err != nil {
5252
suite.T().Fatalf("Suite '%s': Test '%s' : error : %s", suiteName, testName, err)
5353
}

pkg/annotations/cfgSnippet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var cfgSnippet struct {
3535
backends map[string]*cfgData
3636
}
3737

38-
//nolint: gochecknoinits
38+
//nolint:gochecknoinits
3939
func init() {
4040
cfgSnippet.global = &cfgData{}
4141
cfgSnippet.frontends = make(map[string]*cfgData)

pkg/annotations/global/syslogServer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ func (a *SyslogServers) GetName() string {
2929
// Input is multiple syslog lines
3030
// Each syslog line is a list of params
3131
// Example:
32-
// syslog-server: |
33-
// address:127.0.0.1, port:514, facility:local0
34-
// address:192.168.1.1, port:514, facility:local1
32+
//
33+
// syslog-server: |
34+
// address:127.0.0.1, port:514, facility:local0
35+
// address:192.168.1.1, port:514, facility:local1
3536
func (a *SyslogServers) Process(k store.K8s, annotations ...map[string]string) error {
3637
input := common.GetValue(a.GetName(), annotations...)
3738
a.stdout = false

pkg/annotations/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ func model(name, defaultNS string, crType int, k store.K8s, annotations ...map[s
104104
}
105105
return backend, nil
106106
}
107-
return nil, nil
107+
return nil, nil //nolint:nilnil
108108
}

pkg/controller/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (c *HAProxyController) auxCfgManager() (restart, reload bool) {
8383
info, errStat := os.Stat(c.haproxy.AuxCFGFile)
8484
var (
8585
modifTime int64
86-
auxCfgFile string = c.haproxy.AuxCFGFile
86+
auxCfgFile = c.haproxy.AuxCFGFile
8787
useAuxFile bool
8888
)
8989

pkg/haproxy/certs/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package certs
33
import (
44
"errors"
55
"fmt"
6-
"io/ioutil"
76
"os"
87
"path"
98
"strings"
@@ -183,7 +182,7 @@ func (c *certs) CertsUpdated() (reload bool) {
183182
}
184183

185184
func refreshCerts(certs map[string]*cert, certDir string) (removed bool) {
186-
files, err := ioutil.ReadDir(certDir)
185+
files, err := os.ReadDir(certDir)
187186
if err != nil {
188187
logger.Error(err)
189188
return false

pkg/haproxy/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (h HAProxy) Clean() {
8989
}
9090

9191
func logVersion(program string) {
92-
//nolint:gosec //checks of HAProxyBinary should be done in Env.Init() .
92+
// checks of HAProxyBinary should be done in Env.Init() .
9393
cmd := exec.Command(program, "-v")
9494
res, errExec := cmd.Output()
9595
if errExec != nil {

pkg/haproxy/process/s6-overlay.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (d *s6Control) Service(action string) (err error) {
2323
}
2424
var cmd *exec.Cmd
2525

26-
//nolint:gosec //checks on HAProxyBinary should be done in configuration module.
26+
// checks on HAProxyBinary should be done in configuration module.
2727
switch action {
2828
case "start":
2929
// no need to start it is up already (s6)

pkg/haproxy/rules/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type ruleInfo struct {
5555
// ruleState describes Rule creation
5656
type ruleState int
5757

58-
//nolint: golint,stylecheck
58+
//nolint:golint,stylecheck
5959
const (
6060
CREATED ruleState = 0
6161
TO_CREATE ruleState = 1

pkg/haproxy/rules/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package rules
44
// Rules will be evaluated by HAProxy in the defined order.
55
type Type int
66

7-
//nolint: golint,stylecheck
7+
//nolint:golint,stylecheck
88
const (
99
REQ_ACCEPT_CONTENT Type = iota
1010
REQ_INSPECT_DELAY

pkg/ingress/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
corev1 "k8s.io/api/core/v1"
77
)
88

9-
//nolint:golint,stylecheck
109
const CONTROLLER = "haproxy.org/ingress-controller"
1110

1211
var logger = utils.GetLogger()

pkg/k8s/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ import (
3636
var logger = utils.GetK8sAPILogger()
3737

3838
// TRACE_API outputs all k8s events received from k8s API
39-
//nolint golint
39+
//
40+
//nolint:golint
4041
const (
4142
TRACE_API = false
4243
CoreGroupVersion = "core.haproxy.org/v1alpha1"

pkg/utils/logging.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ const (
4444
//
4545
// if nil is sent, it won't be printed. This is useful for printing errors only
4646
// if they exist.
47+
//
4748
// ```
48-
// if err != nil {
49-
// logger.Error(err)
50-
// }
49+
//
50+
// if err != nil {
51+
// logger.Error(err)
52+
// }
53+
//
5154
// ```
5255
// can be shortened to
5356
// ```
@@ -80,11 +83,15 @@ type logger struct {
8083
FileName bool
8184
}
8285

83-
var logSingelton *logger
84-
var doOnce sync.Once
86+
var (
87+
logSingelton *logger
88+
doOnce sync.Once
89+
)
8590

86-
var k8sAPILogSingelton *logger
87-
var dok8sAPIOnce sync.Once
91+
var (
92+
k8sAPILogSingelton *logger
93+
dok8sAPIOnce sync.Once
94+
)
8895

8996
//nolint:golint // 'exported func GetLogger returns unexported type , which can be annoying to use' - this is deliberate here
9097
func GetLogger() *logger {

0 commit comments

Comments
 (0)