From cb3328dca30ed09ef462236156c860d0d0eb063b Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Mon, 14 Oct 2019 11:18:04 +0200 Subject: [PATCH] Normalize service and router names for ingress. --- pkg/provider/kubernetes/ingress/kubernetes.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 863711cce..403069895 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -16,6 +16,7 @@ import ( "github.com/containous/traefik/v2/pkg/config/dynamic" "github.com/containous/traefik/v2/pkg/job" "github.com/containous/traefik/v2/pkg/log" + "github.com/containous/traefik/v2/pkg/provider" "github.com/containous/traefik/v2/pkg/safe" "github.com/containous/traefik/v2/pkg/tls" "github.com/containous/traefik/v2/pkg/types" @@ -324,8 +325,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl continue } - serviceName := ingress.Namespace + "-" + p.Backend.ServiceName + "-" + p.Backend.ServicePort.String() - serviceName = strings.ReplaceAll(serviceName, ".", "-") + serviceName := provider.Normalize(ingress.Namespace + "-" + p.Backend.ServiceName + "-" + p.Backend.ServicePort.String()) var rules []string if len(rule.Host) > 0 { rules = []string{"Host(`" + rule.Host + "`)"} @@ -335,10 +335,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl rules = append(rules, "PathPrefix(`"+p.Path+"`)") } - routerKey := strings.Replace(rule.Host, ".", "-", -1) + strings.Replace(p.Path, "/", "-", 1) - if strings.HasPrefix(routerKey, "-") { - routerKey = strings.Replace(routerKey, "-", "", 1) - } + routerKey := strings.TrimPrefix(provider.Normalize(rule.Host+p.Path), "-") conf.HTTP.Routers[routerKey] = &dynamic.Router{ Rule: strings.Join(rules, " && "), Service: serviceName,