Skip to content

Commit

Permalink
BUILD/MEDIUM: update linter to 1.59.1 version
Browse files Browse the repository at this point in the history
  • Loading branch information
oktalz committed Jun 10, 2024
1 parent 3d72f8f commit 9f08246
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 58 deletions.
19 changes: 5 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
linters-settings:
govet:
check-shadowing: true
shadow: true
gocyclo:
min-complexity: 42
cyclop:
max-complexity: 42
maligned:
suggest-new: true
dupl:
threshold: 200
revive:
Expand All @@ -20,15 +18,13 @@ linters:
- ireturn
- dupl
- exhaustive
- exhaustivestruct
- funlen
- gci
- gochecknoglobals
- gocognit
- goconst
- gocyclo
- godot
- goerr113
- gomnd
- lll
- nestif
Expand All @@ -39,19 +35,14 @@ linters:
- paralleltest
- testpackage
- varnamelen
- nosnakecase
- exhaustruct
- nonamedreturns
- forcetypeassert
- golint #deprecated
- varcheck #deprecated
- ifshort #deprecated
- structcheck #deprecated
- maligned #deprecated
- scopelint #deprecated
- interfacer #deprecated
- deadcode #deprecated
- execinquery #deprecated
- depguard
- mnd
- inamedparam
- err113 # maybe tmp disable
issues:
exclude:
- "tag is not aligned, should be:" # this is harder to read
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PROJECT_PATH=${PWD}
TARGETPLATFORM?=linux/amd64
GOOS?=linux
GOARCH?=amd64
GOLANGCI_LINT_VERSION=1.54.2
GOLANGCI_LINT_VERSION=1.59.1

