From df420b39a30abe7f4092006fade983515aa98125 Mon Sep 17 00:00:00 2001 From: romain Date: Mon, 1 Aug 2022 17:21:59 +0200 Subject: [PATCH] review: remove comma separator --- pkg/provider/consulcatalog/config.go | 2 +- pkg/provider/consulcatalog/config_test.go | 18 +++++++++--------- pkg/provider/consulcatalog/consul_catalog.go | 10 +++++----- pkg/provider/consulcatalog/label.go | 8 ++++---- pkg/provider/nomad/config.go | 2 +- pkg/provider/nomad/config_test.go | 8 ++++---- pkg/provider/nomad/nomad.go | 14 +++++++------- pkg/provider/nomad/nomad_test.go | 2 +- 8 files changed, 32 insertions(+), 32 deletions(-) diff --git a/pkg/provider/consulcatalog/config.go b/pkg/provider/consulcatalog/config.go index 9d0b7def2c..bf0072f2e0 100644 --- a/pkg/provider/consulcatalog/config.go +++ b/pkg/provider/consulcatalog/config.go @@ -306,6 +306,6 @@ func getName(i itemData) string { sort.Strings(tags) hasher := fnv.New64() - hasher.Write([]byte(strings.Join(tags, ","))) + hasher.Write([]byte(strings.Join(tags, ""))) return provider.Normalize(fmt.Sprintf("%s-%d", i.Name, hasher.Sum64())) } diff --git a/pkg/provider/consulcatalog/config_test.go b/pkg/provider/consulcatalog/config_test.go index 9f721e9d92..f97e383f16 100644 --- a/pkg/provider/consulcatalog/config_test.go +++ b/pkg/provider/consulcatalog/config_test.go @@ -273,7 +273,7 @@ func TestDefaultRule(t *testing.T) { for i := 0; i < len(test.items); i++ { var err error - test.items[i].ExtraConf, err = p.getConfiguration(test.items[i].Labels) + test.items[i].ExtraConf, err = p.getExtraConf(test.items[i].Labels) require.NoError(t, err) } @@ -2659,8 +2659,8 @@ func Test_buildConfiguration(t *testing.T) { Service: "Test", Rule: "Host(`Test.traefik.wtf`)", }, - "Test-9063865763995334845": { - Service: "Test-9063865763995334845", + "Test-97077516270503695": { + Service: "Test-97077516270503695", Rule: "Host(`Test.traefik.wtf`)", }, }, @@ -2677,7 +2677,7 @@ func Test_buildConfiguration(t *testing.T) { ServersTransport: "tls-ns-dc1-Test", }, }, - "Test-9063865763995334845": { + "Test-97077516270503695": { LoadBalancer: &dynamic.ServersLoadBalancer{ Servers: []dynamic.Server{ { @@ -2748,7 +2748,7 @@ func Test_buildConfiguration(t *testing.T) { Rule: "HostSNI(`foobar`)", }, "test-canary": { - Service: "Test-17894695160126753176", + Service: "Test-17573747155436217342", Rule: "HostSNI(`canary.foobar`)", }, }, @@ -2762,7 +2762,7 @@ func Test_buildConfiguration(t *testing.T) { TerminationDelay: Int(100), }, }, - "Test-17894695160126753176": { + "Test-17573747155436217342": { LoadBalancer: &dynamic.TCPServersLoadBalancer{ Servers: []dynamic.TCPServer{ {Address: "127.0.0.2:80"}, @@ -2830,7 +2830,7 @@ func Test_buildConfiguration(t *testing.T) { }, "test-canary": { EntryPoints: []string{"udp"}, - Service: "Test-1346847178227676570", + Service: "Test-12825244908842506376", }, }, Services: map[string]*dynamic.UDPService{ @@ -2841,7 +2841,7 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - "Test-1346847178227676570": { + "Test-12825244908842506376": { LoadBalancer: &dynamic.UDPServersLoadBalancer{ Servers: []dynamic.UDPServer{ {Address: "127.0.0.2:80"}, @@ -2880,7 +2880,7 @@ func Test_buildConfiguration(t *testing.T) { for i := 0; i < len(test.items); i++ { var err error - test.items[i].ExtraConf, err = p.getConfiguration(test.items[i].Labels) + test.items[i].ExtraConf, err = p.getExtraConf(test.items[i].Labels) require.NoError(t, err) var tags []string diff --git a/pkg/provider/consulcatalog/consul_catalog.go b/pkg/provider/consulcatalog/consul_catalog.go index 59e19ddf4d..effd67cacf 100644 --- a/pkg/provider/consulcatalog/consul_catalog.go +++ b/pkg/provider/consulcatalog/consul_catalog.go @@ -283,13 +283,13 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error for name, tags := range serviceNames { logger := log.FromContext(log.With(ctx, log.Str("serviceName", name))) - svcCfg, err := p.getConfiguration(tagsToNeutralLabels(tags, p.Prefix)) + extraConf, err := p.getExtraConf(tagsToNeutralLabels(tags, p.Prefix)) if err != nil { logger.Errorf("Skip service: %v", err) continue } - if !svcCfg.Enable { + if !extraConf.Enable { logger.Debug("Filtering disabled item") continue } @@ -305,12 +305,12 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error continue } - if !p.ConnectAware && svcCfg.ConsulCatalog.Connect { + if !p.ConnectAware && extraConf.ConsulCatalog.Connect { logger.Debugf("Filtering out Connect aware item, Connect support is not enabled") continue } - consulServices, statuses, err := p.fetchService(ctx, name, svcCfg.ConsulCatalog.Connect) + consulServices, statuses, err := p.fetchService(ctx, name, extraConf.ConsulCatalog.Connect) if err != nil { return nil, err } @@ -344,7 +344,7 @@ func (p *Provider) getConsulServicesData(ctx context.Context) ([]itemData, error Status: status, } - extraConf, err := p.getConfiguration(item.Labels) + extraConf, err := p.getExtraConf(item.Labels) if err != nil { log.FromContext(ctx).Errorf("Skip item %s: %v", item.Name, err) continue diff --git a/pkg/provider/consulcatalog/label.go b/pkg/provider/consulcatalog/label.go index d17d60c8a8..4a08daf614 100644 --- a/pkg/provider/consulcatalog/label.go +++ b/pkg/provider/consulcatalog/label.go @@ -4,18 +4,18 @@ import ( "github.com/traefik/traefik/v2/pkg/config/label" ) -// configuration Contains information from the labels that are globals (not related to the dynamic configuration) or specific to the provider. +// configuration contains information from the labels that are globals (not related to the dynamic configuration) or specific to the provider. type configuration struct { Enable bool ConsulCatalog specificConfiguration } type specificConfiguration struct { - Connect bool // .consulcatalog.connect - Canary bool // .consulcatalog.canary + Connect bool // .consulcatalog.connect is the corresponding label. + Canary bool // .consulcatalog.canary is the corresponding label. } -func (p *Provider) getConfiguration(labels map[string]string) (configuration, error) { +func (p *Provider) getExtraConf(labels map[string]string) (configuration, error) { conf := configuration{ Enable: p.ExposedByDefault, ConsulCatalog: specificConfiguration{Connect: p.ConnectByDefault}, diff --git a/pkg/provider/nomad/config.go b/pkg/provider/nomad/config.go index 529f1da29e..6978bf04b9 100644 --- a/pkg/provider/nomad/config.go +++ b/pkg/provider/nomad/config.go @@ -280,6 +280,6 @@ func getName(i item) string { sort.Strings(tags) hasher := fnv.New64() - hasher.Write([]byte(strings.Join(tags, ","))) + hasher.Write([]byte(strings.Join(tags, ""))) return provider.Normalize(fmt.Sprintf("%s-%d", i.Name, hasher.Sum64())) } diff --git a/pkg/provider/nomad/config_test.go b/pkg/provider/nomad/config_test.go index 75ab216a12..4c72ee8548 100644 --- a/pkg/provider/nomad/config_test.go +++ b/pkg/provider/nomad/config_test.go @@ -2330,7 +2330,7 @@ func Test_buildConfig(t *testing.T) { Rule: "HostSNI(`foobar`)", }, "test-canary": { - Service: "Test-9726919899690485944", + Service: "Test-8769860286750522282", Rule: "HostSNI(`canary.foobar`)", }, }, @@ -2344,7 +2344,7 @@ func Test_buildConfig(t *testing.T) { TerminationDelay: Int(100), }, }, - "Test-9726919899690485944": { + "Test-8769860286750522282": { LoadBalancer: &dynamic.TCPServersLoadBalancer{ Servers: []dynamic.TCPServer{ {Address: "127.0.0.2:80"}, @@ -2414,7 +2414,7 @@ func Test_buildConfig(t *testing.T) { }, "test-canary": { EntryPoints: []string{"udp"}, - Service: "Test-10874264889956497526", + Service: "Test-1611429260986126224", }, }, Services: map[string]*dynamic.UDPService{ @@ -2425,7 +2425,7 @@ func Test_buildConfig(t *testing.T) { }, }, }, - "Test-10874264889956497526": { + "Test-1611429260986126224": { LoadBalancer: &dynamic.UDPServersLoadBalancer{ Servers: []dynamic.UDPServer{ {Address: "127.0.0.2:80"}, diff --git a/pkg/provider/nomad/nomad.go b/pkg/provider/nomad/nomad.go index 1aaf8f7f31..0f33634da9 100644 --- a/pkg/provider/nomad/nomad.go +++ b/pkg/provider/nomad/nomad.go @@ -185,12 +185,12 @@ func createClient(namespace string, endpoint *EndpointConfig) (*api.Client, erro // configuration contains information from the service's tags that are globals // (not specific to the dynamic configuration). type configuration struct { - Enable bool // .enable - Canary bool // .nomad.canary + Enable bool // .enable is the corresponding label. + Canary bool // .nomad.canary is the corresponding label. } -// globalConfig returns a configuration with settings not specific to the dynamic configuration (i.e. ".enable"). -func (p *Provider) globalConfig(tags []string) configuration { +// getExtraConf returns a configuration with settings not specific to the dynamic configuration (i.e. ".enable"). +func (p *Provider) getExtraConf(tags []string) configuration { labels := tagsToLabels(tags, p.Prefix) enabled := p.ExposedByDefault @@ -222,8 +222,8 @@ func (p *Provider) getNomadServiceData(ctx context.Context) ([]item, error) { for _, service := range stub.Services { logger := log.FromContext(log.With(ctx, log.Str("serviceName", service.ServiceName))) - globalCfg := p.globalConfig(service.Tags) - if !globalCfg.Enable { + extraConf := p.getExtraConf(service.Tags) + if !extraConf.Enable { logger.Debug("Filter Nomad service that is not enabled") continue } @@ -254,7 +254,7 @@ func (p *Provider) getNomadServiceData(ctx context.Context) ([]item, error) { Address: i.Address, Port: i.Port, Tags: i.Tags, - ExtraConf: p.globalConfig(i.Tags), + ExtraConf: p.getExtraConf(i.Tags), }) } } diff --git a/pkg/provider/nomad/nomad_test.go b/pkg/provider/nomad/nomad_test.go index 3142eb3e96..02e1217efd 100644 --- a/pkg/provider/nomad/nomad_test.go +++ b/pkg/provider/nomad/nomad_test.go @@ -65,7 +65,7 @@ func Test_globalConfig(t *testing.T) { for _, test := range cases { t.Run(test.Name, func(t *testing.T) { p := Provider{ExposedByDefault: test.ExposedByDefault, Prefix: test.Prefix} - result := p.globalConfig(test.Tags) + result := p.getExtraConf(test.Tags) require.Equal(t, test.exp, result) }) }