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

View file

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