.PHONY: test
test:
Expand Down
2 changes: 1 addition & 1 deletion deploy/tests/e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (t *Test) GetK8sVersion() (major, minor int, err error) {
if err != nil {
return 0, 0, err
}
config, err := clientcmd.BuildConfigFromFlags("", fmt.Sprintf("%s/.kube/config", home))
config, err := clientcmd.BuildConfigFromFlags("", home+"/.kube/config")
if err != nil {
return 0, 0, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func (suite *CustomResourceSuite) TestGlobalCR() {
suite.globalCREvt.EventProcessed = eventProcessedChan
testController.EventChan <- suite.globalCREvt
<-eventProcessedChan
assert.Len(t, globals, 0, "No Global CR should be present")
assert.Len(t, logtrargets, 0, "No LogTargets should be present")
assert.Empty(t, globals, "No Global CR should be present")
assert.Empty(t, logtrargets, "No LogTargets should be present")
})

suite.StopController()
Expand Down
4 changes: 2 additions & 2 deletions pkg/annotations/service/checkHTTP.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package service

import (
"fmt"
"errors"
"strings"

"github.com/haproxytech/client-native/v5/models"
Expand Down Expand Up @@ -34,7 +34,7 @@ func (a *CheckHTTP) Process(k store.K8s, annotations ...map[string]string) error
checkHTTPParams := strings.Fields(strings.TrimSpace(input))
switch len(checkHTTPParams) {
case 0:
return fmt.Errorf("httpchk option: incorrect number of params")
return errors.New("httpchk option: incorrect number of params")
case 1:
params = &models.HttpchkParams{
URI: checkHTTPParams[0],
Expand Down
3 changes: 2 additions & 1 deletion pkg/annotations/service/loadbalance.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package service

import (
"errors"
"fmt"
"regexp"
"strconv"
Expand Down Expand Up @@ -49,7 +50,7 @@ func getParamsFromInput(value string) (*models.Balance, error) {
balance := &models.Balance{}
tokens := strings.Split(value, " ")
if len(tokens) == 0 {
return nil, fmt.Errorf("missing algorithm name")
return nil, errors.New("missing algorithm name")
}

reg := regexp.MustCompile(`(\(|\))`)
Expand Down
1 change: 0 additions & 1 deletion pkg/gateways/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ func (statusMgr *StatusManagerImpl) UpdateStatusTCPRoutes(routesStatusRecords []
}

for _, parentStatusRecord := range tcprouteStatusRecord.parentsStatusesRecords {
parentStatusRecord := parentStatusRecord
conditions := []metav1.Condition{}
routeParentStatus := v1alpha2.RouteParentStatus{
ControllerName: v1alpha2.GatewayController(statusMgr.gatewayControllerName),
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (handler HTTPS) enableSSLPassthrough(h haproxy.HAProxy) (err error) {
}),
h.BackendSwitchingRuleCreate(h.FrontSSL, models.BackendSwitchingRule{
Index: utils.PtrInt64(0),
Name: fmt.Sprintf("%%[var(txn.sni_match),field(1,.)]"),
Name: "%[var(txn.sni_match),field(1,.)]",
}),
handler.toggleSSLPassthrough(true, h))
return errors.Result()
Expand Down
2 changes: 1 addition & 1 deletion pkg/handler/tcp-services.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (handler TCPServices) Update(k store.K8s, h haproxy.HAProxy, a annotations.
if port == "log-format-tcp" {
continue
}
frontendName := fmt.Sprintf("tcp-%s", port)
frontendName := "tcp-" + port
p, err = handler.parseTCPService(k, tcpSvcAnn)
if err != nil {
logger.Error(err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/haproxy/api/backend.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package api

import (
"fmt"
"errors"

"github.com/haproxytech/client-native/v5/models"
"github.com/haproxytech/config-parser/v5/types"
Expand Down Expand Up @@ -197,7 +197,7 @@ func (c *clientNative) BackendSwitchingRuleDeleteAll(frontend string) (err error
if err != nil {
return
}
for i := 0; i < len(switchingRules); i++ {
for range len(switchingRules) {
if err = configuration.DeleteBackendSwitchingRule(0, frontend, c.activeTransaction, 0); err != nil {
break
}
Expand Down Expand Up @@ -232,7 +232,7 @@ func (c *clientNative) BackendServersGet(backendName string) (models.Servers, er
func (c *clientNative) RefreshBackends() (deleted []string, err error) {
backends, errAPI := c.BackendsGet()
if errAPI != nil {
err = fmt.Errorf("unable to get configured backends")
err = errors.New("unable to get configured backends")
return
}
for _, backend := range backends {
Expand Down
4 changes: 2 additions & 2 deletions pkg/haproxy/api/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c *clientNative) runRaw(runtime runtime.Runtime, sb strings.Builder, backe
pmm.UpdateRuntimeMetrics(metrics.ObjectServer, err)
return err
}
for i := 0; i < len(result); i++ {
for i := range len(result) {
if len(result[i]) > 5 {
switch result[i][1:5] {
case "[3]:", "[2]:", "[1]:", "[0]:":
Expand Down Expand Up @@ -138,7 +138,7 @@ func (c *clientNative) SetMapContent(mapFile string, payload []string) error {
err = fmt.Errorf("error getting map path: %w", err)
return err
}
for i := 0; i < len(payload); i++ {
for i := range len(payload) {
_, err = runtime.ExecuteRaw(fmt.Sprintf("add map @%s %s <<\n%s\n", mapVer, mapPath, payload[i]))
pmm.UpdateRuntimeMetrics(metrics.ObjectMap, err)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/haproxy/certs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ type SecretCtx struct {
func New(envParam Env) (Certificates, error) { //nolint:ireturn
env = envParam
if env.FrontendDir == "" {
return nil, fmt.Errorf("empty name for Frontend Cert Directory")
return nil, errors.New("empty name for Frontend Cert Directory")
}
if env.BackendDir == "" {
return nil, fmt.Errorf("empty name for Backend Cert Directory")
return nil, errors.New("empty name for Backend Cert Directory")
}
if env.CaDir == "" {
return nil, fmt.Errorf("empty name for CA Cert Directory")
return nil, errors.New("empty name for CA Cert Directory")
}
if env.TCPCRDir == "" {
return nil, fmt.Errorf("empty name for TCP Cert Directory")
return nil, errors.New("empty name for TCP Cert Directory")
}
return &certs{
frontend: make(map[string]*cert),
Expand Down Expand Up @@ -227,15 +227,15 @@ func writeSecret(secret *store.Secret, c *cert, privateKeyNull bool) (err error)
if !crtOk {
return fmt.Errorf("certificate missing in %s/%s", secret.Namespace, secret.Name)
}
c.path = fmt.Sprintf("%s.pem", c.path)
c.path += ".pem"
return writeCert(c.path, []byte(""), crtValue)
}
for _, k := range []string{"tls", "rsa", "ecdsa", "dsa"} {
keyValue, keyOk = secret.Data[k+".key"]
crtValue, crtOk = secret.Data[k+".crt"]
if keyOk && crtOk {
pemOk = true
certPath = fmt.Sprintf("%s.pem", c.path)
certPath = c.path + ".pem"
if k != "tls" {
// HAProxy "cert bundle"
certPath = fmt.Sprintf("%s.%s", certPath, k)
Expand Down
3 changes: 2 additions & 1 deletion pkg/haproxy/env/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package env

import (
"errors"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -62,7 +63,7 @@ func (env *Env) Init(osArgs utils.OSArgs) (err error) {
}
for _, dir := range []string{env.CfgDir, env.RuntimeDir, env.StateDir} {
if dir == "" {
return fmt.Errorf("failed to init controller config: missing config directories")
return errors.New("failed to init controller config: missing config directories")
}
}
// Binary and main files
Expand Down
3 changes: 1 addition & 2 deletions pkg/haproxy/maps/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package maps

import (
"errors"
"fmt"
"hash/fnv"
"os"
"path"
Expand Down Expand Up @@ -82,7 +81,7 @@ func (mf *mapFile) getContent() (result []string, hash uint64) {

func New(dir string, persistentMaps []Name) (Maps, error) { //nolint:ireturn
if dir == "" {
return nil, fmt.Errorf("empty name for map directory")
return nil, errors.New("empty name for map directory")
}
mapDir = dir
var maps mapFiles = make(map[Name]*mapFile, len(persistentMaps))
Expand Down
2 changes: 1 addition & 1 deletion pkg/haproxy/process/direct-control.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (d *directControl) Service(action string) (err error) {
// hold information about a running Master HAproxy process
process, processErr := haproxyProcess(d.Env.PIDFile)

masterSocketArg := fmt.Sprintf("%s,level,admin", d.Env.MasterSocket)
masterSocketArg := d.Env.MasterSocket + ",level,admin"

//nolint:gosec //checks on HAProxyBinary should be done in configuration module.
switch action {
Expand Down
3 changes: 2 additions & 1 deletion pkg/haproxy/rules/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package rules

import (
"encoding/json"
"errors"
"fmt"

"github.com/haproxytech/client-native/v5/models"
Expand Down Expand Up @@ -73,7 +74,7 @@ func (rules *List) Add(rule Rule) {

func (r SectionRules) AddRule(frontend string, rule Rule, ingressRule bool) error {
if rule == nil || frontend == "" {
return fmt.Errorf("invalid params")
return errors.New("invalid params")
}
// Create frontend ruleSet
ftRuleSet, ok := r[frontend]
Expand Down
4 changes: 2 additions & 2 deletions pkg/haproxy/rules/reqAcceptContent.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rules

import (
"fmt"
"errors"

"github.com/haproxytech/client-native/v5/models"

Expand All @@ -17,7 +17,7 @@ func (r ReqAcceptContent) GetType() Type {

func (r ReqAcceptContent) Create(client api.HAProxyClient, frontend *models.Frontend, ingressACL string) error {
if frontend.Mode == "http" {
return fmt.Errorf("tcp accept-content rule is only available in TCP frontends")
return errors.New("tcp accept-content rule is only available in TCP frontends")
}
tcpRule := models.TCPRequestRule{
Index: utils.PtrInt64(0),
Expand Down
4 changes: 2 additions & 2 deletions pkg/haproxy/rules/reqInspectDelay.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rules

import (
"fmt"
"errors"

"github.com/haproxytech/client-native/v5/models"

Expand All @@ -19,7 +19,7 @@ func (r ReqInspectDelay) GetType() Type {

func (r ReqInspectDelay) Create(client api.HAProxyClient, frontend *models.Frontend, ingressACL string) error {
if frontend.Mode == "http" {
return fmt.Errorf("tcp inspect-delay rule is only available in TCP frontends")
return errors.New("tcp inspect-delay rule is only available in TCP frontends")
}
tcpRule := models.TCPRequestRule{
Type: "inspect-delay",
Expand Down
4 changes: 2 additions & 2 deletions pkg/haproxy/rules/reqPathRewrite.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rules

import (
"fmt"
"errors"

"github.com/haproxytech/client-native/v5/models"

Expand All @@ -20,7 +20,7 @@ func (r ReqPathRewrite) GetType() Type {

func (r ReqPathRewrite) Create(client api.HAProxyClient, frontend *models.Frontend, ingressACL string) error {
if frontend.Mode == "tcp" {
return fmt.Errorf("SSL redirect cannot be configured in TCP mode")
return errors.New("SSL redirect cannot be configured in TCP mode")
}
httpRule := models.HTTPRequestRule{
Index: utils.PtrInt64(0),
Expand Down
3 changes: 2 additions & 1 deletion pkg/haproxy/rules/reqRatelimit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rules

import (
"errors"
"fmt"

"github.com/haproxytech/client-native/v5/models"
Expand All @@ -21,7 +22,7 @@ func (r ReqRateLimit) GetType() Type {

func (r ReqRateLimit) Create(client api.HAProxyClient, frontend *models.Frontend, ingressACL string) error {
if frontend.Mode == "tcp" {
return fmt.Errorf("request Track cannot be configured in TCP mode")
return errors.New("request Track cannot be configured in TCP mode")
}
httpRule := models.HTTPRequestRule{
Index: utils.PtrInt64(0),
Expand Down
3 changes: 2 additions & 1 deletion pkg/haproxy/rules/reqRequestRedirect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package rules

import (
"errors"
"fmt"

"github.com/haproxytech/client-native/v5/models"
Expand All @@ -23,7 +24,7 @@ func (r RequestRedirect) GetType() Type {

func (r RequestRedirect) Create(client api.HAProxyClient, frontend *models.Frontend, ingressACL string) error {
if frontend.Mode == "tcp" {
return fmt.Errorf("request redirection cannot be configured in TCP mode")
return errors.New("request redirection cannot be configured in TCP mode")
}
var rule string
if r.SSLRedirect {
Expand Down
4 changes: 2 additions & 2 deletions pkg/haproxy/rules/reqRequestRedirectQuic.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package rules

import (
"fmt"
"errors"

"github.com/haproxytech/client-native/v5/models"

Expand All @@ -17,7 +17,7 @@ func (r RequestRedirectQuic) GetType() Type {

func (r RequestRedirectQuic) Create(client api.HAProxyClient, frontend *models.Frontend, ingressACL string) error {
if frontend.Mode == "tcp" {
return fmt.Errorf("request redirection cannot be configured in TCP mode")
return errors.New("request redirection cannot be configured in TCP mode")
}

httpRule := models.HTTPRequestRule{
Expand Down
Loading

0 comments on commit 9f08246

Please sign in to comment.