Skip to content

Commit

Permalink
review: remove comma separator
Browse files Browse the repository at this point in the history
  • Loading branch information
rtribotte committed Aug 1, 2022
1 parent ef66aad commit df420b3
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion pkg/provider/consulcatalog/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
18 changes: 9 additions & 9 deletions pkg/provider/consulcatalog/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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`)",
},
},
Expand All @@ -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{
{
Expand Down Expand Up @@ -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`)",
},
},
Expand All @@ -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"},
Expand Down Expand Up @@ -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{
Expand All @@ -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"},
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions pkg/provider/consulcatalog/consul_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/provider/consulcatalog/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 // <prefix>.consulcatalog.connect
Canary bool // <prefix>.consulcatalog.canary
Connect bool // <prefix>.consulcatalog.connect is the corresponding label.
Canary bool // <prefix>.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},
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/nomad/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
8 changes: 4 additions & 4 deletions pkg/provider/nomad/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)",
},
},
Expand All @@ -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"},
Expand Down Expand Up @@ -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{
Expand All @@ -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"},
Expand Down
14 changes: 7 additions & 7 deletions pkg/provider/nomad/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 // <prefix>.enable
Canary bool // <prefix>.nomad.canary
Enable bool // <prefix>.enable is the corresponding label.
Canary bool // <prefix>.nomad.canary is the corresponding label.
}

// globalConfig returns a configuration with settings not specific to the dynamic configuration (i.e. "<prefix>.enable").
func (p *Provider) globalConfig(tags []string) configuration {
// getExtraConf returns a configuration with settings not specific to the dynamic configuration (i.e. "<prefix>.enable").
func (p *Provider) getExtraConf(tags []string) configuration {
labels := tagsToLabels(tags, p.Prefix)

enabled := p.ExposedByDefault
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/nomad/nomad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down

0 comments on commit df420b3

Please sign in to comment.