diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 4ed4a3542..2b249da47 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -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: diff --git a/.golangci.yml b/.golangci.yml index 743021e87..21151a677 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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: diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index ede5885d5..4c638d96c 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -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) diff --git a/pkg/middlewares/metrics/metrics.go b/pkg/middlewares/metrics/metrics.go index 3c278a9d2..f93ea0f8c 100644 --- a/pkg/middlewares/metrics/metrics.go +++ b/pkg/middlewares/metrics/metrics.go @@ -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 } diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index bc1f9a413..f83b37d45 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -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 } diff --git a/pkg/server/configurationwatcher_test.go b/pkg/server/configurationwatcher_test.go index cc909c81d..f353c1f90 100644 --- a/pkg/server/configurationwatcher_test.go +++ b/pkg/server/configurationwatcher_test.go @@ -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) {