chore: update linter

This commit is contained in:
Ludovic Fernandez 2024-05-27 09:46:08 +02:00 committed by GitHub
parent 05828bab07
commit ed10bc5833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 30 additions and 34 deletions

View file

@ -7,7 +7,7 @@ on:
env:
GO_VERSION: '1.22'
GOLANGCI_LINT_VERSION: v1.57.0
GOLANGCI_LINT_VERSION: v1.59.0
MISSSPELL_VERSION: v0.4.1
jobs:

View file

@ -153,24 +153,16 @@ linters-settings:
- suite-dont-use-pkg
- require-error
- go-require
errcheck:
exclude-functions:
- fmt.Fprintln
linters:
enable-all: true
disable:
- deadcode # deprecated
- exhaustivestruct # deprecated
- golint # deprecated
- ifshort # deprecated
- interfacer # deprecated
- maligned # deprecated
- nosnakecase # deprecated
- scopelint # deprecated
- scopelint # deprecated
- structcheck # deprecated
- varcheck # deprecated
- execinquery # deprecated
- gomnd # deprecated
- sqlclosecheck # not relevant (SQL)
- rowserrcheck # not relevant (SQL)
- execinquery # not relevant (SQL)
- cyclop # duplicate of gocyclo
- lll # Not relevant
- gocyclo # FIXME must be fixed
@ -184,14 +176,14 @@ linters:
- gochecknoglobals
- wsl # Too strict
- nlreturn # Not relevant
- gomnd # Too strict
- mnd # Too strict
- stylecheck # skip because report issues related to some generated files.
- testpackage # Too strict
- tparallel # Not relevant
- paralleltest # Not relevant
- exhaustive # Not relevant
- exhaustruct # Not relevant
- goerr113 # Too strict
- err113 # Too strict
- wrapcheck # Too strict
- noctx # Too strict
- bodyclose # too many false-positive
@ -233,6 +225,8 @@ issues:
- goconst
- funlen
- godot
- canonicalheader
- fatcontext
- path: '(.+)_test.go'
text: ' always receives '
linters:

View file

@ -25,7 +25,7 @@ global_job_config:
- export "PATH=${GOPATH}/bin:${PATH}"
- mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin"
- export GOPROXY=https://proxy.golang.org,direct
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.57.0
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" v1.59.0
- curl -sSfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | bash -s -- -b "${GOPATH}/bin"
- checkout
- cache restore traefik-$(checksum go.sum)

View file

@ -131,10 +131,12 @@ func (m *metricsMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request)
capt, err := capture.FromContext(ctx)
if err != nil {
ctxMetrics := req.Context()
for i := 0; i < len(m.baseLabels); i += 2 {
ctx = log.With(ctx, log.Str(m.baseLabels[i], m.baseLabels[i+1]))
//nolint:fatcontext // false positive
ctxMetrics = log.With(ctxMetrics, log.Str(m.baseLabels[i], m.baseLabels[i+1]))
}
log.FromContext(ctx).WithError(err).Errorf("Could not get Capture")
log.FromContext(ctxMetrics).WithError(err).Errorf("Could not get Capture")
return
}

View file

