1
0
Fork 0

Fix kubernetes id name

This commit is contained in:
Michael 2019-09-13 20:44:04 +02:00 committed by Traefiker Bot
parent 685c6dc00c
commit 255e88fbf6
6 changed files with 255 additions and 251 deletions

View file

@ -325,7 +325,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
continue
}
serviceName := ingress.Namespace + "/" + p.Backend.ServiceName + "/" + p.Backend.ServicePort.String()
serviceName := ingress.Namespace + "-" + p.Backend.ServiceName + "-" + p.Backend.ServicePort.String()
serviceName = strings.ReplaceAll(serviceName, ".", "-")
var rules []string
if len(rule.Host) > 0 {
@ -336,14 +336,18 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
rules = append(rules, "PathPrefix(`"+p.Path+"`)")
}
conf.HTTP.Routers[strings.Replace(rule.Host, ".", "-", -1)+p.Path] = &dynamic.Router{
routerKey := strings.Replace(rule.Host, ".", "-", -1) + strings.Replace(p.Path, "/", "-", 1)
if strings.HasPrefix(routerKey, "-") {
routerKey = strings.Replace(routerKey, "-", "", 1)
}
conf.HTTP.Routers[routerKey] = &dynamic.Router{
Rule: strings.Join(rules, " && "),
Service: serviceName,
}
if len(ingress.Spec.TLS) > 0 {
// TLS enabled for this ingress, add TLS router
conf.HTTP.Routers[strings.Replace(rule.Host, ".", "-", -1)+p.Path+"-tls"] = &dynamic.Router{
conf.HTTP.Routers[routerKey+"-tls"] = &dynamic.Router{
Rule: strings.Join(rules, " && "),
Service: serviceName,
TLS: &dynamic.RouterTLSConfig{},
@ -381,7 +385,7 @@ func getTLS(ctx context.Context, ingress *v1beta1.Ingress, k8sClient Client, tls
continue
}
configKey := ingress.Namespace + "/" + t.SecretName
configKey := ingress.Namespace + "-" + t.SecretName
if _, tlsExists := tlsConfigs[configKey]; !tlsExists {
secret, exists, err := k8sClient.GetSecret(ingress.Namespace, t.SecretName)
if err != nil {

View file

@ -43,13 +43,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -73,17 +73,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
"/foo": {
"foo": {
Rule: "PathPrefix(`/foo`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -107,17 +107,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
"/foo": {
"foo": {
Rule: "PathPrefix(`/foo`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -141,13 +141,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -172,11 +172,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Routers: map[string]*dynamic.Router{
"example-com": {
Rule: "Host(`example.com`)",
Service: "testing/example-com/80",
Service: "testing-example-com-80",
},
},
Services: map[string]*dynamic.Service{
"testing/example-com/80": {
"testing-example-com-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -197,17 +197,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
"traefik-tchouk/foo": {
"traefik-tchouk-foo": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/foo`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -231,17 +231,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
"traefik-courgette/carotte": {
"traefik-courgette-carotte": {
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -265,17 +265,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
"/foo": {
"foo": {
Rule: "PathPrefix(`/foo`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -310,13 +310,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-courgette/carotte": {
"traefik-courgette-carotte": {
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -351,17 +351,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
"traefik-courgette/carotte": {
"traefik-courgette-carotte": {
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
Service: "testing/service2/8082",
Service: "testing-service2-8082",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -374,7 +374,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
},
"testing/service2/8082": {
"testing-service2-8082": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -451,13 +451,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -481,13 +481,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
Service: "testing-service1-tchouk",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
"testing-service1-tchouk": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -511,13 +511,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
Service: "testing-service1-tchouk",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
"testing-service1-tchouk": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -541,17 +541,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
Service: "testing-service1-tchouk",
},
"traefik-tchouk/foo": {
"traefik-tchouk-foo": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/foo`)",
Service: "testing/service1/carotte",
Service: "testing-service1-carotte",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
"testing-service1-tchouk": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -564,7 +564,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
},
"testing/service1/carotte": {
"testing-service1-carotte": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -588,17 +588,17 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
Service: "testing-service1-tchouk",
},
"toto-traefik-tchouk/bar": {
"toto-traefik-tchouk-bar": {
Rule: "Host(`toto.traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "toto/service1/tchouk",
Service: "toto-service1-tchouk",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
"testing-service1-tchouk": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -611,7 +611,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
},
"toto/service1/tchouk": {
"toto-service1-tchouk": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -657,13 +657,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
"traefik-tchouk-bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/8080",
Service: "testing-service1-8080",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/8080": {
"testing-service1-8080": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -686,16 +686,16 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Routers: map[string]*dynamic.Router{
"example-com": {
Rule: "Host(`example.com`)",
Service: "testing/example-com/80",
Service: "testing-example-com-80",
},
"example-com-tls": {
Rule: "Host(`example.com`)",
Service: "testing/example-com/80",
Service: "testing-example-com-80",
TLS: &dynamic.RouterTLSConfig{},
},
},
Services: map[string]*dynamic.Service{
"testing/example-com/80": {
"testing-example-com-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -726,13 +726,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/443",
Service: "testing-service1-443",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/443": {
"testing-service1-443": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -756,13 +756,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/8443",
Service: "testing-service1-8443",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/8443": {
"testing-service1-8443": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -787,13 +787,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/8443",
Service: "testing-service1-8443",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/8443": {
"testing-service1-8443": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -848,13 +848,13 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
"bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
Service: "testing-service1-80",
},
},
Services: map[string]*dynamic.Service{
"testing/service1/80": {
"testing-service1-80": {
LoadBalancer: &dynamic.ServersLoadBalancer{
PassHostHeader: true,
Servers: []dynamic.Server{
@ -1088,13 +1088,13 @@ func TestGetTLS(t *testing.T) {
},
},
result: map[string]*tls.CertAndStores{
"testing/test-secret": {
"testing-test-secret": {
Certificate: tls.Certificate{
CertFile: tls.FileOrContent("tls-crt"),
KeyFile: tls.FileOrContent("tls-key"),
},
},
"testing/test-secret2": {
"testing-test-secret2": {
Certificate: tls.Certificate{
CertFile: tls.FileOrContent("tls-crt"),
KeyFile: tls.FileOrContent("tls-key"),