From b67a7215f66e0cbf609e7d8a8300620c1dceb26d Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Fri, 21 Aug 2020 11:12:04 +0200 Subject: [PATCH] chore: update linter. --- .golangci.toml | 1 + build.Dockerfile | 2 +- integration/try/try.go | 2 +- pkg/anonymize/anonymize_config_test.go | 7 +++---- pkg/config/static/static_config.go | 4 ++-- pkg/metrics/pilot.go | 6 +++--- pkg/metrics/prometheus.go | 8 ++++---- pkg/middlewares/accesslog/logdata.go | 6 +++--- .../requestdecorator/request_decorator_test.go | 3 +-- pkg/provider/docker/docker.go | 2 +- pkg/provider/docker/swarm_test.go | 13 ++++++------- pkg/provider/ecs/config.go | 1 - pkg/provider/kubernetes/crd/kubernetes_test.go | 3 +-- pkg/provider/kubernetes/ingress/client_mock_test.go | 9 ++++----- pkg/provider/kubernetes/ingress/kubernetes.go | 13 ++++++------- pkg/version/version.go | 2 +- 16 files changed, 38 insertions(+), 44 deletions(-) diff --git a/.golangci.toml b/.golangci.toml index 14307c954..9e939601c 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -54,6 +54,7 @@ "nestif", # Too many false-positive. "noctx", # Too strict "exhaustive", # Too strict + "nlreturn", # Too strict ] [issues] diff --git a/build.Dockerfile b/build.Dockerfile index a8ca337eb..b0999f841 100644 --- a/build.Dockerfile +++ b/build.Dockerfile @@ -19,7 +19,7 @@ RUN mkdir -p /usr/local/bin \ && chmod +x /usr/local/bin/go-bindata # Download golangci-lint binary to bin folder in $GOPATH -RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.28.0 +RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.30.0 # Download misspell binary to bin folder in $GOPATH RUN curl -sfL https://raw.githubusercontent.com/client9/misspell/master/install-misspell.sh | bash -s -- -b $GOPATH/bin v0.3.4 diff --git a/integration/try/try.go b/integration/try/try.go index 98231626b..3922f7f14 100644 --- a/integration/try/try.go +++ b/integration/try/try.go @@ -11,7 +11,7 @@ import ( ) const ( - // CITimeoutMultiplier is the multiplier for all timeout in the CI + // CITimeoutMultiplier is the multiplier for all timeout in the CI. CITimeoutMultiplier = 3 maxInterval = 5 * time.Second ) diff --git a/pkg/anonymize/anonymize_config_test.go b/pkg/anonymize/anonymize_config_test.go index f65f6a825..df88d5bbd 100644 --- a/pkg/anonymize/anonymize_config_test.go +++ b/pkg/anonymize/anonymize_config_test.go @@ -8,7 +8,6 @@ import ( "github.com/containous/traefik/v2/pkg/config/static" "github.com/containous/traefik/v2/pkg/ping" "github.com/containous/traefik/v2/pkg/provider/acme" - acmeprovider "github.com/containous/traefik/v2/pkg/provider/acme" "github.com/containous/traefik/v2/pkg/provider/docker" "github.com/containous/traefik/v2/pkg/provider/file" "github.com/containous/traefik/v2/pkg/provider/kubernetes/crd" @@ -96,11 +95,11 @@ func TestDo_globalConfiguration(t *testing.T) { CAServer: "CAServer", Storage: "Storage", KeyType: "MyKeyType", - DNSChallenge: &acmeprovider.DNSChallenge{Provider: "DNSProvider"}, - HTTPChallenge: &acmeprovider.HTTPChallenge{ + DNSChallenge: &acme.DNSChallenge{Provider: "DNSProvider"}, + HTTPChallenge: &acme.HTTPChallenge{ EntryPoint: "MyEntryPoint", }, - TLSChallenge: &acmeprovider.TLSChallenge{}, + TLSChallenge: &acme.TLSChallenge{}, }, }, } diff --git a/pkg/config/static/static_config.go b/pkg/config/static/static_config.go index 4f3162595..40e2ef9a8 100644 --- a/pkg/config/static/static_config.go +++ b/pkg/config/static/static_config.go @@ -38,7 +38,7 @@ import ( ) const ( - // DefaultInternalEntryPointName the name of the default internal entry point + // DefaultInternalEntryPointName the name of the default internal entry point. DefaultInternalEntryPointName = "traefik" // DefaultGraceTimeout controls how long Traefik serves pending requests @@ -48,7 +48,7 @@ const ( // DefaultIdleTimeout before closing an idle connection. DefaultIdleTimeout = 180 * time.Second - // DefaultAcmeCAServer is the default ACME API endpoint + // DefaultAcmeCAServer is the default ACME API endpoint. DefaultAcmeCAServer = "https://acme-v02.api.letsencrypt.org/directory" ) diff --git a/pkg/metrics/pilot.go b/pkg/metrics/pilot.go index 8bd192a5a..9ed199246 100644 --- a/pkg/metrics/pilot.go +++ b/pkg/metrics/pilot.go @@ -10,21 +10,21 @@ import ( ) const ( - // server meta information + // server meta information. pilotConfigPrefix = "config" pilotConfigReloadsTotalName = pilotConfigPrefix + "ReloadsTotal" pilotConfigReloadsFailuresTotalName = pilotConfigPrefix + "ReloadsFailureTotal" pilotConfigLastReloadSuccessName = pilotConfigPrefix + "LastReloadSuccess" pilotConfigLastReloadFailureName = pilotConfigPrefix + "LastReloadFailure" - // entry point + // entry point. pilotEntryPointPrefix = "entrypoint" pilotEntryPointReqsTotalName = pilotEntryPointPrefix + "RequestsTotal" pilotEntryPointReqsTLSTotalName = pilotEntryPointPrefix + "RequestsTLSTotal" pilotEntryPointReqDurationName = pilotEntryPointPrefix + "RequestDurationSeconds" pilotEntryPointOpenConnsName = pilotEntryPointPrefix + "OpenConnections" - // service level + // service level. pilotServicePrefix = "service" pilotServiceReqsTotalName = pilotServicePrefix + "RequestsTotal" pilotServiceReqsTLSTotalName = pilotServicePrefix + "RequestsTLSTotal" diff --git a/pkg/metrics/prometheus.go b/pkg/metrics/prometheus.go index 4cebea505..9c46736a2 100644 --- a/pkg/metrics/prometheus.go +++ b/pkg/metrics/prometheus.go @@ -18,17 +18,17 @@ import ( ) const ( - // MetricNamePrefix prefix of all metric names + // MetricNamePrefix prefix of all metric names. MetricNamePrefix = "traefik_" - // server meta information + // server meta information. metricConfigPrefix = MetricNamePrefix + "config_" configReloadsTotalName = metricConfigPrefix + "reloads_total" configReloadsFailuresTotalName = metricConfigPrefix + "reloads_failure_total" configLastReloadSuccessName = metricConfigPrefix + "last_reload_success" configLastReloadFailureName = metricConfigPrefix + "last_reload_failure" - // entry point + // entry point. metricEntryPointPrefix = MetricNamePrefix + "entrypoint_" entryPointReqsTotalName = metricEntryPointPrefix + "requests_total" entryPointReqsTLSTotalName = metricEntryPointPrefix + "requests_tls_total" @@ -37,7 +37,7 @@ const ( // service level. - // MetricServicePrefix prefix of all service metric names + // MetricServicePrefix prefix of all service metric names. MetricServicePrefix = MetricNamePrefix + "service_" serviceReqsTotalName = MetricServicePrefix + "requests_total" serviceReqsTLSTotalName = MetricServicePrefix + "requests_tls_total" diff --git a/pkg/middlewares/accesslog/logdata.go b/pkg/middlewares/accesslog/logdata.go index 5347d1b8e..37f415ed5 100644 --- a/pkg/middlewares/accesslog/logdata.go +++ b/pkg/middlewares/accesslog/logdata.go @@ -19,7 +19,7 @@ const ( ServiceName = "ServiceName" // ServiceURL is the map key used for the URL of the Traefik backend. ServiceURL = "ServiceURL" - // ServiceAddr is the map key used for the IP:port of the Traefik backend (extracted from BackendURL) + // ServiceAddr is the map key used for the IP:port of the Traefik backend (extracted from BackendURL). ServiceAddr = "ServiceAddr" // ClientAddr is the map key used for the remote address in its original form (usually IP:port). @@ -46,9 +46,9 @@ const ( RequestScheme = "RequestScheme" // RequestContentSize is the map key used for the number of bytes in the request entity (a.k.a. body) sent by the client. RequestContentSize = "RequestContentSize" - // RequestRefererHeader is the Referer header in the request + // RequestRefererHeader is the Referer header in the request. RequestRefererHeader = "request_Referer" - // RequestUserAgentHeader is the User-Agent header in the request + // RequestUserAgentHeader is the User-Agent header in the request. RequestUserAgentHeader = "request_User-Agent" // OriginDuration is the map key used for the time taken by the origin server ('upstream') to return its response. OriginDuration = "OriginDuration" diff --git a/pkg/middlewares/requestdecorator/request_decorator_test.go b/pkg/middlewares/requestdecorator/request_decorator_test.go index a757c1f60..8c6550e3c 100644 --- a/pkg/middlewares/requestdecorator/request_decorator_test.go +++ b/pkg/middlewares/requestdecorator/request_decorator_test.go @@ -4,9 +4,8 @@ import ( "net/http" "testing" - "github.com/containous/traefik/v2/pkg/types" - "github.com/containous/traefik/v2/pkg/testhelpers" + "github.com/containous/traefik/v2/pkg/types" "github.com/stretchr/testify/assert" ) diff --git a/pkg/provider/docker/docker.go b/pkg/provider/docker/docker.go index 0d4b3c7bc..49f51eded 100644 --- a/pkg/provider/docker/docker.go +++ b/pkg/provider/docker/docker.go @@ -33,7 +33,7 @@ import ( ) const ( - // DockerAPIVersion is a constant holding the version of the Provider API traefik will use + // DockerAPIVersion is a constant holding the version of the Provider API traefik will use. DockerAPIVersion = "1.24" // SwarmAPIVersion is a constant holding the version of the Provider API traefik will use. diff --git a/pkg/provider/docker/swarm_test.go b/pkg/provider/docker/swarm_test.go index 45d7957a2..541af22f2 100644 --- a/pkg/provider/docker/swarm_test.go +++ b/pkg/provider/docker/swarm_test.go @@ -7,7 +7,6 @@ import ( "time" "github.com/davecgh/go-spew/spew" - docker "github.com/docker/docker/api/types" dockertypes "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" dockerclient "github.com/docker/docker/client" @@ -36,7 +35,7 @@ func TestListTasks(t *testing.T) { tasks []swarm.Task isGlobalSVC bool expectedTasks []string - networks map[string]*docker.NetworkResource + networks map[string]*dockertypes.NetworkResource }{ { service: swarmService(serviceName("container")), @@ -71,7 +70,7 @@ func TestListTasks(t *testing.T) { "container.1", "container.4", }, - networks: map[string]*docker.NetworkResource{ + networks: map[string]*dockertypes.NetworkResource{ "1": { Name: "foo", }, @@ -300,7 +299,7 @@ func TestSwarmTaskParsing(t *testing.T) { tasks []swarm.Task isGlobalSVC bool expected map[string]dockerData - networks map[string]*docker.NetworkResource + networks map[string]*dockertypes.NetworkResource }{ { service: swarmService(serviceName("container")), @@ -321,7 +320,7 @@ func TestSwarmTaskParsing(t *testing.T) { Name: "container.3", }, }, - networks: map[string]*docker.NetworkResource{ + networks: map[string]*dockertypes.NetworkResource{ "1": { Name: "foo", }, @@ -346,7 +345,7 @@ func TestSwarmTaskParsing(t *testing.T) { Name: "container.id3", }, }, - networks: map[string]*docker.NetworkResource{ + networks: map[string]*dockertypes.NetworkResource{ "1": { Name: "foo", }, @@ -384,7 +383,7 @@ func TestSwarmTaskParsing(t *testing.T) { }, }, }, - networks: map[string]*docker.NetworkResource{ + networks: map[string]*dockertypes.NetworkResource{ "1": { Name: "vlan", }, diff --git a/pkg/provider/ecs/config.go b/pkg/provider/ecs/config.go index c274082b6..2bb0ad712 100644 --- a/pkg/provider/ecs/config.go +++ b/pkg/provider/ecs/config.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/aws/aws-sdk-go/service/ec2" - "github.com/containous/traefik/v2/pkg/config/dynamic" "github.com/containous/traefik/v2/pkg/config/label" "github.com/containous/traefik/v2/pkg/log" diff --git a/pkg/provider/kubernetes/crd/kubernetes_test.go b/pkg/provider/kubernetes/crd/kubernetes_test.go index eba2ad1b3..e8d68affb 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_test.go +++ b/pkg/provider/kubernetes/crd/kubernetes_test.go @@ -4,12 +4,11 @@ import ( "context" "testing" - corev1 "k8s.io/api/core/v1" - "github.com/containous/traefik/v2/pkg/config/dynamic" "github.com/containous/traefik/v2/pkg/provider" "github.com/containous/traefik/v2/pkg/tls" "github.com/stretchr/testify/assert" + corev1 "k8s.io/api/core/v1" ) var _ provider.Provider = (*Provider)(nil) diff --git a/pkg/provider/kubernetes/ingress/client_mock_test.go b/pkg/provider/kubernetes/ingress/client_mock_test.go index 410c96d52..3ef9093db 100644 --- a/pkg/provider/kubernetes/ingress/client_mock_test.go +++ b/pkg/provider/kubernetes/ingress/client_mock_test.go @@ -8,14 +8,13 @@ import ( "github.com/hashicorp/go-version" corev1 "k8s.io/api/core/v1" extensionsv1beta1 "k8s.io/api/extensions/v1beta1" - "k8s.io/api/networking/v1beta1" networkingv1beta1 "k8s.io/api/networking/v1beta1" ) var _ Client = (*clientMock)(nil) type clientMock struct { - ingresses []*v1beta1.Ingress + ingresses []*networkingv1beta1.Ingress services []*corev1.Service secrets []*corev1.Secret endpoints []*corev1.Endpoints @@ -51,7 +50,7 @@ func newClientMock(serverVersion string, paths ...string) clientMock { c.secrets = append(c.secrets, o) case *corev1.Endpoints: c.endpoints = append(c.endpoints, o) - case *v1beta1.Ingress: + case *networkingv1beta1.Ingress: c.ingresses = append(c.ingresses, o) case *extensionsv1beta1.Ingress: ing, err := extensionsToNetworking(o) @@ -70,7 +69,7 @@ func newClientMock(serverVersion string, paths ...string) clientMock { return c } -func (c clientMock) GetIngresses() []*v1beta1.Ingress { +func (c clientMock) GetIngresses() []*networkingv1beta1.Ingress { return c.ingresses } @@ -126,6 +125,6 @@ func (c clientMock) WatchAll(namespaces []string, stopCh <-chan struct{}) (<-cha return c.watchChan, nil } -func (c clientMock) UpdateIngressStatus(_ *v1beta1.Ingress, _, _ string) error { +func (c clientMock) UpdateIngressStatus(_ *networkingv1beta1.Ingress, _, _ string) error { return c.apiIngressStatusError } diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index ac1d0f209..eefc68679 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -20,7 +20,6 @@ import ( "github.com/mitchellh/hashstructure" ptypes "github.com/traefik/paerser/types" corev1 "k8s.io/api/core/v1" - "k8s.io/api/networking/v1beta1" networkingv1beta1 "k8s.io/api/networking/v1beta1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/util/intstr" @@ -291,7 +290,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl return conf } -func (p *Provider) updateIngressStatus(ing *v1beta1.Ingress, k8sClient Client) error { +func (p *Provider) updateIngressStatus(ing *networkingv1beta1.Ingress, k8sClient Client) error { // Only process if an EndpointIngress has been configured. if p.IngressEndpoint == nil { return nil @@ -348,7 +347,7 @@ func buildHostRule(host string) string { return "Host(`" + host + "`)" } -func getCertificates(ctx context.Context, ingress *v1beta1.Ingress, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { +func getCertificates(ctx context.Context, ingress *networkingv1beta1.Ingress, k8sClient Client, tlsConfigs map[string]*tls.CertAndStores) error { for _, t := range ingress.Spec.TLS { if t.SecretName == "" { log.FromContext(ctx).Debugf("Skipping TLS sub-section: No secret name provided") @@ -433,7 +432,7 @@ func getTLSConfig(tlsConfigs map[string]*tls.CertAndStores) []*tls.CertAndStores return configs } -func loadService(client Client, namespace string, backend v1beta1.IngressBackend) (*dynamic.Service, error) { +func loadService(client Client, namespace string, backend networkingv1beta1.IngressBackend) (*dynamic.Service, error) { service, exists, err := client.GetService(namespace, backend.ServiceName) if err != nil { return nil, err @@ -539,7 +538,7 @@ func getProtocol(portSpec corev1.ServicePort, portName string, svcConfig *Servic return protocol } -func loadRouter(rule v1beta1.IngressRule, pa v1beta1.HTTPIngressPath, rtConfig *RouterConfig, serviceName string) *dynamic.Router { +func loadRouter(rule networkingv1beta1.IngressRule, pa networkingv1beta1.HTTPIngressPath, rtConfig *RouterConfig, serviceName string) *dynamic.Router { var rules []string if len(rule.Host) > 0 { rules = []string{buildHostRule(rule.Host)} @@ -548,11 +547,11 @@ func loadRouter(rule v1beta1.IngressRule, pa v1beta1.HTTPIngressPath, rtConfig * if len(pa.Path) > 0 { matcher := defaultPathMatcher - if pa.PathType == nil || *pa.PathType == "" || *pa.PathType == v1beta1.PathTypeImplementationSpecific { + if pa.PathType == nil || *pa.PathType == "" || *pa.PathType == networkingv1beta1.PathTypeImplementationSpecific { if rtConfig != nil && rtConfig.Router != nil && rtConfig.Router.PathMatcher != "" { matcher = rtConfig.Router.PathMatcher } - } else if *pa.PathType == v1beta1.PathTypeExact { + } else if *pa.PathType == networkingv1beta1.PathTypeExact { matcher = "Path" } diff --git a/pkg/version/version.go b/pkg/version/version.go index 5e5e0ff0c..db613ca48 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -41,7 +41,7 @@ func (v Handler) Append(router *mux.Router) { Version string Codename string StartDate time.Time `json:"startDate"` - UUID string `json:"uuid"` + UUID string `json:"uuid,omitempty"` }{ Version: Version, Codename: Codename,