1
0
Fork 0

Move dynamic config into a dedicated package.

This commit is contained in:
Ludovic Fernandez 2019-07-10 09:26:04 +02:00 committed by Traefiker Bot
parent 09cc1161c9
commit c8bf8e896a
102 changed files with 3170 additions and 3166 deletions

View file

@ -14,7 +14,7 @@ import (
"time"
"github.com/cenkalti/backoff"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/job"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/safe"
@ -92,7 +92,7 @@ func (p *Provider) Init() error {
// Provide allows the k8s provider to provide configurations to traefik
// using the given configuration channel.
func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.Pool) error {
func (p *Provider) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
ctxLog := log.With(context.Background(), log.Str(log.ProviderName, "kubernetes"))
logger := log.FromContext(ctxLog)
// Tell glog (used by client-go) to log into STDERR. Otherwise, we risk
@ -138,7 +138,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
logger.Debugf("Skipping Kubernetes event kind %T", event)
} else {
p.lastConfiguration.Set(conf)
configurationChan <- config.Message{
configurationChan <- dynamic.Message{
ProviderName: "kubernetes",
Configuration: conf,
}
@ -164,7 +164,7 @@ func checkStringQuoteValidity(value string) error {
return err
}
func loadService(client Client, namespace string, backend v1beta1.IngressBackend) (*config.Service, error) {
func loadService(client Client, namespace string, backend v1beta1.IngressBackend) (*dynamic.Service, error) {
service, exists, err := client.GetService(namespace, backend.ServiceName)
if err != nil {
return nil, err
@ -174,7 +174,7 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
return nil, errors.New("service not found")
}
var servers []config.Server
var servers []dynamic.Server
var portName string
var portSpec corev1.ServicePort
var match bool
@ -193,7 +193,7 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
}
if service.Spec.Type == corev1.ServiceTypeExternalName {
servers = append(servers, config.Server{
servers = append(servers, dynamic.Server{
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
})
} else {
@ -230,29 +230,29 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
}
for _, addr := range subset.Addresses {
servers = append(servers, config.Server{
servers = append(servers, dynamic.Server{
URL: fmt.Sprintf("%s://%s:%d", protocol, addr.IP, port),
})
}
}
}
return &config.Service{
LoadBalancer: &config.LoadBalancerService{
return &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: servers,
PassHostHeader: true,
},
}, nil
}
func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Client) *config.Configuration {
conf := &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Client) *dynamic.Configuration {
conf := &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
TCP: &config.TCPConfiguration{},
TCP: &dynamic.TCPConfiguration{},
}
ingresses := client.GetIngresses()
@ -286,7 +286,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
continue
}
conf.HTTP.Routers["/"] = &config.Router{
conf.HTTP.Routers["/"] = &dynamic.Router{
Rule: "PathPrefix(`/`)",
Priority: math.MinInt32,
Service: "default-backend",
@ -327,7 +327,7 @@ 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] = &config.Router{
conf.HTTP.Routers[strings.Replace(rule.Host, ".", "-", -1)+p.Path] = &dynamic.Router{
Rule: strings.Join(rules, " && "),
Service: serviceName,
}
@ -343,7 +343,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
certs := getTLSConfig(tlsConfigs)
if len(certs) > 0 {
conf.TLS = &config.TLSConfiguration{
conf.TLS = &dynamic.TLSConfiguration{
Certificates: certs,
}
}

View file

@ -8,7 +8,7 @@ import (
"strings"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/provider"
"github.com/containous/traefik/pkg/tls"
"github.com/stretchr/testify/assert"
@ -23,36 +23,36 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
testCases := []struct {
desc string
ingressClass string
expected *config.Configuration
expected *dynamic.Configuration
}{
{
desc: "Empty ingresses",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with a basic rule on one path",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -68,11 +68,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with two different rules with one path",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
@ -82,11 +82,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -102,11 +102,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress one rule with two paths",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
@ -116,11 +116,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -136,21 +136,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress one rule with one path and one host",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -165,21 +165,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
}, {
desc: "Ingress with one host without path",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"example-com": {
Rule: "Host(`example.com`)",
Service: "testing/example-com/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/example-com/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.11.0.1:80",
},
@ -192,11 +192,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress one rule with one host and two paths",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
@ -206,11 +206,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -226,11 +226,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress Two rules with one host and one path",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
@ -240,11 +240,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -260,11 +260,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with a bad path syntax",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
@ -274,11 +274,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -294,32 +294,32 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with only a bad path syntax",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with a bad host syntax",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-courgette/carotte": {
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -335,22 +335,22 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with only a bad host syntax",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with two services",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
@ -360,11 +360,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service2/8082",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -375,9 +375,9 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
"testing/service2/8082": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.2:8080",
},
@ -393,44 +393,44 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with one service without endpoints subset",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with one service without endpoint",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Single Service Ingress (without any rules)",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/": {
Rule: "PathPrefix(`/`)",
Service: "default-backend",
Priority: math.MinInt32,
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"default-backend": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -446,21 +446,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with port value in backend and no pod replica",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8089",
},
@ -476,21 +476,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with port name in backend and no pod replica",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8089",
},
@ -506,21 +506,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with with port name in backend and 2 pod replica",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8089",
},
@ -536,11 +536,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with two paths using same service and different port name",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
@ -550,11 +550,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "testing/service1/carotte",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8089",
},
@ -565,9 +565,9 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
"testing/service1/carotte": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8090",
},
@ -583,11 +583,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "2 ingresses in different namespace with same service name",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/tchouk",
@ -597,11 +597,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
Service: "toto/service1/tchouk",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8089",
},
@ -612,9 +612,9 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
"toto/service1/tchouk": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.11.0.1:8089",
},
@ -630,43 +630,43 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with unknown service port name",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with unknown service port",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with service with externalName",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"traefik-tchouk/bar": {
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
Service: "testing/service1/8080",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/8080": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://traefik.wtf:8080",
},
@ -679,21 +679,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "TLS support",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"example-com": {
Rule: "Host(`example.com`)",
Service: "testing/example-com/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/example-com/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.11.0.1:80",
},
@ -702,7 +702,7 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
},
},
TLS: &config.TLSConfiguration{
TLS: &dynamic.TLSConfiguration{
Certificates: []*tls.CertAndStores{
{
Certificate: tls.Certificate{
@ -716,21 +716,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with a basic rule on one path with https (port == 443)",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/443",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/443": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "https://10.10.0.1:443",
},
@ -746,21 +746,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with a basic rule on one path with https (portname == https)",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/8443",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/8443": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "https://10.10.0.1:8443",
},
@ -776,22 +776,22 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with a basic rule on one path with https (portname starts with https)",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*config.Router{
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/8443",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/8443": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "https://10.10.0.1:8443",
},
@ -807,22 +807,22 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Double Single Service Ingress",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/": {
Rule: "PathPrefix(`/`)",
Service: "default-backend",
Priority: math.MinInt32,
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"default-backend": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.30.0.1:8080",
},
@ -838,21 +838,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress with default traefik ingressClass",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{
"/bar": {
Rule: "PathPrefix(`/bar`)",
Service: "testing/service1/80",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"testing/service1/80": {
LoadBalancer: &config.LoadBalancerService{
LoadBalancer: &dynamic.LoadBalancerService{
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: "http://10.10.0.1:8080",
},
@ -865,48 +865,48 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
},
{
desc: "Ingress without provider traefik ingressClass and unknown annotation",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with non matching provider traefik ingressClass and annotation",
ingressClass: "tchouk",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with ingressClass without annotation",
ingressClass: "tchouk",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},
{
desc: "Ingress with ingressClass without annotation",
ingressClass: "toto",
expected: &config.Configuration{
TCP: &config.TCPConfiguration{},
HTTP: &config.HTTPConfiguration{
Middlewares: map[string]*config.Middleware{},
Routers: map[string]*config.Router{},
Services: map[string]*config.Service{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{},
HTTP: &dynamic.HTTPConfiguration{
Middlewares: map[string]*dynamic.Middleware{},
Routers: map[string]*dynamic.Router{},
Services: map[string]*dynamic.Service{},
},
},
},