@ -230,7 +230,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
certConfigs := make(map[string]*tls.CertAndStores)
for _, ingress := range ingresses {
ctx = log.With(ctx, log.Str("ingress", ingress.Name), log.Str("namespace", ingress.Namespace))
ctxIngress := log.With(ctx, log.Str("ingress", ingress.Name), log.Str("namespace", ingress.Namespace))
if !p.shouldProcessIngress(ingress, ingressClasses) {
continue
@ -238,24 +238,24 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
rtConfig, err := parseRouterConfig(ingress.Annotations)
if err != nil {
log.FromContext(ctx).Errorf("Failed to parse annotations: %v", err)
log.FromContext(ctxIngress).Errorf("Failed to parse annotations: %v", err)
continue
}
err = getCertificates(ctx, ingress, client, certConfigs)
err = getCertificates(ctxIngress, ingress, client, certConfigs)
if err != nil {
log.FromContext(ctx).Errorf("Error configuring TLS: %v", err)
log.FromContext(ctxIngress).Errorf("Error configuring TLS: %v", err)
}
if len(ingress.Spec.Rules) == 0 && ingress.Spec.DefaultBackend != nil {
if _, ok := conf.HTTP.Services["default-backend"]; ok {
log.FromContext(ctx).Error("The default backend already exists.")
log.FromContext(ctxIngress).Error("The default backend already exists.")
continue
}
service, err := p.loadService(client, ingress.Namespace, *ingress.Spec.DefaultBackend)
if err != nil {
log.FromContext(ctx).
log.FromContext(ctxIngress).
WithField("serviceName", ingress.Spec.DefaultBackend.Service.Name).
WithField("servicePort", ingress.Spec.DefaultBackend.Service.Port.String()).
Errorf("Cannot create service: %v", err)
@ -263,7 +263,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
}
if len(service.LoadBalancer.Servers) == 0 && !p.AllowEmptyServices {
log.FromContext(ctx).
log.FromContext(ctxIngress).
WithField("serviceName", ingress.Spec.DefaultBackend.Service.Name).
WithField("servicePort", ingress.Spec.DefaultBackend.Service.Port.String()).
Errorf("Skipping service: no endpoints found")
@ -282,7 +282,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
rt.TLS = rtConfig.Router.TLS
}
p.applyRouterTransform(ctx, rt, ingress)
p.applyRouterTransform(ctxIngress, rt, ingress)
conf.HTTP.Routers["default-router"] = rt
conf.HTTP.Services["default-backend"] = service
@ -292,7 +292,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
for _, rule := range ingress.Spec.Rules {
if err := p.updateIngressStatus(ingress, client); err != nil {
log.FromContext(ctx).Errorf("Error while updating ingress status: %v", err)
log.FromContext(ctxIngress).Errorf("Error while updating ingress status: %v", err)
}
if rule.HTTP == nil {
@ -302,7 +302,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
for _, pa := range rule.HTTP.Paths {
service, err := p.loadService(client, ingress.Namespace, pa.Backend)
if err != nil {
log.FromContext(ctx).
log.FromContext(ctxIngress).
WithField("serviceName", pa.Backend.Service.Name).
WithField("servicePort", pa.Backend.Service.Port.String()).
Errorf("Cannot create service: %v", err)
@ -310,7 +310,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
}
if len(service.LoadBalancer.Servers) == 0 && !p.AllowEmptyServices {
log.FromContext(ctx).
log.FromContext(ctxIngress).
WithField("serviceName", pa.Backend.Service.Name).
WithField("servicePort", pa.Backend.Service.Port.String()).
Errorf("Skipping service: no endpoints found")
@ -328,7 +328,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
rt := loadRouter(rule, pa, rtConfig, serviceName)
p.applyRouterTransform(ctx, rt, ingress)
p.applyRouterTransform(ctxIngress, rt, ingress)
routerKey := strings.TrimPrefix(provider.Normalize(ingress.Namespace+"-"+ingress.Name+"-"+rule.Host+pa.Path), "-")
@ -342,12 +342,12 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
continue
}
log.FromContext(ctx).Debugf("Multiple routers are defined with the same key %q, generating hashes to avoid conflicts", routerKey)
log.FromContext(ctxIngress).Debugf("Multiple routers are defined with the same key %q, generating hashes to avoid conflicts", routerKey)
for _, router := range conflictingRouters {
key, err := makeRouterKeyWithHash(routerKey, router.Rule)
if err != nil {
log.FromContext(ctx).Error(err)
log.FromContext(ctxIngress).Error(err)
continue
}

View file

@ -339,7 +339,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) {
// To load 5 new configs it would require 150ms (5 configs * 30ms).
// In 100ms, we should only have time to load 3 configs.
assert.LessOrEqual(t, publishedConfigCount, 3, "config was applied too many times")
assert.Greater(t, publishedConfigCount, 0, "config was not applied at least once")
assert.Positive(t, publishedConfigCount, "config was not applied at least once")
}
func TestListenProvidersSkipsEmptyConfigs(t *testing.T) {