chore: update linter
This commit is contained in:
parent
05828bab07
commit
ed10bc5833
6 changed files with 30 additions and 34 deletions
2
.github/workflows/validate.yaml
vendored
2
.github/workflows/validate.yaml
vendored
|
@ -7,7 +7,7 @@ on:
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GO_VERSION: '1.22'
|
GO_VERSION: '1.22'
|
||||||
GOLANGCI_LINT_VERSION: v1.57.0
|
GOLANGCI_LINT_VERSION: v1.59.0
|
||||||
MISSSPELL_VERSION: v0.4.1
|
MISSSPELL_VERSION: v0.4.1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
|
@ -153,24 +153,16 @@ linters-settings:
|
||||||
- suite-dont-use-pkg
|
- suite-dont-use-pkg
|
||||||
- require-error
|
- require-error
|
||||||
- go-require
|
- go-require
|
||||||
|
errcheck:
|
||||||
|
exclude-functions:
|
||||||
|
- fmt.Fprintln
|
||||||
linters:
|
linters:
|
||||||
enable-all: true
|
enable-all: true
|
||||||
disable:
|
disable:
|
||||||
- deadcode # deprecated
|
- execinquery # deprecated
|
||||||
- exhaustivestruct # deprecated
|
- gomnd # deprecated
|
||||||
- golint # deprecated
|
|
||||||
- ifshort # deprecated
|
|
||||||
- interfacer # deprecated
|
|
||||||
- maligned # deprecated
|
|
||||||
- nosnakecase # deprecated
|
|
||||||
- scopelint # deprecated
|
|
||||||
- scopelint # deprecated
|
|
||||||
- structcheck # deprecated
|
|
||||||
- varcheck # deprecated
|
|
||||||
- sqlclosecheck # not relevant (SQL)
|
- sqlclosecheck # not relevant (SQL)
|
||||||
- rowserrcheck # not relevant (SQL)
|
- rowserrcheck # not relevant (SQL)
|
||||||
- execinquery # not relevant (SQL)
|
|
||||||
- cyclop # duplicate of gocyclo
|
- cyclop # duplicate of gocyclo
|
||||||
- lll # Not relevant
|
- lll # Not relevant
|
||||||
- gocyclo # FIXME must be fixed
|
- gocyclo # FIXME must be fixed
|
||||||
|
@ -184,14 +176,14 @@ linters:
|
||||||
- gochecknoglobals
|
- gochecknoglobals
|
||||||
- wsl # Too strict
|
- wsl # Too strict
|
||||||
- nlreturn # Not relevant
|
- nlreturn # Not relevant
|
||||||
- gomnd # Too strict
|
- mnd # Too strict
|
||||||
- stylecheck # skip because report issues related to some generated files.
|
- stylecheck # skip because report issues related to some generated files.
|
||||||
- testpackage # Too strict
|
- testpackage # Too strict
|
||||||
- tparallel # Not relevant
|
- tparallel # Not relevant
|
||||||
- paralleltest # Not relevant
|
- paralleltest # Not relevant
|
||||||
- exhaustive # Not relevant
|
- exhaustive # Not relevant
|
||||||
- exhaustruct # Not relevant
|
- exhaustruct # Not relevant
|
||||||
- goerr113 # Too strict
|
- err113 # Too strict
|
||||||
- wrapcheck # Too strict
|
- wrapcheck # Too strict
|
||||||
- noctx # Too strict
|
- noctx # Too strict
|
||||||
- bodyclose # too many false-positive
|
- bodyclose # too many false-positive
|
||||||
|
@ -233,6 +225,8 @@ issues:
|
||||||
- goconst
|
- goconst
|
||||||
- funlen
|
- funlen
|
||||||
- godot
|
- godot
|
||||||
|
- canonicalheader
|
||||||
|
- fatcontext
|
||||||
- path: '(.+)_test.go'
|
- path: '(.+)_test.go'
|
||||||
text: ' always receives '
|
text: ' always receives '
|
||||||
linters:
|
linters:
|
||||||
|
|
|
@ -25,7 +25,7 @@ global_job_config:
|
||||||
- export "PATH=${GOPATH}/bin:${PATH}"
|
- export "PATH=${GOPATH}/bin:${PATH}"
|
||||||
- mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin"
|
- mkdir -vp "${SEMAPHORE_GIT_DIR}" "${GOPATH}/bin"
|
||||||
- export GOPROXY=https://proxy.golang.org,direct
|
- 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"
|
- curl -sSfL https://gist.githubusercontent.com/traefiker/6d7ac019c11d011e4f131bb2cca8900e/raw/goreleaser.sh | bash -s -- -b "${GOPATH}/bin"
|
||||||
- checkout
|
- checkout
|
||||||
- cache restore traefik-$(checksum go.sum)
|
- cache restore traefik-$(checksum go.sum)
|
||||||
|
|
|
@ -131,10 +131,12 @@ func (m *metricsMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request)
|
||||||
|
|
||||||
capt, err := capture.FromContext(ctx)
|
capt, err := capture.FromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ctxMetrics := req.Context()
|
||||||
for i := 0; i < len(m.baseLabels); i += 2 {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
|
|
||||||
certConfigs := make(map[string]*tls.CertAndStores)
|
certConfigs := make(map[string]*tls.CertAndStores)
|
||||||
for _, ingress := range ingresses {
|
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) {
|
if !p.shouldProcessIngress(ingress, ingressClasses) {
|
||||||
continue
|
continue
|
||||||
|
@ -238,24 +238,24 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
|
|
||||||
rtConfig, err := parseRouterConfig(ingress.Annotations)
|
rtConfig, err := parseRouterConfig(ingress.Annotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctx).Errorf("Failed to parse annotations: %v", err)
|
log.FromContext(ctxIngress).Errorf("Failed to parse annotations: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
err = getCertificates(ctx, ingress, client, certConfigs)
|
err = getCertificates(ctxIngress, ingress, client, certConfigs)
|
||||||
if err != nil {
|
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 len(ingress.Spec.Rules) == 0 && ingress.Spec.DefaultBackend != nil {
|
||||||
if _, ok := conf.HTTP.Services["default-backend"]; ok {
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
service, err := p.loadService(client, ingress.Namespace, *ingress.Spec.DefaultBackend)
|
service, err := p.loadService(client, ingress.Namespace, *ingress.Spec.DefaultBackend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctx).
|
log.FromContext(ctxIngress).
|
||||||
WithField("serviceName", ingress.Spec.DefaultBackend.Service.Name).
|
WithField("serviceName", ingress.Spec.DefaultBackend.Service.Name).
|
||||||
WithField("servicePort", ingress.Spec.DefaultBackend.Service.Port.String()).
|
WithField("servicePort", ingress.Spec.DefaultBackend.Service.Port.String()).
|
||||||
Errorf("Cannot create service: %v", err)
|
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 {
|
if len(service.LoadBalancer.Servers) == 0 && !p.AllowEmptyServices {
|
||||||
log.FromContext(ctx).
|
log.FromContext(ctxIngress).
|
||||||
WithField("serviceName", ingress.Spec.DefaultBackend.Service.Name).
|
WithField("serviceName", ingress.Spec.DefaultBackend.Service.Name).
|
||||||
WithField("servicePort", ingress.Spec.DefaultBackend.Service.Port.String()).
|
WithField("servicePort", ingress.Spec.DefaultBackend.Service.Port.String()).
|
||||||
Errorf("Skipping service: no endpoints found")
|
Errorf("Skipping service: no endpoints found")
|
||||||
|
@ -282,7 +282,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
rt.TLS = rtConfig.Router.TLS
|
rt.TLS = rtConfig.Router.TLS
|
||||||
}
|
}
|
||||||
|
|
||||||
p.applyRouterTransform(ctx, rt, ingress)
|
p.applyRouterTransform(ctxIngress, rt, ingress)
|
||||||
|
|
||||||
conf.HTTP.Routers["default-router"] = rt
|
conf.HTTP.Routers["default-router"] = rt
|
||||||
conf.HTTP.Services["default-backend"] = service
|
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 {
|
for _, rule := range ingress.Spec.Rules {
|
||||||
if err := p.updateIngressStatus(ingress, client); err != nil {
|
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 {
|
if rule.HTTP == nil {
|
||||||
|
@ -302,7 +302,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
for _, pa := range rule.HTTP.Paths {
|
for _, pa := range rule.HTTP.Paths {
|
||||||
service, err := p.loadService(client, ingress.Namespace, pa.Backend)
|
service, err := p.loadService(client, ingress.Namespace, pa.Backend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctx).
|
log.FromContext(ctxIngress).
|
||||||
WithField("serviceName", pa.Backend.Service.Name).
|
WithField("serviceName", pa.Backend.Service.Name).
|
||||||
WithField("servicePort", pa.Backend.Service.Port.String()).
|
WithField("servicePort", pa.Backend.Service.Port.String()).
|
||||||
Errorf("Cannot create service: %v", err)
|
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 {
|
if len(service.LoadBalancer.Servers) == 0 && !p.AllowEmptyServices {
|
||||||
log.FromContext(ctx).
|
log.FromContext(ctxIngress).
|
||||||
WithField("serviceName", pa.Backend.Service.Name).
|
WithField("serviceName", pa.Backend.Service.Name).
|
||||||
WithField("servicePort", pa.Backend.Service.Port.String()).
|
WithField("servicePort", pa.Backend.Service.Port.String()).
|
||||||
Errorf("Skipping service: no endpoints found")
|
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)
|
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), "-")
|
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
|
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 {
|
for _, router := range conflictingRouters {
|
||||||
key, err := makeRouterKeyWithHash(routerKey, router.Rule)
|
key, err := makeRouterKeyWithHash(routerKey, router.Rule)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctx).Error(err)
|
log.FromContext(ctxIngress).Error(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -339,7 +339,7 @@ func TestListenProvidersThrottleProviderConfigReload(t *testing.T) {
|
||||||
// To load 5 new configs it would require 150ms (5 configs * 30ms).
|
// To load 5 new configs it would require 150ms (5 configs * 30ms).
|
||||||
// In 100ms, we should only have time to load 3 configs.
|
// In 100ms, we should only have time to load 3 configs.
|
||||||
assert.LessOrEqual(t, publishedConfigCount, 3, "config was applied too many times")
|
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) {
|
func TestListenProvidersSkipsEmptyConfigs(t *testing.T) {
|
||||||
|
|
Loading…
Reference in a new issue