Normalize default names for ConsulCatalog.

This commit is contained in:
Ludovic Fernandez 2020-03-30 19:12:05 +02:00 committed by GitHub
parent a6b6e1d101
commit 6f749c6414
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View file

@ -18,8 +18,8 @@ func (p *Provider) buildConfiguration(ctx context.Context, items []itemData) *dy
configurations := make(map[string]*dynamic.Configuration)
for _, item := range items {
svcName := item.Node + "-" + item.Name + "-" + item.ID
ctxSvc := log.With(ctx, log.Str("serviceName", svcName))
svcName := provider.Normalize(item.Node + "-" + item.Name + "-" + item.ID)
ctxSvc := log.With(ctx, log.Str(log.ServiceName, svcName))
if !p.keepContainer(ctxSvc, item) {
continue
@ -77,7 +77,7 @@ func (p *Provider) buildConfiguration(ctx context.Context, items []itemData) *dy
Labels: item.Labels,
}
provider.BuildRouterConfiguration(ctx, confFromLabel.HTTP, item.Name, p.defaultRuleTpl, model)
provider.BuildRouterConfiguration(ctx, confFromLabel.HTTP, provider.Normalize(item.Name), p.defaultRuleTpl, model)
configurations[svcName] = confFromLabel
}
@ -118,7 +118,7 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, item itemDa
lb := &dynamic.TCPServersLoadBalancer{}
lb.SetDefaults()
configuration.Services[item.Name] = &dynamic.TCPService{
configuration.Services[provider.Normalize(item.Name)] = &dynamic.TCPService{
LoadBalancer: lb,
}
}
@ -140,7 +140,7 @@ func (p *Provider) buildUDPServiceConfiguration(ctx context.Context, item itemDa
lb := &dynamic.UDPServersLoadBalancer{}
configuration.Services[item.Name] = &dynamic.UDPService{
configuration.Services[provider.Normalize(item.Name)] = &dynamic.UDPService{
LoadBalancer: lb,
}
}
@ -163,7 +163,7 @@ func (p *Provider) buildServiceConfiguration(ctx context.Context, item itemData,
lb := &dynamic.ServersLoadBalancer{}
lb.SetDefaults()
configuration.Services[item.Name] = &dynamic.Service{
configuration.Services[provider.Normalize(item.Name)] = &dynamic.Service{
LoadBalancer: lb,
}
}

View file

@ -284,7 +284,7 @@ func Test_buildConfiguration(t *testing.T) {
{
ID: "Test",
Node: "Node1",
Name: "Test",
Name: "dev/Test",
Labels: map[string]string{},
Address: "127.0.0.1",
Port: "80",
@ -302,14 +302,14 @@ func Test_buildConfiguration(t *testing.T) {
},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
"dev-Test": {
Service: "dev-Test",
Rule: "Host(`dev-Test.traefik.wtf`)",
},
},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test": {
"dev-Test": {
LoadBalancer: &dynamic.ServersLoadBalancer{
Servers: []dynamic.Server{
{