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

@ -17,7 +17,7 @@ import (
cmdVersion "github.com/containous/traefik/cmd/version"
"github.com/containous/traefik/pkg/cli"
"github.com/containous/traefik/pkg/collector"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider/aggregator"
@ -147,7 +147,7 @@ func runCmd(staticConfiguration *static.Configuration, configFile string) error
svr := server.NewServer(*staticConfiguration, providerAggregator, serverEntryPointsTCP, tlsManager)
if acmeProvider != nil && acmeProvider.OnHostRule {
acmeProvider.SetConfigListenerChan(make(chan config.Configuration))
acmeProvider.SetConfigListenerChan(make(chan dynamic.Configuration))
svr.AddListener(acmeProvider.ListenConfiguration)
}
ctx := cmd.ContextWithSignal(context.Background())

View file

@ -12,7 +12,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/containous/traefik/integration/try"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
traefiktls "github.com/containous/traefik/pkg/tls"
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
@ -864,8 +864,8 @@ func modifyCertificateConfFileContent(c *check.C, certFileName, confFileName, en
// If certificate file is not provided, just truncate the configuration file
if len(certFileName) > 0 {
tlsConf := config.Configuration{
TLS: &config.TLSConfiguration{
tlsConf := dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Certificates: []*traefiktls.CertAndStores{{
Certificate: traefiktls.Certificate{
CertFile: traefiktls.FileOrContent("fixtures/https/" + certFileName + ".cert"),

View file

@ -7,7 +7,7 @@ import (
"time"
"github.com/containous/traefik/integration/try"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)
@ -32,8 +32,8 @@ func (s *RestSuite) TestSimpleConfiguration(c *check.C) {
err = try.GetRequest("http://127.0.0.1:8000/", 1000*time.Millisecond, try.StatusCodeIs(http.StatusNotFound))
c.Assert(err, checker.IsNil)
config := config.HTTPConfiguration{
Routers: map[string]*config.Router{
config := dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router1": {
EntryPoints: []string{"web"},
Middlewares: []string{},
@ -41,10 +41,10 @@ func (s *RestSuite) TestSimpleConfiguration(c *check.C) {
Rule: "PathPrefix(`/`)",
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"service1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80",
},

View file

@ -12,7 +12,7 @@ import (
"time"
"github.com/containous/traefik/integration/try"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/go-check/check"
checker "github.com/vdemeester/shakers"
)
@ -440,8 +440,8 @@ func (s *SimpleSuite) TestMultiprovider(c *check.C) {
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1000*time.Millisecond, try.BodyContains("service"))
c.Assert(err, checker.IsNil)
config := config.HTTPConfiguration{
Routers: map[string]*config.Router{
config := dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router1": {
EntryPoints: []string{"web"},
Middlewares: []string{"customheader@file"},

View file

@ -48,8 +48,8 @@ func genStaticConfDoc(outputFile string, prefix string, encodeFn func(interface{
w.writeln(`<!--
CODE GENERATED AUTOMATICALLY
THIS FILE MUST NOT BE EDITED BY HAND
-->
`)
-->`)
w.writeln()
for i, flat := range flats {
w.writeln("`" + prefix + strings.ReplaceAll(flat.Name, "[0]", "[n]") + "`: ")

View file

@ -9,7 +9,7 @@ import (
"strings"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/types"
@ -25,46 +25,46 @@ const (
const nextPageHeader = "X-Next-Page"
type serviceInfoRepresentation struct {
*config.ServiceInfo
*dynamic.ServiceInfo
ServerStatus map[string]string `json:"serverStatus,omitempty"`
}
// RunTimeRepresentation is the configuration information exposed by the API handler.
type RunTimeRepresentation struct {
Routers map[string]*config.RouterInfo `json:"routers,omitempty"`
Middlewares map[string]*config.MiddlewareInfo `json:"middlewares,omitempty"`
Routers map[string]*dynamic.RouterInfo `json:"routers,omitempty"`
Middlewares map[string]*dynamic.MiddlewareInfo `json:"middlewares,omitempty"`
Services map[string]*serviceInfoRepresentation `json:"services,omitempty"`
TCPRouters map[string]*config.TCPRouterInfo `json:"tcpRouters,omitempty"`
TCPServices map[string]*config.TCPServiceInfo `json:"tcpServices,omitempty"`
TCPRouters map[string]*dynamic.TCPRouterInfo `json:"tcpRouters,omitempty"`
TCPServices map[string]*dynamic.TCPServiceInfo `json:"tcpServices,omitempty"`
}
type routerRepresentation struct {
*config.RouterInfo
*dynamic.RouterInfo
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
}
type serviceRepresentation struct {
*config.ServiceInfo
*dynamic.ServiceInfo
ServerStatus map[string]string `json:"serverStatus,omitempty"`
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
}
type middlewareRepresentation struct {
*config.MiddlewareInfo
*dynamic.MiddlewareInfo
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
}
type tcpRouterRepresentation struct {
*config.TCPRouterInfo
*dynamic.TCPRouterInfo
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
}
type tcpServiceRepresentation struct {
*config.TCPServiceInfo
*dynamic.TCPServiceInfo
Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"`
}
@ -80,7 +80,7 @@ type Handler struct {
dashboard bool
debug bool
// runtimeConfiguration is the data set used to create all the data representations exposed by the API.
runtimeConfiguration *config.RuntimeConfiguration
runtimeConfiguration *dynamic.RuntimeConfiguration
statistics *types.Statistics
// stats *thoasstats.Stats // FIXME stats
// StatsRecorder *middlewares.StatsRecorder // FIXME stats
@ -89,10 +89,10 @@ type Handler struct {
// New returns a Handler defined by staticConfig, and if provided, by runtimeConfig.
// It finishes populating the information provided in the runtimeConfig.
func New(staticConfig static.Configuration, runtimeConfig *config.RuntimeConfiguration) *Handler {
func New(staticConfig static.Configuration, runtimeConfig *dynamic.RuntimeConfiguration) *Handler {
rConfig := runtimeConfig
if rConfig == nil {
rConfig = &config.RuntimeConfiguration{}
rConfig = &dynamic.RuntimeConfiguration{}
}
return &Handler{

View file

@ -11,7 +11,7 @@ import (
"testing"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -29,13 +29,13 @@ func TestHandlerTCP_API(t *testing.T) {
testCases := []struct {
desc string
path string
conf config.RuntimeConfiguration
conf dynamic.RuntimeConfiguration
expected expected
}{
{
desc: "all TCP routers, but no config",
path: "/api/tcp/routers",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
@ -45,20 +45,20 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "all TCP routers",
path: "/api/tcp/routers",
conf: config.RuntimeConfiguration{
TCPRouters: map[string]*config.TCPRouterInfo{
conf: dynamic.RuntimeConfiguration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{
"test@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar.other`)",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
},
},
},
"bar@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -75,24 +75,24 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "all TCP routers, pagination, 1 res per page, want page 2",
path: "/api/tcp/routers?page=2&per_page=1",
conf: config.RuntimeConfiguration{
TCPRouters: map[string]*config.TCPRouterInfo{
conf: dynamic.RuntimeConfiguration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{
"bar@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
},
},
"baz@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`toto.bar`)",
},
},
"test@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar.other`)",
@ -109,10 +109,10 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "one TCP router by id",
path: "/api/tcp/routers/bar@myprovider",
conf: config.RuntimeConfiguration{
TCPRouters: map[string]*config.TCPRouterInfo{
conf: dynamic.RuntimeConfiguration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{
"bar@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -128,10 +128,10 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "one TCP router by id, that does not exist",
path: "/api/tcp/routers/foo@myprovider",
conf: config.RuntimeConfiguration{
TCPRouters: map[string]*config.TCPRouterInfo{
conf: dynamic.RuntimeConfiguration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{
"bar@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -146,7 +146,7 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "one TCP router by id, but no config",
path: "/api/tcp/routers/bar@myprovider",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusNotFound,
},
@ -154,7 +154,7 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "all tcp services, but no config",
path: "/api/tcp/services",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
@ -164,12 +164,12 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "all tcp services",
path: "/api/tcp/services",
conf: config.RuntimeConfiguration{
TCPServices: map[string]*config.TCPServiceInfo{
conf: dynamic.RuntimeConfiguration{
TCPServices: map[string]*dynamic.TCPServiceInfo{
"bar@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:2345",
},
@ -179,9 +179,9 @@ func TestHandlerTCP_API(t *testing.T) {
UsedBy: []string{"foo@myprovider", "test@myprovider"},
},
"baz@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.2:2345",
},
@ -201,12 +201,12 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "all tcp services, 1 res per page, want page 2",
path: "/api/tcp/services?page=2&per_page=1",
conf: config.RuntimeConfiguration{
TCPServices: map[string]*config.TCPServiceInfo{
conf: dynamic.RuntimeConfiguration{
TCPServices: map[string]*dynamic.TCPServiceInfo{
"bar@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:2345",
},
@ -216,9 +216,9 @@ func TestHandlerTCP_API(t *testing.T) {
UsedBy: []string{"foo@myprovider", "test@myprovider"},
},
"baz@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.2:2345",
},
@ -228,9 +228,9 @@ func TestHandlerTCP_API(t *testing.T) {
UsedBy: []string{"foo@myprovider"},
},
"test@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.3:2345",
},
@ -249,12 +249,12 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "one tcp service by id",
path: "/api/tcp/services/bar@myprovider",
conf: config.RuntimeConfiguration{
TCPServices: map[string]*config.TCPServiceInfo{
conf: dynamic.RuntimeConfiguration{
TCPServices: map[string]*dynamic.TCPServiceInfo{
"bar@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:2345",
},
@ -273,12 +273,12 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "one tcp service by id, that does not exist",
path: "/api/tcp/services/nono@myprovider",
conf: config.RuntimeConfiguration{
TCPServices: map[string]*config.TCPServiceInfo{
conf: dynamic.RuntimeConfiguration{
TCPServices: map[string]*dynamic.TCPServiceInfo{
"bar@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:2345",
},
@ -296,7 +296,7 @@ func TestHandlerTCP_API(t *testing.T) {
{
desc: "one tcp service by id, but no config",
path: "/api/tcp/services/foo@myprovider",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusNotFound,
},
@ -363,13 +363,13 @@ func TestHandlerHTTP_API(t *testing.T) {
testCases := []struct {
desc string
path string
conf config.RuntimeConfiguration
conf dynamic.RuntimeConfiguration
expected expected
}{
{
desc: "all routers, but no config",
path: "/api/http/routers",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
@ -379,10 +379,10 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all routers",
path: "/api/http/routers",
conf: config.RuntimeConfiguration{
Routers: map[string]*config.RouterInfo{
conf: dynamic.RuntimeConfiguration{
Routers: map[string]*dynamic.RouterInfo{
"test@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar.other`)",
@ -390,7 +390,7 @@ func TestHandlerHTTP_API(t *testing.T) {
},
},
"bar@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -408,10 +408,10 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all routers, pagination, 1 res per page, want page 2",
path: "/api/http/routers?page=2&per_page=1",
conf: config.RuntimeConfiguration{
Routers: map[string]*config.RouterInfo{
conf: dynamic.RuntimeConfiguration{
Routers: map[string]*dynamic.RouterInfo{
"bar@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -419,14 +419,14 @@ func TestHandlerHTTP_API(t *testing.T) {
},
},
"baz@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`toto.bar`)",
},
},
"test@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar.other`)",
@ -444,7 +444,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all routers, pagination, 19 results overall, 7 res per page, want page 3",
path: "/api/http/routers?page=3&per_page=7",
conf: config.RuntimeConfiguration{
conf: dynamic.RuntimeConfiguration{
Routers: generateHTTPRouters(19),
},
expected: expected{
@ -456,7 +456,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all routers, pagination, 5 results overall, 10 res per page, want page 2",
path: "/api/http/routers?page=2&per_page=10",
conf: config.RuntimeConfiguration{
conf: dynamic.RuntimeConfiguration{
Routers: generateHTTPRouters(5),
},
expected: expected{
@ -466,7 +466,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all routers, pagination, 10 results overall, 10 res per page, want page 2",
path: "/api/http/routers?page=2&per_page=10",
conf: config.RuntimeConfiguration{
conf: dynamic.RuntimeConfiguration{
Routers: generateHTTPRouters(10),
},
expected: expected{
@ -476,10 +476,10 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one router by id",
path: "/api/http/routers/bar@myprovider",
conf: config.RuntimeConfiguration{
Routers: map[string]*config.RouterInfo{
conf: dynamic.RuntimeConfiguration{
Routers: map[string]*dynamic.RouterInfo{
"bar@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -496,10 +496,10 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one router by id, that does not exist",
path: "/api/http/routers/foo@myprovider",
conf: config.RuntimeConfiguration{
Routers: map[string]*config.RouterInfo{
conf: dynamic.RuntimeConfiguration{
Routers: map[string]*dynamic.RouterInfo{
"bar@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -515,7 +515,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one router by id, but no config",
path: "/api/http/routers/foo@myprovider",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusNotFound,
},
@ -523,7 +523,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all services, but no config",
path: "/api/http/services",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
@ -533,13 +533,13 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all services",
path: "/api/http/services",
conf: config.RuntimeConfiguration{
Services: map[string]*config.ServiceInfo{
"bar@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
conf: dynamic.RuntimeConfiguration{
Services: map[string]*dynamic.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -551,11 +551,11 @@ func TestHandlerHTTP_API(t *testing.T) {
si.UpdateStatus("http://127.0.0.1", "UP")
return si
}(),
"baz@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
"baz@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.2",
},
@ -578,13 +578,13 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all services, 1 res per page, want page 2",
path: "/api/http/services?page=2&per_page=1",
conf: config.RuntimeConfiguration{
Services: map[string]*config.ServiceInfo{
"bar@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
conf: dynamic.RuntimeConfiguration{
Services: map[string]*dynamic.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -596,11 +596,11 @@ func TestHandlerHTTP_API(t *testing.T) {
si.UpdateStatus("http://127.0.0.1", "UP")
return si
}(),
"baz@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
"baz@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.2",
},
@ -612,11 +612,11 @@ func TestHandlerHTTP_API(t *testing.T) {
si.UpdateStatus("http://127.0.0.2", "UP")
return si
}(),
"test@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
"test@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.3",
},
@ -639,13 +639,13 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one service by id",
path: "/api/http/services/bar@myprovider",
conf: config.RuntimeConfiguration{
Services: map[string]*config.ServiceInfo{
"bar@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
conf: dynamic.RuntimeConfiguration{
Services: map[string]*dynamic.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -667,13 +667,13 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one service by id, that does not exist",
path: "/api/http/services/nono@myprovider",
conf: config.RuntimeConfiguration{
Services: map[string]*config.ServiceInfo{
"bar@myprovider": func() *config.ServiceInfo {
si := &config.ServiceInfo{
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
conf: dynamic.RuntimeConfiguration{
Services: map[string]*dynamic.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo {
si := &dynamic.ServiceInfo{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -694,7 +694,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one service by id, but no config",
path: "/api/http/services/foo@myprovider",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusNotFound,
},
@ -702,7 +702,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all middlewares, but no config",
path: "/api/http/middlewares",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusOK,
nextPage: "1",
@ -712,27 +712,27 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all middlewares",
path: "/api/http/middlewares",
conf: config.RuntimeConfiguration{
Middlewares: map[string]*config.MiddlewareInfo{
conf: dynamic.RuntimeConfiguration{
Middlewares: map[string]*dynamic.MiddlewareInfo{
"auth@myprovider": {
Middleware: &config.Middleware{
BasicAuth: &config.BasicAuth{
Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
"addPrefixTest@myprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/titi",
},
},
UsedBy: []string{"test@myprovider"},
},
"addPrefixTest@anotherprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/toto",
},
},
@ -749,27 +749,27 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "all middlewares, 1 res per page, want page 2",
path: "/api/http/middlewares?page=2&per_page=1",
conf: config.RuntimeConfiguration{
Middlewares: map[string]*config.MiddlewareInfo{
conf: dynamic.RuntimeConfiguration{
Middlewares: map[string]*dynamic.MiddlewareInfo{
"auth@myprovider": {
Middleware: &config.Middleware{
BasicAuth: &config.BasicAuth{
Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
"addPrefixTest@myprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/titi",
},
},
UsedBy: []string{"test@myprovider"},
},
"addPrefixTest@anotherprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/toto",
},
},
@ -786,27 +786,27 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one middleware by id",
path: "/api/http/middlewares/auth@myprovider",
conf: config.RuntimeConfiguration{
Middlewares: map[string]*config.MiddlewareInfo{
conf: dynamic.RuntimeConfiguration{
Middlewares: map[string]*dynamic.MiddlewareInfo{
"auth@myprovider": {
Middleware: &config.Middleware{
BasicAuth: &config.BasicAuth{
Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
UsedBy: []string{"bar@myprovider", "test@myprovider"},
},
"addPrefixTest@myprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/titi",
},
},
UsedBy: []string{"test@myprovider"},
},
"addPrefixTest@anotherprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/toto",
},
},
@ -822,11 +822,11 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one middleware by id, that does not exist",
path: "/api/http/middlewares/foo@myprovider",
conf: config.RuntimeConfiguration{
Middlewares: map[string]*config.MiddlewareInfo{
conf: dynamic.RuntimeConfiguration{
Middlewares: map[string]*dynamic.MiddlewareInfo{
"auth@myprovider": {
Middleware: &config.Middleware{
BasicAuth: &config.BasicAuth{
Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
@ -841,7 +841,7 @@ func TestHandlerHTTP_API(t *testing.T) {
{
desc: "one middleware by id, but no config",
path: "/api/http/middlewares/foo@myprovider",
conf: config.RuntimeConfiguration{},
conf: dynamic.RuntimeConfiguration{},
expected: expected{
statusCode: http.StatusNotFound,
},
@ -906,18 +906,18 @@ func TestHandler_Configuration(t *testing.T) {
testCases := []struct {
desc string
path string
conf config.RuntimeConfiguration
conf dynamic.RuntimeConfiguration
expected expected
}{
{
desc: "Get rawdata",
path: "/api/rawdata",
conf: config.RuntimeConfiguration{
Services: map[string]*config.ServiceInfo{
conf: dynamic.RuntimeConfiguration{
Services: map[string]*dynamic.ServiceInfo{
"foo-service@myprovider": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -926,32 +926,32 @@ func TestHandler_Configuration(t *testing.T) {
},
},
},
Middlewares: map[string]*config.MiddlewareInfo{
Middlewares: map[string]*dynamic.MiddlewareInfo{
"auth@myprovider": {
Middleware: &config.Middleware{
BasicAuth: &config.BasicAuth{
Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
},
"addPrefixTest@myprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/titi",
},
},
},
"addPrefixTest@anotherprovider": {
Middleware: &config.Middleware{
AddPrefix: &config.AddPrefix{
Middleware: &dynamic.Middleware{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/toto",
},
},
},
},
Routers: map[string]*config.RouterInfo{
Routers: map[string]*dynamic.RouterInfo{
"bar@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar`)",
@ -959,7 +959,7 @@ func TestHandler_Configuration(t *testing.T) {
},
},
"test@myprovider": {
Router: &config.Router{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar.other`)",
@ -967,11 +967,11 @@ func TestHandler_Configuration(t *testing.T) {
},
},
},
TCPServices: map[string]*config.TCPServiceInfo{
TCPServices: map[string]*dynamic.TCPServiceInfo{
"tcpfoo-service@myprovider": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1",
},
@ -980,16 +980,16 @@ func TestHandler_Configuration(t *testing.T) {
},
},
},
TCPRouters: map[string]*config.TCPRouterInfo{
TCPRouters: map[string]*dynamic.TCPRouterInfo{
"tcpbar@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "tcpfoo-service@myprovider",
Rule: "HostSNI(`foo.bar`)",
},
},
"tcptest@myprovider": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "tcpfoo-service@myprovider",
Rule: "HostSNI(`foo.bar.other`)",
@ -1054,11 +1054,11 @@ func TestHandler_Configuration(t *testing.T) {
}
}
func generateHTTPRouters(nbRouters int) map[string]*config.RouterInfo {
routers := make(map[string]*config.RouterInfo, nbRouters)
func generateHTTPRouters(nbRouters int) map[string]*dynamic.RouterInfo {
routers := make(map[string]*dynamic.RouterInfo, nbRouters)
for i := 0; i < nbRouters; i++ {
routers[fmt.Sprintf("bar%2d@myprovider", i)] = &config.RouterInfo{
Router: &config.Router{
routers[fmt.Sprintf("bar%2d@myprovider", i)] = &dynamic.RouterInfo{
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar" + strconv.Itoa(i) + "`)",

View file

@ -0,0 +1,36 @@
package dynamic
import (
"github.com/containous/traefik/pkg/tls"
)
// +k8s:deepcopy-gen=true
// Message holds configuration information exchanged between parts of traefik.
type Message struct {
ProviderName string
Configuration *Configuration
}
// +k8s:deepcopy-gen=true
// Configurations is for currentConfigurations Map.
type Configurations map[string]*Configuration
// +k8s:deepcopy-gen=true
// Configuration is the root of the dynamic configuration
type Configuration struct {
HTTP *HTTPConfiguration `json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty"`
TCP *TCPConfiguration `json:"tcp,omitempty" toml:"tcp,omitempty" yaml:"tcp,omitempty"`
TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty"`
}
// +k8s:deepcopy-gen=true
// TLSConfiguration contains all the configuration parameters of a TLS connection.
type TLSConfiguration struct {
Certificates []*tls.CertAndStores `json:"-" toml:"certificates,omitempty" yaml:"certificates,omitempty" label:"-"`
Options map[string]tls.Options `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"`
Stores map[string]tls.Store `json:"stores,omitempty" toml:"stores,omitempty" yaml:"stores,omitempty"`
}

View file

@ -1,4 +1,4 @@
package config
package dynamic
import (
"reflect"

View file

@ -1,41 +1,6 @@
package config
package dynamic
import (
"reflect"
traefiktls "github.com/containous/traefik/pkg/tls"
)
// +k8s:deepcopy-gen=true
// Message holds configuration information exchanged between parts of traefik.
type Message struct {
ProviderName string
Configuration *Configuration
}
// +k8s:deepcopy-gen=true
// Configurations is for currentConfigurations Map.
type Configurations map[string]*Configuration
// +k8s:deepcopy-gen=true
// Configuration is the root of the dynamic configuration
type Configuration struct {
HTTP *HTTPConfiguration `json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty"`
TCP *TCPConfiguration `json:"tcp,omitempty" toml:"tcp,omitempty" yaml:"tcp,omitempty"`
TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty"`
}
// +k8s:deepcopy-gen=true
// TLSConfiguration contains all the configuration parameters of a TLS connection.
type TLSConfiguration struct {
Certificates []*traefiktls.CertAndStores `json:"-" toml:"certificates,omitempty" yaml:"certificates,omitempty" label:"-"`
Options map[string]traefiktls.Options `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"`
Stores map[string]traefiktls.Store `json:"stores,omitempty" toml:"stores,omitempty" yaml:"stores,omitempty"`
}
import "reflect"
// +k8s:deepcopy-gen=true
@ -48,14 +13,6 @@ type HTTPConfiguration struct {
// +k8s:deepcopy-gen=true
// TCPConfiguration contains all the TCP configuration parameters.
type TCPConfiguration struct {
Routers map[string]*TCPRouter `json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty"`
Services map[string]*TCPService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty"`
}
// +k8s:deepcopy-gen=true
// Service holds a service configuration (can only be of one type at the same time).
type Service struct {
LoadBalancer *LoadBalancerService `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"`
@ -63,13 +20,6 @@ type Service struct {
// +k8s:deepcopy-gen=true
// TCPService holds a tcp service configuration (can only be of one type at the same time).
type TCPService struct {
LoadBalancer *TCPLoadBalancerService `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"`
}
// +k8s:deepcopy-gen=true
// Router holds the router configuration.
type Router struct {
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty"`
@ -89,24 +39,6 @@ type RouterTLSConfig struct {
// +k8s:deepcopy-gen=true
// TCPRouter holds the router configuration.
type TCPRouter struct {
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty"`
Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty"`
Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"`
TLS *RouterTCPTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty"`
}
// +k8s:deepcopy-gen=true
// RouterTCPTLSConfig holds the TLS configuration for a router
type RouterTCPTLSConfig struct {
Passthrough bool `json:"passthrough" toml:"passthrough" yaml:"passthrough"`
Options string `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"`
}
// +k8s:deepcopy-gen=true
// LoadBalancerService holds the LoadBalancerService configuration.
type LoadBalancerService struct {
Stickiness *Stickiness `json:"stickiness,omitempty" toml:"stickiness,omitempty" yaml:"stickiness,omitempty" label:"allowEmpty"`
@ -116,30 +48,6 @@ type LoadBalancerService struct {
ResponseForwarding *ResponseForwarding `json:"responseForwarding,omitempty" toml:"responseForwarding,omitempty" yaml:"responseForwarding,omitempty"`
}
// +k8s:deepcopy-gen=true
// TCPLoadBalancerService holds the LoadBalancerService configuration.
type TCPLoadBalancerService struct {
Servers []TCPServer `json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" label-slice-as-struct:"server"`
}
// Mergeable tells if the given service is mergeable.
func (l *TCPLoadBalancerService) Mergeable(loadBalancer *TCPLoadBalancerService) bool {
savedServers := l.Servers
defer func() {
l.Servers = savedServers
}()
l.Servers = nil
savedServersLB := loadBalancer.Servers
defer func() {
loadBalancer.Servers = savedServersLB
}()
loadBalancer.Servers = nil
return reflect.DeepEqual(l, loadBalancer)
}
// Mergeable tells if the given service is mergeable.
func (l *LoadBalancerService) Mergeable(loadBalancer *LoadBalancerService) bool {
savedServers := l.Servers
@ -187,14 +95,6 @@ type Server struct {
Port string `toml:"-" json:"-" yaml:"-"`
}
// +k8s:deepcopy-gen=true
// TCPServer holds a TCP Server configuration
type TCPServer struct {
Address string `json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty" label:"-"`
Port string `toml:"-" json:"-" yaml:"-"`
}
// SetDefaults Default values for a Server.
func (s *Server) SetDefaults() {
s.Scheme = "http"

View file

@ -1,4 +1,4 @@
package config
package dynamic
import (
"crypto/tls"

View file

@ -1,4 +1,4 @@
package config
package dynamic
import (
"context"

View file

@ -0,0 +1,68 @@
package dynamic
import "reflect"
// +k8s:deepcopy-gen=true
// TCPConfiguration contains all the TCP configuration parameters.
type TCPConfiguration struct {
Routers map[string]*TCPRouter `json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty"`
Services map[string]*TCPService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty"`
}
// +k8s:deepcopy-gen=true
// TCPService holds a tcp service configuration (can only be of one type at the same time).
type TCPService struct {
LoadBalancer *TCPLoadBalancerService `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"`
}
// +k8s:deepcopy-gen=true
// TCPRouter holds the router configuration.
type TCPRouter struct {
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty"`
Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty"`
Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"`
TLS *RouterTCPTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty"`
}
// +k8s:deepcopy-gen=true
// RouterTCPTLSConfig holds the TLS configuration for a router
type RouterTCPTLSConfig struct {
Passthrough bool `json:"passthrough" toml:"passthrough" yaml:"passthrough"`
Options string `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"`
}
// +k8s:deepcopy-gen=true
// TCPLoadBalancerService holds the LoadBalancerService configuration.
type TCPLoadBalancerService struct {
Servers []TCPServer `json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" label-slice-as-struct:"server"`
}
// Mergeable tells if the given service is mergeable.
func (l *TCPLoadBalancerService) Mergeable(loadBalancer *TCPLoadBalancerService) bool {
savedServers := l.Servers
defer func() {
l.Servers = savedServers
}()
l.Servers = nil
savedServersLB := loadBalancer.Servers
defer func() {
loadBalancer.Servers = savedServersLB
}()
loadBalancer.Servers = nil
return reflect.DeepEqual(l, loadBalancer)
}
// +k8s:deepcopy-gen=true
// TCPServer holds a TCP Server configuration
type TCPServer struct {
Address string `json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty" label:"-"`
Port string `toml:"-" json:"-" yaml:"-"`
}

View file

@ -26,7 +26,7 @@ THE SOFTWARE.
// Code generated by deepcopy-gen. DO NOT EDIT.
package config
package dynamic
import (
tls "github.com/containous/traefik/pkg/tls"

View file

@ -2,15 +2,15 @@
package label
import (
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/parser"
)
// DecodeConfiguration converts the labels to a configuration.
func DecodeConfiguration(labels map[string]string) (*config.Configuration, error) {
conf := &config.Configuration{
HTTP: &config.HTTPConfiguration{},
TCP: &config.TCPConfiguration{},
func DecodeConfiguration(labels map[string]string) (*dynamic.Configuration, error) {
conf := &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{},
TCP: &dynamic.TCPConfiguration{},
}
err := parser.Decode(labels, conf, parser.DefaultRootName, "traefik.http", "traefik.tcp")
@ -22,7 +22,7 @@ func DecodeConfiguration(labels map[string]string) (*config.Configuration, error
}
// EncodeConfiguration converts a configuration to labels.
func EncodeConfiguration(conf *config.Configuration) (map[string]string, error) {
func EncodeConfiguration(conf *dynamic.Configuration) (map[string]string, error) {
return parser.Encode(conf, parser.DefaultRootName)
}

View file

@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -175,9 +175,9 @@ func TestDecodeConfiguration(t *testing.T) {
configuration, err := DecodeConfiguration(labels)
require.NoError(t, err)
expected := &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{
expected := &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"Router0": {
EntryPoints: []string{
"foobar",
@ -185,7 +185,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
Service: "foobar",
Rule: "foobar",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
Options: "foo",
},
@ -197,16 +197,16 @@ func TestDecodeConfiguration(t *testing.T) {
},
Service: "foobar",
Rule: "foobar",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
Options: "foo",
},
},
},
Services: map[string]*config.TCPService{
Services: map[string]*dynamic.TCPService{
"Service0": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Port: "42",
},
@ -214,8 +214,8 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Service1": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Port: "42",
},
@ -224,8 +224,8 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Router0": {
EntryPoints: []string{
"foobar",
@ -238,7 +238,7 @@ func TestDecodeConfiguration(t *testing.T) {
Service: "foobar",
Rule: "foobar",
Priority: 42,
TLS: &config.RouterTLSConfig{},
TLS: &dynamic.RouterTLSConfig{},
},
"Router1": {
EntryPoints: []string{
@ -254,14 +254,14 @@ func TestDecodeConfiguration(t *testing.T) {
Priority: 42,
},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"Middleware0": {
AddPrefix: &config.AddPrefix{
AddPrefix: &dynamic.AddPrefix{
Prefix: "foobar",
},
},
"Middleware1": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{
"foobar",
"fiibar",
@ -273,18 +273,18 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware10": {
MaxConn: &config.MaxConn{
MaxConn: &dynamic.MaxConn{
Amount: 42,
ExtractorFunc: "foobar",
},
},
"Middleware11": {
PassTLSClientCert: &config.PassTLSClientCert{
PassTLSClientCert: &dynamic.PassTLSClientCert{
PEM: true,
Info: &config.TLSClientCertificateInfo{
Info: &dynamic.TLSClientCertificateInfo{
NotAfter: true,
NotBefore: true,
Subject: &config.TLSCLientCertificateDNInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -293,7 +293,7 @@ func TestDecodeConfiguration(t *testing.T) {
SerialNumber: true,
DomainComponent: true,
},
Issuer: &config.TLSCLientCertificateDNInfo{
Issuer: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -307,8 +307,8 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware12": {
RateLimit: &config.RateLimit{
RateSet: map[string]*config.Rate{
RateLimit: &dynamic.RateLimit{
RateSet: map[string]*dynamic.Rate{
"Rate0": {
Period: types.Duration(42 * time.Second),
Average: 42,
@ -324,37 +324,37 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware13": {
RedirectRegex: &config.RedirectRegex{
RedirectRegex: &dynamic.RedirectRegex{
Regex: "foobar",
Replacement: "foobar",
Permanent: true,
},
},
"Middleware13b": {
RedirectScheme: &config.RedirectScheme{
RedirectScheme: &dynamic.RedirectScheme{
Scheme: "https",
Port: "80",
Permanent: true,
},
},
"Middleware14": {
ReplacePath: &config.ReplacePath{
ReplacePath: &dynamic.ReplacePath{
Path: "foobar",
},
},
"Middleware15": {
ReplacePathRegex: &config.ReplacePathRegex{
ReplacePathRegex: &dynamic.ReplacePathRegex{
Regex: "foobar",
Replacement: "foobar",
},
},
"Middleware16": {
Retry: &config.Retry{
Retry: &dynamic.Retry{
Attempts: 42,
},
},
"Middleware17": {
StripPrefix: &config.StripPrefix{
StripPrefix: &dynamic.StripPrefix{
Prefixes: []string{
"foobar",
"fiibar",
@ -362,7 +362,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware18": {
StripPrefixRegex: &config.StripPrefixRegex{
StripPrefixRegex: &dynamic.StripPrefixRegex{
Regex: []string{
"foobar",
"fiibar",
@ -370,10 +370,10 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware19": {
Compress: &config.Compress{},
Compress: &dynamic.Compress{},
},
"Middleware2": {
Buffering: &config.Buffering{
Buffering: &dynamic.Buffering{
MaxRequestBodyBytes: 42,
MemRequestBodyBytes: 42,
MaxResponseBodyBytes: 42,
@ -382,7 +382,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware3": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{
"foobar",
"fiibar",
@ -390,12 +390,12 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware4": {
CircuitBreaker: &config.CircuitBreaker{
CircuitBreaker: &dynamic.CircuitBreaker{
Expression: "foobar",
},
},
"Middleware5": {
DigestAuth: &config.DigestAuth{
DigestAuth: &dynamic.DigestAuth{
Users: []string{
"foobar",
"fiibar",
@ -407,7 +407,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware6": {
Errors: &config.ErrorPage{
Errors: &dynamic.ErrorPage{
Status: []string{
"foobar",
"fiibar",
@ -417,9 +417,9 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware7": {
ForwardAuth: &config.ForwardAuth{
ForwardAuth: &dynamic.ForwardAuth{
Address: "foobar",
TLS: &config.ClientTLS{
TLS: &dynamic.ClientTLS{
CA: "foobar",
CAOptional: true,
Cert: "foobar",
@ -434,7 +434,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware8": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{
"name0": "foobar",
"name1": "foobar",
@ -491,12 +491,12 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
"Middleware9": {
IPWhiteList: &config.IPWhiteList{
IPWhiteList: &dynamic.IPWhiteList{
SourceRange: []string{
"foobar",
"fiibar",
},
IPStrategy: &config.IPStrategy{
IPStrategy: &dynamic.IPStrategy{
Depth: 42,
ExcludedIPs: []string{
"foobar",
@ -506,21 +506,21 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"Service0": {
LoadBalancer: &config.LoadBalancerService{
Stickiness: &config.Stickiness{
LoadBalancer: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{
CookieName: "foobar",
SecureCookie: true,
HTTPOnlyCookie: false,
},
Servers: []config.Server{
Servers: []dynamic.Server{
{
Scheme: "foobar",
Port: "8080",
},
},
HealthCheck: &config.HealthCheck{
HealthCheck: &dynamic.HealthCheck{
Scheme: "foobar",
Path: "foobar",
Port: 42,
@ -533,20 +533,20 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
PassHostHeader: true,
ResponseForwarding: &config.ResponseForwarding{
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
},
},
},
"Service1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
Scheme: "foobar",
Port: "8080",
},
},
HealthCheck: &config.HealthCheck{
HealthCheck: &dynamic.HealthCheck{
Scheme: "foobar",
Path: "foobar",
Port: 42,
@ -559,7 +559,7 @@ func TestDecodeConfiguration(t *testing.T) {
},
},
PassHostHeader: true,
ResponseForwarding: &config.ResponseForwarding{
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
},
},
@ -572,9 +572,9 @@ func TestDecodeConfiguration(t *testing.T) {
}
func TestEncodeConfiguration(t *testing.T) {
configuration := &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{
configuration := &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"Router0": {
EntryPoints: []string{
"foobar",
@ -582,7 +582,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
Service: "foobar",
Rule: "foobar",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
Options: "foo",
},
@ -594,16 +594,16 @@ func TestEncodeConfiguration(t *testing.T) {
},
Service: "foobar",
Rule: "foobar",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
Options: "foo",
},
},
},
Services: map[string]*config.TCPService{
Services: map[string]*dynamic.TCPService{
"Service0": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Port: "42",
},
@ -611,8 +611,8 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Service1": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Port: "42",
},
@ -621,8 +621,8 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Router0": {
EntryPoints: []string{
"foobar",
@ -635,7 +635,7 @@ func TestEncodeConfiguration(t *testing.T) {
Service: "foobar",
Rule: "foobar",
Priority: 42,
TLS: &config.RouterTLSConfig{},
TLS: &dynamic.RouterTLSConfig{},
},
"Router1": {
EntryPoints: []string{
@ -651,14 +651,14 @@ func TestEncodeConfiguration(t *testing.T) {
Priority: 42,
},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"Middleware0": {
AddPrefix: &config.AddPrefix{
AddPrefix: &dynamic.AddPrefix{
Prefix: "foobar",
},
},
"Middleware1": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{
"foobar",
"fiibar",
@ -670,18 +670,18 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware10": {
MaxConn: &config.MaxConn{
MaxConn: &dynamic.MaxConn{
Amount: 42,
ExtractorFunc: "foobar",
},
},
"Middleware11": {
PassTLSClientCert: &config.PassTLSClientCert{
PassTLSClientCert: &dynamic.PassTLSClientCert{
PEM: true,
Info: &config.TLSClientCertificateInfo{
Info: &dynamic.TLSClientCertificateInfo{
NotAfter: true,
NotBefore: true,
Subject: &config.TLSCLientCertificateDNInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -690,7 +690,7 @@ func TestEncodeConfiguration(t *testing.T) {
SerialNumber: true,
DomainComponent: true,
},
Issuer: &config.TLSCLientCertificateDNInfo{
Issuer: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -703,8 +703,8 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware12": {
RateLimit: &config.RateLimit{
RateSet: map[string]*config.Rate{
RateLimit: &dynamic.RateLimit{
RateSet: map[string]*dynamic.Rate{
"Rate0": {
Period: types.Duration(42 * time.Nanosecond),
Average: 42,
@ -720,37 +720,37 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware13": {
RedirectRegex: &config.RedirectRegex{
RedirectRegex: &dynamic.RedirectRegex{
Regex: "foobar",
Replacement: "foobar",
Permanent: true,
},
},
"Middleware13b": {
RedirectScheme: &config.RedirectScheme{
RedirectScheme: &dynamic.RedirectScheme{
Scheme: "https",
Port: "80",
Permanent: true,
},
},
"Middleware14": {
ReplacePath: &config.ReplacePath{
ReplacePath: &dynamic.ReplacePath{
Path: "foobar",
},
},
"Middleware15": {
ReplacePathRegex: &config.ReplacePathRegex{
ReplacePathRegex: &dynamic.ReplacePathRegex{
Regex: "foobar",
Replacement: "foobar",
},
},
"Middleware16": {
Retry: &config.Retry{
Retry: &dynamic.Retry{
Attempts: 42,
},
},
"Middleware17": {
StripPrefix: &config.StripPrefix{
StripPrefix: &dynamic.StripPrefix{
Prefixes: []string{
"foobar",
"fiibar",
@ -758,7 +758,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware18": {
StripPrefixRegex: &config.StripPrefixRegex{
StripPrefixRegex: &dynamic.StripPrefixRegex{
Regex: []string{
"foobar",
"fiibar",
@ -766,10 +766,10 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware19": {
Compress: &config.Compress{},
Compress: &dynamic.Compress{},
},
"Middleware2": {
Buffering: &config.Buffering{
Buffering: &dynamic.Buffering{
MaxRequestBodyBytes: 42,
MemRequestBodyBytes: 42,
MaxResponseBodyBytes: 42,
@ -778,7 +778,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware3": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{
"foobar",
"fiibar",
@ -786,12 +786,12 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware4": {
CircuitBreaker: &config.CircuitBreaker{
CircuitBreaker: &dynamic.CircuitBreaker{
Expression: "foobar",
},
},
"Middleware5": {
DigestAuth: &config.DigestAuth{
DigestAuth: &dynamic.DigestAuth{
Users: []string{
"foobar",
"fiibar",
@ -803,7 +803,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware6": {
Errors: &config.ErrorPage{
Errors: &dynamic.ErrorPage{
Status: []string{
"foobar",
"fiibar",
@ -813,9 +813,9 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware7": {
ForwardAuth: &config.ForwardAuth{
ForwardAuth: &dynamic.ForwardAuth{
Address: "foobar",
TLS: &config.ClientTLS{
TLS: &dynamic.ClientTLS{
CA: "foobar",
CAOptional: true,
Cert: "foobar",
@ -830,7 +830,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware8": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{
"name0": "foobar",
"name1": "foobar",
@ -887,12 +887,12 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
"Middleware9": {
IPWhiteList: &config.IPWhiteList{
IPWhiteList: &dynamic.IPWhiteList{
SourceRange: []string{
"foobar",
"fiibar",
},
IPStrategy: &config.IPStrategy{
IPStrategy: &dynamic.IPStrategy{
Depth: 42,
ExcludedIPs: []string{
"foobar",
@ -902,20 +902,20 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"Service0": {
LoadBalancer: &config.LoadBalancerService{
Stickiness: &config.Stickiness{
LoadBalancer: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{
CookieName: "foobar",
HTTPOnlyCookie: true,
},
Servers: []config.Server{
Servers: []dynamic.Server{
{
Scheme: "foobar",
Port: "8080",
},
},
HealthCheck: &config.HealthCheck{
HealthCheck: &dynamic.HealthCheck{
Scheme: "foobar",
Path: "foobar",
Port: 42,
@ -928,20 +928,20 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
PassHostHeader: true,
ResponseForwarding: &config.ResponseForwarding{
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
},
},
},
"Service1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
Scheme: "foobar",
Port: "8080",
},
},
HealthCheck: &config.HealthCheck{
HealthCheck: &dynamic.HealthCheck{
Scheme: "foobar",
Path: "foobar",
Port: 42,
@ -954,7 +954,7 @@ func TestEncodeConfiguration(t *testing.T) {
},
},
PassHostHeader: true,
ResponseForwarding: &config.ResponseForwarding{
ResponseForwarding: &dynamic.ResponseForwarding{
FlushInterval: "foobar",
},
},

View file

@ -10,7 +10,7 @@ import (
"sync"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/safe"
"github.com/go-kit/kit/metrics"
@ -229,7 +229,7 @@ func checkHealth(serverURL *url.URL, backend *BackendConfig) error {
}
// NewLBStatusUpdater returns a new LbStatusUpdater
func NewLBStatusUpdater(bh BalancerHandler, svinfo *config.ServiceInfo) *LbStatusUpdater {
func NewLBStatusUpdater(bh BalancerHandler, svinfo *dynamic.ServiceInfo) *LbStatusUpdater {
return &LbStatusUpdater{
BalancerHandler: bh,
serviceInfo: svinfo,
@ -240,7 +240,7 @@ func NewLBStatusUpdater(bh BalancerHandler, svinfo *config.ServiceInfo) *LbStatu
// so it can keep track of the status of a server in the ServiceInfo.
type LbStatusUpdater struct {
BalancerHandler
serviceInfo *config.ServiceInfo // can be nil
serviceInfo *dynamic.ServiceInfo // can be nil
}
// RemoveServer removes the given server from the BalancerHandler,

View file

@ -9,7 +9,7 @@ import (
"testing"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -443,7 +443,7 @@ func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func TestLBStatusUpdater(t *testing.T) {
lb := &testLoadBalancer{RWMutex: &sync.RWMutex{}}
svInfo := &config.ServiceInfo{}
svInfo := &dynamic.ServiceInfo{}
lbsu := NewLBStatusUpdater(lb, svInfo)
newServer, err := url.Parse("http://foo.com")
assert.Nil(t, err)

View file

@ -8,7 +8,7 @@ import (
"sync"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/safe"
"github.com/containous/traefik/pkg/types"
@ -189,7 +189,7 @@ func registerPromState(ctx context.Context) bool {
// OnConfigurationUpdate receives the current configuration from Traefik.
// It then converts the configuration to the optimized package internal format
// and sets it to the promState.
func OnConfigurationUpdate(configurations config.Configurations) {
func OnConfigurationUpdate(configurations dynamic.Configurations) {
dynamicConfig := newDynamicConfig()
// FIXME metrics

View file

@ -8,7 +8,7 @@ import (
"testing"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
th "github.com/containous/traefik/pkg/testhelpers"
"github.com/containous/traefik/pkg/types"
"github.com/prometheus/client_golang/prometheus"
@ -276,8 +276,8 @@ func TestPrometheusMetricRemoval(t *testing.T) {
prometheusRegistry := RegisterPrometheus(context.Background(), &types.Prometheus{})
defer prometheus.Unregister(promState)
configurations := make(config.Configurations)
configurations["providerName"] = &config.Configuration{
configurations := make(dynamic.Configurations)
configurations["providerName"] = &dynamic.Configuration{
HTTP: th.BuildConfiguration(
th.WithRouters(
th.WithRouter("foo",

View file

@ -5,7 +5,7 @@ import (
"fmt"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -23,7 +23,7 @@ type addPrefix struct {
}
// New creates a new handler.
func New(ctx context.Context, next http.Handler, config config.AddPrefix, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.AddPrefix, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
var result *addPrefix

View file

@ -5,7 +5,7 @@ import (
"net/http"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
@ -15,16 +15,16 @@ import (
func TestNewAddPrefix(t *testing.T) {
testCases := []struct {
desc string
prefix config.AddPrefix
prefix dynamic.AddPrefix
expectsError bool
}{
{
desc: "Works with a non empty prefix",
prefix: config.AddPrefix{Prefix: "/a"},
prefix: dynamic.AddPrefix{Prefix: "/a"},
},
{
desc: "Fails if prefix is empty",
prefix: config.AddPrefix{Prefix: ""},
prefix: dynamic.AddPrefix{Prefix: ""},
expectsError: true,
},
}
@ -50,20 +50,20 @@ func TestAddPrefix(t *testing.T) {
logrus.SetLevel(logrus.DebugLevel)
testCases := []struct {
desc string
prefix config.AddPrefix
prefix dynamic.AddPrefix
path string
expectedPath string
expectedRawPath string
}{
{
desc: "Works with a regular path",
prefix: config.AddPrefix{Prefix: "/a"},
prefix: dynamic.AddPrefix{Prefix: "/a"},
path: "/b",
expectedPath: "/a/b",
},
{
desc: "Works with a raw path",
prefix: config.AddPrefix{Prefix: "/a"},
prefix: dynamic.AddPrefix{Prefix: "/a"},
path: "/b%2Fc",
expectedPath: "/a/b/c",
expectedRawPath: "/a/b%2Fc",

View file

@ -8,7 +8,7 @@ import (
"strings"
goauth "github.com/abbot/go-http-auth"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/middlewares/accesslog"
"github.com/containous/traefik/pkg/tracing"
@ -29,7 +29,7 @@ type basicAuth struct {
}
// NewBasic creates a basicAuth middleware.
func NewBasic(ctx context.Context, next http.Handler, authConfig config.BasicAuth, name string) (http.Handler, error) {
func NewBasic(ctx context.Context, next http.Handler, authConfig dynamic.BasicAuth, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, basicTypeName).Debug("Creating middleware")
users, err := getUsers(authConfig.UsersFile, authConfig.Users, basicUserParser)
if err != nil {

View file

@ -9,7 +9,7 @@ import (
"os"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -20,13 +20,13 @@ func TestBasicAuthFail(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.BasicAuth{
auth := dynamic.BasicAuth{
Users: []string{"test"},
}
_, err := NewBasic(context.Background(), next, auth, "authName")
require.Error(t, err)
auth2 := config.BasicAuth{
auth2 := dynamic.BasicAuth{
Users: []string{"test:test"},
}
authMiddleware, err := NewBasic(context.Background(), next, auth2, "authTest")
@ -49,7 +49,7 @@ func TestBasicAuthSuccess(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.BasicAuth{
auth := dynamic.BasicAuth{
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
}
authMiddleware, err := NewBasic(context.Background(), next, auth, "authName")
@ -79,7 +79,7 @@ func TestBasicAuthUserHeader(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.BasicAuth{
auth := dynamic.BasicAuth{
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
HeaderField: "X-Webauth-User",
}
@ -110,7 +110,7 @@ func TestBasicAuthHeaderRemoved(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.BasicAuth{
auth := dynamic.BasicAuth{
RemoveHeader: true,
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
}
@ -142,7 +142,7 @@ func TestBasicAuthHeaderPresent(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.BasicAuth{
auth := dynamic.BasicAuth{
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
}
middleware, err := NewBasic(context.Background(), next, auth, "authName")
@ -226,7 +226,7 @@ func TestBasicAuthUsersFromFile(t *testing.T) {
require.NoError(t, err)
// Creates the configuration for our Authenticator
authenticatorConfiguration := config.BasicAuth{
authenticatorConfiguration := dynamic.BasicAuth{
Users: test.givenUsers,
UsersFile: usersFile.Name(),
Realm: test.realm,

View file

@ -8,7 +8,7 @@ import (
"strings"
goauth "github.com/abbot/go-http-auth"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/middlewares/accesslog"
"github.com/containous/traefik/pkg/tracing"
@ -29,7 +29,7 @@ type digestAuth struct {
}
// NewDigest creates a digest auth middleware.
func NewDigest(ctx context.Context, next http.Handler, authConfig config.DigestAuth, name string) (http.Handler, error) {
func NewDigest(ctx context.Context, next http.Handler, authConfig dynamic.DigestAuth, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, digestTypeName).Debug("Creating middleware")
users, err := getUsers(authConfig.UsersFile, authConfig.Users, digestUserParser)
if err != nil {

View file

@ -9,7 +9,7 @@ import (
"os"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -20,7 +20,7 @@ func TestDigestAuthError(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.DigestAuth{
auth := dynamic.DigestAuth{
Users: []string{"test"},
}
_, err := NewDigest(context.Background(), next, auth, "authName")
@ -32,7 +32,7 @@ func TestDigestAuthFail(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.DigestAuth{
auth := dynamic.DigestAuth{
Users: []string{"test:traefik:a2688e031edb4be6a3797f3882655c05"},
}
authMiddleware, err := NewDigest(context.Background(), next, auth, "authName")
@ -101,7 +101,7 @@ func TestDigestAuthUsersFromFile(t *testing.T) {
require.NoError(t, err)
// Creates the configuration for our Authenticator
authenticatorConfiguration := config.DigestAuth{
authenticatorConfiguration := dynamic.DigestAuth{
Users: test.givenUsers,
UsersFile: usersFile.Name(),
Realm: test.realm,

View file

@ -9,7 +9,7 @@ import (
"net/http"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -33,7 +33,7 @@ type forwardAuth struct {
}
// NewForward creates a forward auth middleware.
func NewForward(ctx context.Context, next http.Handler, config config.ForwardAuth, name string) (http.Handler, error) {
func NewForward(ctx context.Context, next http.Handler, config dynamic.ForwardAuth, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, forwardedTypeName).Debug("Creating middleware")
fa := &forwardAuth{

View file

@ -8,7 +8,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -25,7 +25,7 @@ func TestForwardAuthFail(t *testing.T) {
}))
defer server.Close()
middleware, err := NewForward(context.Background(), next, config.ForwardAuth{
middleware, err := NewForward(context.Background(), next, dynamic.ForwardAuth{
Address: server.URL,
}, "authTest")
require.NoError(t, err)
@ -63,7 +63,7 @@ func TestForwardAuthSuccess(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.ForwardAuth{
auth := dynamic.ForwardAuth{
Address: server.URL,
AuthResponseHeaders: []string{"X-Auth-User", "X-Auth-Group"},
}
@ -96,7 +96,7 @@ func TestForwardAuthRedirect(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.ForwardAuth{
auth := dynamic.ForwardAuth{
Address: authTs.URL,
}
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
@ -147,7 +147,7 @@ func TestForwardAuthRemoveHopByHopHeaders(t *testing.T) {
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "traefik")
})
auth := config.ForwardAuth{
auth := dynamic.ForwardAuth{
Address: authTs.URL,
}
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
@ -193,7 +193,7 @@ func TestForwardAuthFailResponseHeaders(t *testing.T) {
fmt.Fprintln(w, "traefik")
})
auth := config.ForwardAuth{
auth := dynamic.ForwardAuth{
Address: authTs.URL,
}
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")

View file

@ -4,7 +4,7 @@ import (
"context"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -21,7 +21,7 @@ type buffer struct {
}
// New creates a buffering middleware.
func New(ctx context.Context, next http.Handler, config config.Buffering, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.Buffering, name string) (http.Handler, error) {
logger := middlewares.GetLogger(ctx, name, typeName)
logger.Debug("Creating middleware")
logger.Debug("Setting up buffering: request limits: %d (mem), %d (max), response limits: %d (mem), %d (max) with retry: '%s'",

View file

@ -5,7 +5,7 @@ import (
"net/http"
"github.com/containous/alice"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
)
@ -18,7 +18,7 @@ type chainBuilder interface {
}
// New creates a chain middleware
func New(ctx context.Context, next http.Handler, config config.Chain, builder chainBuilder, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.Chain, builder chainBuilder, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
middlewareChain := builder.BuildChain(ctx, config.Middlewares)

View file

@ -4,7 +4,7 @@ import (
"context"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
@ -22,7 +22,7 @@ type circuitBreaker struct {
}
// New creates a new circuit breaker middleware.
func New(ctx context.Context, next http.Handler, confCircuitBreaker config.CircuitBreaker, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, confCircuitBreaker dynamic.CircuitBreaker, name string) (http.Handler, error) {
expression := confCircuitBreaker.Expression
logger := middlewares.GetLogger(ctx, name, typeName)

View file

@ -11,7 +11,7 @@ import (
"strconv"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/containous/traefik/pkg/types"
@ -42,7 +42,7 @@ type customErrors struct {
}
// New creates a new custom error pages middleware.
func New(ctx context.Context, next http.Handler, config config.ErrorPage, serviceBuilder serviceBuilder, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.ErrorPage, serviceBuilder serviceBuilder, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
httpCodeRanges, err := types.NewHTTPCodeRanges(config.Status)

View file

@ -7,7 +7,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
@ -17,14 +17,14 @@ import (
func TestHandler(t *testing.T) {
testCases := []struct {
desc string
errorPage *config.ErrorPage
errorPage *dynamic.ErrorPage
backendCode int
backendErrorHandler http.HandlerFunc
validate func(t *testing.T, recorder *httptest.ResponseRecorder)
}{
{
desc: "no error",
errorPage: &config.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
backendCode: http.StatusOK,
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "My error page.")
@ -36,7 +36,7 @@ func TestHandler(t *testing.T) {
},
{
desc: "in the range",
errorPage: &config.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
backendCode: http.StatusInternalServerError,
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "My error page.")
@ -49,7 +49,7 @@ func TestHandler(t *testing.T) {
},
{
desc: "not in the range",
errorPage: &config.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/test", Status: []string{"500-501", "503-599"}},
backendCode: http.StatusBadGateway,
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "My error page.")
@ -62,7 +62,7 @@ func TestHandler(t *testing.T) {
},
{
desc: "query replacement",
errorPage: &config.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503-503"}},
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503-503"}},
backendCode: http.StatusServiceUnavailable,
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/503" {
@ -79,7 +79,7 @@ func TestHandler(t *testing.T) {
},
{
desc: "Single code",
errorPage: &config.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503"}},
errorPage: &dynamic.ErrorPage{Service: "error", Query: "/{status}", Status: []string{"503"}},
backendCode: http.StatusServiceUnavailable,
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.RequestURI == "/503" {

View file

@ -8,7 +8,7 @@ import (
"strconv"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -26,7 +26,7 @@ type headers struct {
}
// New creates a Headers middleware.
func New(ctx context.Context, next http.Handler, config config.Headers, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.Headers, name string) (http.Handler, error) {
// HeaderMiddleware -> SecureMiddleWare -> next
logger := middlewares.GetLogger(ctx, name, typeName)
logger.Debug("Creating middleware")
@ -73,7 +73,7 @@ type secureHeader struct {
}
// newSecure constructs a new secure instance with supplied options.
func newSecure(next http.Handler, headers config.Headers) *secureHeader {
func newSecure(next http.Handler, headers dynamic.Headers) *secureHeader {
opt := secure.Options{
BrowserXssFilter: headers.BrowserXSSFilter,
ContentTypeNosniff: headers.ContentTypeNosniff,
@ -111,11 +111,11 @@ func (s secureHeader) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// provided to configure which features should be enabled, and the ability to override a few of the default values.
type Header struct {
next http.Handler
headers *config.Headers
headers *dynamic.Headers
}
// NewHeader constructs a new header instance from supplied frontend header struct.
func NewHeader(next http.Handler, headers config.Headers) *Header {
func NewHeader(next http.Handler, headers dynamic.Headers) *Header {
return &Header{
next: next,
headers: &headers,

View file

@ -8,7 +8,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/containous/traefik/pkg/tracing"
"github.com/stretchr/testify/assert"
@ -18,7 +18,7 @@ import (
func TestCustomRequestHeader(t *testing.T) {
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
header := NewHeader(emptyHandler, config.Headers{
header := NewHeader(emptyHandler, dynamic.Headers{
CustomRequestHeaders: map[string]string{
"X-Custom-Request-Header": "test_request",
},
@ -36,7 +36,7 @@ func TestCustomRequestHeader(t *testing.T) {
func TestCustomRequestHeaderEmptyValue(t *testing.T) {
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
header := NewHeader(emptyHandler, config.Headers{
header := NewHeader(emptyHandler, dynamic.Headers{
CustomRequestHeaders: map[string]string{
"X-Custom-Request-Header": "test_request",
},
@ -50,7 +50,7 @@ func TestCustomRequestHeaderEmptyValue(t *testing.T) {
assert.Equal(t, http.StatusOK, res.Code)
assert.Equal(t, "test_request", req.Header.Get("X-Custom-Request-Header"))
header = NewHeader(emptyHandler, config.Headers{
header = NewHeader(emptyHandler, dynamic.Headers{
CustomRequestHeaders: map[string]string{
"X-Custom-Request-Header": "",
},
@ -86,7 +86,7 @@ func TestSecureHeader(t *testing.T) {
}
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
header, err := New(context.Background(), emptyHandler, config.Headers{
header, err := New(context.Background(), emptyHandler, dynamic.Headers{
AllowedHosts: []string{"foo.com", "bar.com"},
}, "foo")
require.NoError(t, err)
@ -119,7 +119,7 @@ func TestSSLForceHost(t *testing.T) {
{
desc: "http should return a 301",
host: "http://powpow.example.com",
secureMiddleware: newSecure(next, config.Headers{
secureMiddleware: newSecure(next, dynamic.Headers{
SSLRedirect: true,
SSLForceHost: true,
SSLHost: "powpow.example.com",
@ -129,7 +129,7 @@ func TestSSLForceHost(t *testing.T) {
{
desc: "http sub domain should return a 301",
host: "http://www.powpow.example.com",
secureMiddleware: newSecure(next, config.Headers{
secureMiddleware: newSecure(next, dynamic.Headers{
SSLRedirect: true,
SSLForceHost: true,
SSLHost: "powpow.example.com",
@ -139,7 +139,7 @@ func TestSSLForceHost(t *testing.T) {
{
desc: "https should return a 200",
host: "https://powpow.example.com",
secureMiddleware: newSecure(next, config.Headers{
secureMiddleware: newSecure(next, dynamic.Headers{
SSLRedirect: true,
SSLForceHost: true,
SSLHost: "powpow.example.com",
@ -149,7 +149,7 @@ func TestSSLForceHost(t *testing.T) {
{
desc: "https sub domain should return a 301",
host: "https://www.powpow.example.com",
secureMiddleware: newSecure(next, config.Headers{
secureMiddleware: newSecure(next, dynamic.Headers{
SSLRedirect: true,
SSLForceHost: true,
SSLHost: "powpow.example.com",
@ -159,7 +159,7 @@ func TestSSLForceHost(t *testing.T) {
{
desc: "http without force host and sub domain should return a 301",
host: "http://www.powpow.example.com",
secureMiddleware: newSecure(next, config.Headers{
secureMiddleware: newSecure(next, dynamic.Headers{
SSLRedirect: true,
SSLForceHost: false,
SSLHost: "powpow.example.com",
@ -169,7 +169,7 @@ func TestSSLForceHost(t *testing.T) {
{
desc: "https without force host and sub domain should return a 301",
host: "https://www.powpow.example.com",
secureMiddleware: newSecure(next, config.Headers{
secureMiddleware: newSecure(next, dynamic.Headers{
SSLRedirect: true,
SSLForceHost: false,
SSLHost: "powpow.example.com",
@ -201,7 +201,7 @@ func TestCORSPreflights(t *testing.T) {
}{
{
desc: "Test Simple Preflight",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
AccessControlAllowOrigin: "origin-list-or-null",
AccessControlMaxAge: 600,
@ -219,7 +219,7 @@ func TestCORSPreflights(t *testing.T) {
},
{
desc: "Wildcard origin Preflight",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
AccessControlAllowOrigin: "*",
AccessControlMaxAge: 600,
@ -237,7 +237,7 @@ func TestCORSPreflights(t *testing.T) {
},
{
desc: "Allow Credentials Preflight",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
AccessControlAllowOrigin: "*",
AccessControlAllowCredentials: true,
@ -257,7 +257,7 @@ func TestCORSPreflights(t *testing.T) {
},
{
desc: "Allow Headers Preflight",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
AccessControlAllowOrigin: "*",
AccessControlAllowHeaders: []string{"origin", "X-Forwarded-For"},
@ -293,14 +293,14 @@ func TestCORSPreflights(t *testing.T) {
func TestEmptyHeaderObject(t *testing.T) {
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
_, err := New(context.Background(), next, config.Headers{}, "testing")
_, err := New(context.Background(), next, dynamic.Headers{}, "testing")
require.Errorf(t, err, "headers configuration not valid")
}
func TestCustomHeaderHandler(t *testing.T) {
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
header, _ := New(context.Background(), next, config.Headers{
header, _ := New(context.Background(), next, dynamic.Headers{
CustomRequestHeaders: map[string]string{
"X-Custom-Request-Header": "test_request",
},
@ -342,7 +342,7 @@ func TestCORSResponses(t *testing.T) {
}{
{
desc: "Test Simple Request",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "origin-list-or-null",
}),
requestHeaders: map[string][]string{
@ -354,7 +354,7 @@ func TestCORSResponses(t *testing.T) {
},
{
desc: "Wildcard origin Request",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "*",
}),
requestHeaders: map[string][]string{
@ -366,7 +366,7 @@ func TestCORSResponses(t *testing.T) {
},
{
desc: "Empty origin Request",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "origin-list-or-null",
}),
requestHeaders: map[string][]string{},
@ -376,13 +376,13 @@ func TestCORSResponses(t *testing.T) {
},
{
desc: "Not Defined origin Request",
header: NewHeader(emptyHandler, config.Headers{}),
header: NewHeader(emptyHandler, dynamic.Headers{}),
requestHeaders: map[string][]string{},
expected: map[string][]string{},
},
{
desc: "Allow Credentials Request",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "*",
AccessControlAllowCredentials: true,
}),
@ -396,7 +396,7 @@ func TestCORSResponses(t *testing.T) {
},
{
desc: "Expose Headers Request",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "*",
AccessControlExposeHeaders: []string{"origin", "X-Forwarded-For"},
}),
@ -410,7 +410,7 @@ func TestCORSResponses(t *testing.T) {
},
{
desc: "Test Simple Request with Vary Headers",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "origin-list-or-null",
AddVaryHeader: true,
}),
@ -424,7 +424,7 @@ func TestCORSResponses(t *testing.T) {
},
{
desc: "Test Simple Request with Vary Headers and non-empty response",
header: NewHeader(nonEmptyHandler, config.Headers{
header: NewHeader(nonEmptyHandler, dynamic.Headers{
AccessControlAllowOrigin: "origin-list-or-null",
AddVaryHeader: true,
}),
@ -462,7 +462,7 @@ func TestCustomResponseHeaders(t *testing.T) {
}{
{
desc: "Test Simple Response",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
CustomResponseHeaders: map[string]string{
"Testing": "foo",
"Testing2": "bar",
@ -475,7 +475,7 @@ func TestCustomResponseHeaders(t *testing.T) {
},
{
desc: "Deleting Custom Header",
header: NewHeader(emptyHandler, config.Headers{
header: NewHeader(emptyHandler, dynamic.Headers{
CustomResponseHeaders: map[string]string{
"Testing": "foo",
"Testing2": "",

View file

@ -6,7 +6,7 @@ import (
"fmt"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/ip"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
@ -27,7 +27,7 @@ type ipWhiteLister struct {
}
// New builds a new IPWhiteLister given a list of CIDR-Strings to whitelist
func New(ctx context.Context, next http.Handler, config config.IPWhiteList, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.IPWhiteList, name string) (http.Handler, error) {
logger := middlewares.GetLogger(ctx, name, typeName)
logger.Debug("Creating middleware")

View file

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -14,19 +14,19 @@ import (
func TestNewIPWhiteLister(t *testing.T) {
testCases := []struct {
desc string
whiteList config.IPWhiteList
whiteList dynamic.IPWhiteList
expectedError bool
}{
{
desc: "invalid IP",
whiteList: config.IPWhiteList{
whiteList: dynamic.IPWhiteList{
SourceRange: []string{"foo"},
},
expectedError: true,
},
{
desc: "valid IP",
whiteList: config.IPWhiteList{
whiteList: dynamic.IPWhiteList{
SourceRange: []string{"10.10.10.10"},
},
},
@ -53,13 +53,13 @@ func TestNewIPWhiteLister(t *testing.T) {
func TestIPWhiteLister_ServeHTTP(t *testing.T) {
testCases := []struct {
desc string
whiteList config.IPWhiteList
whiteList dynamic.IPWhiteList
remoteAddr string
expected int
}{
{
desc: "authorized with remote address",
whiteList: config.IPWhiteList{
whiteList: dynamic.IPWhiteList{
SourceRange: []string{"20.20.20.20"},
},
remoteAddr: "20.20.20.20:1234",
@ -67,7 +67,7 @@ func TestIPWhiteLister_ServeHTTP(t *testing.T) {
},
{
desc: "non authorized with remote address",
whiteList: config.IPWhiteList{
whiteList: dynamic.IPWhiteList{
SourceRange: []string{"20.20.20.20"},
},
remoteAddr: "20.20.20.21:1234",

View file

@ -5,7 +5,7 @@ import (
"fmt"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -23,7 +23,7 @@ type maxConnection struct {
}
// New creates a max connection middleware.
func New(ctx context.Context, next http.Handler, maxConns config.MaxConn, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, maxConns dynamic.MaxConn, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
extractFunc, err := utils.NewExtractor(maxConns.ExtractorFunc)

View file

@ -11,7 +11,7 @@ import (
"net/url"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
@ -40,7 +40,7 @@ type DistinguishedNameOptions struct {
StateOrProvinceName bool
}
func newDistinguishedNameOptions(info *config.TLSCLientCertificateDNInfo) *DistinguishedNameOptions {
func newDistinguishedNameOptions(info *dynamic.TLSCLientCertificateDNInfo) *DistinguishedNameOptions {
if info == nil {
return nil
}
@ -65,7 +65,7 @@ type passTLSClientCert struct {
}
// New constructs a new PassTLSClientCert instance from supplied frontend header struct.
func New(ctx context.Context, next http.Handler, config config.PassTLSClientCert, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.PassTLSClientCert, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
return &passTLSClientCert{
@ -85,7 +85,7 @@ type tlsClientCertificateInfo struct {
issuer *DistinguishedNameOptions
}
func newTLSClientInfo(info *config.TLSClientCertificateInfo) *tlsClientCertificateInfo {
func newTLSClientInfo(info *dynamic.TLSClientCertificateInfo) *tlsClientCertificateInfo {
if info == nil {
return nil
}

View file

@ -13,7 +13,7 @@ import (
"strings"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/require"
)
@ -367,7 +367,7 @@ func TestTLSClientHeadersWithPEM(t *testing.T) {
testCases := []struct {
desc string
certContents []string // set the request TLS attribute if defined
config config.PassTLSClientCert
config dynamic.PassTLSClientCert
expectedHeader string
}{
{
@ -379,24 +379,24 @@ func TestTLSClientHeadersWithPEM(t *testing.T) {
},
{
desc: "No TLS, with pem option true",
config: config.PassTLSClientCert{PEM: true},
config: dynamic.PassTLSClientCert{PEM: true},
},
{
desc: "TLS with simple certificate, with pem option true",
certContents: []string{minimalCheeseCrt},
config: config.PassTLSClientCert{PEM: true},
config: dynamic.PassTLSClientCert{PEM: true},
expectedHeader: getCleanCertContents([]string{minimalCert}),
},
{
desc: "TLS with complete certificate, with pem option true",
certContents: []string{minimalCheeseCrt},
config: config.PassTLSClientCert{PEM: true},
config: dynamic.PassTLSClientCert{PEM: true},
expectedHeader: getCleanCertContents([]string{minimalCheeseCrt}),
},
{
desc: "TLS with two certificate, with pem option true",
certContents: []string{minimalCert, minimalCheeseCrt},
config: config.PassTLSClientCert{PEM: true},
config: dynamic.PassTLSClientCert{PEM: true},
expectedHeader: getCleanCertContents([]string{minimalCert, minimalCheeseCrt}),
},
}
@ -488,7 +488,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
testCases := []struct {
desc string
certContents []string // set the request TLS attribute if defined
config config.PassTLSClientCert
config dynamic.PassTLSClientCert
expectedHeader string
}{
{
@ -500,9 +500,9 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
},
{
desc: "No TLS, with subject info",
config: config.PassTLSClientCert{
Info: &config.TLSClientCertificateInfo{
Subject: &config.TLSCLientCertificateDNInfo{
config: dynamic.PassTLSClientCert{
Info: &dynamic.TLSClientCertificateInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
CommonName: true,
Organization: true,
Locality: true,
@ -515,22 +515,22 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
},
{
desc: "No TLS, with pem option false with empty subject info",
config: config.PassTLSClientCert{
config: dynamic.PassTLSClientCert{
PEM: false,
Info: &config.TLSClientCertificateInfo{
Subject: &config.TLSCLientCertificateDNInfo{},
Info: &dynamic.TLSClientCertificateInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{},
},
},
},
{
desc: "TLS with simple certificate, with all info",
certContents: []string{minimalCheeseCrt},
config: config.PassTLSClientCert{
Info: &config.TLSClientCertificateInfo{
config: dynamic.PassTLSClientCert{
Info: &dynamic.TLSClientCertificateInfo{
NotAfter: true,
NotBefore: true,
Sans: true,
Subject: &config.TLSCLientCertificateDNInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
CommonName: true,
Country: true,
DomainComponent: true,
@ -539,7 +539,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
Province: true,
SerialNumber: true,
},
Issuer: &config.TLSCLientCertificateDNInfo{
Issuer: &dynamic.TLSCLientCertificateDNInfo{
CommonName: true,
Country: true,
DomainComponent: true,
@ -555,14 +555,14 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
{
desc: "TLS with simple certificate, with some info",
certContents: []string{minimalCheeseCrt},
config: config.PassTLSClientCert{
Info: &config.TLSClientCertificateInfo{
config: dynamic.PassTLSClientCert{
Info: &dynamic.TLSClientCertificateInfo{
NotAfter: true,
Sans: true,
Subject: &config.TLSCLientCertificateDNInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
Organization: true,
},
Issuer: &config.TLSCLientCertificateDNInfo{
Issuer: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
},
},
@ -572,12 +572,12 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
{
desc: "TLS with complete certificate, with all info",
certContents: []string{completeCheeseCrt},
config: config.PassTLSClientCert{
Info: &config.TLSClientCertificateInfo{
config: dynamic.PassTLSClientCert{
Info: &dynamic.TLSClientCertificateInfo{
NotAfter: true,
NotBefore: true,
Sans: true,
Subject: &config.TLSCLientCertificateDNInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -586,7 +586,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
SerialNumber: true,
DomainComponent: true,
},
Issuer: &config.TLSCLientCertificateDNInfo{
Issuer: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -602,12 +602,12 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
{
desc: "TLS with 2 certificates, with all info",
certContents: []string{minimalCheeseCrt, completeCheeseCrt},
config: config.PassTLSClientCert{
Info: &config.TLSClientCertificateInfo{
config: dynamic.PassTLSClientCert{
Info: &dynamic.TLSClientCertificateInfo{
NotAfter: true,
NotBefore: true,
Sans: true,
Subject: &config.TLSCLientCertificateDNInfo{
Subject: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,
@ -616,7 +616,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
SerialNumber: true,
DomainComponent: true,
},
Issuer: &config.TLSCLientCertificateDNInfo{
Issuer: &dynamic.TLSCLientCertificateDNInfo{
Country: true,
Province: true,
Locality: true,

View file

@ -5,7 +5,7 @@ import (
"net/http"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -23,7 +23,7 @@ type rateLimiter struct {
}
// New creates rate limiter middleware.
func New(ctx context.Context, next http.Handler, config config.RateLimit, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.RateLimit, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
extractFunc, err := utils.NewExtractor(config.ExtractorFunc)

View file

@ -4,7 +4,7 @@ import (
"context"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
)
@ -13,7 +13,7 @@ const (
)
// NewRedirectRegex creates a redirect middleware.
func NewRedirectRegex(ctx context.Context, next http.Handler, conf config.RedirectRegex, name string) (http.Handler, error) {
func NewRedirectRegex(ctx context.Context, next http.Handler, conf dynamic.RedirectRegex, name string) (http.Handler, error) {
logger := middlewares.GetLogger(ctx, name, typeRegexName)
logger.Debug("Creating middleware")
logger.Debugf("Setting up redirection from %s to %s", conf.Regex, conf.Replacement)

View file

@ -7,7 +7,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -16,7 +16,7 @@ import (
func TestRedirectRegexHandler(t *testing.T) {
testCases := []struct {
desc string
config config.RedirectRegex
config dynamic.RedirectRegex
method string
url string
secured bool
@ -26,7 +26,7 @@ func TestRedirectRegexHandler(t *testing.T) {
}{
{
desc: "simple redirection",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
Replacement: "https://${1}bar$2:443$4",
},
@ -36,7 +36,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "use request header",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
Replacement: `https://${1}{{ .Request.Header.Get "X-Foo" }}$2:443$4`,
},
@ -46,7 +46,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "URL doesn't match regex",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
Replacement: "https://${1}bar$2:443$4",
},
@ -55,7 +55,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "invalid rewritten URL",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^(.*)$`,
Replacement: "http://192.168.0.%31/",
},
@ -64,7 +64,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "invalid regex",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^(.*`,
Replacement: "$1",
},
@ -73,7 +73,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTP to HTTPS permanent",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^http://`,
Replacement: "https://$1",
Permanent: true,
@ -84,7 +84,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTPS to HTTP permanent",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `https://foo`,
Replacement: "http://foo",
Permanent: true,
@ -96,7 +96,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTP to HTTPS",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `http://foo:80`,
Replacement: "https://foo:443",
},
@ -106,7 +106,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTPS to HTTP",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `https://foo:443`,
Replacement: "http://foo:80",
},
@ -117,7 +117,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTP to HTTP",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `http://foo:80`,
Replacement: "http://foo:88",
},
@ -127,7 +127,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTP to HTTP POST",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^http://`,
Replacement: "https://$1",
},
@ -138,7 +138,7 @@ func TestRedirectRegexHandler(t *testing.T) {
},
{
desc: "HTTP to HTTP POST permanent",
config: config.RedirectRegex{
config: dynamic.RedirectRegex{
Regex: `^http://`,
Replacement: "https://$1",
Permanent: true,

View file

@ -5,7 +5,7 @@ import (
"errors"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
)
@ -15,7 +15,7 @@ const (
)
// NewRedirectScheme creates a new RedirectScheme middleware.
func NewRedirectScheme(ctx context.Context, next http.Handler, conf config.RedirectScheme, name string) (http.Handler, error) {
func NewRedirectScheme(ctx context.Context, next http.Handler, conf dynamic.RedirectScheme, name string) (http.Handler, error) {
logger := middlewares.GetLogger(ctx, name, typeSchemeName)
logger.Debug("Creating middleware")
logger.Debugf("Setting up redirection to %s %s", conf.Scheme, conf.Port)

View file

@ -8,7 +8,7 @@ import (
"regexp"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -16,7 +16,7 @@ import (
func TestRedirectSchemeHandler(t *testing.T) {
testCases := []struct {
desc string
config config.RedirectScheme
config dynamic.RedirectScheme
method string
url string
secured bool
@ -26,13 +26,13 @@ func TestRedirectSchemeHandler(t *testing.T) {
}{
{
desc: "Without scheme",
config: config.RedirectScheme{},
config: dynamic.RedirectScheme{},
url: "http://foo",
errorExpected: true,
},
{
desc: "HTTP to HTTPS",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
},
url: "http://foo",
@ -41,7 +41,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP with port to HTTPS without port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
},
url: "http://foo:8080",
@ -50,7 +50,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP without port to HTTPS with port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
Port: "8443",
},
@ -60,7 +60,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP with port to HTTPS with port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
Port: "8443",
},
@ -70,7 +70,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTPS with port to HTTPS with port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
Port: "8443",
},
@ -80,7 +80,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTPS with port to HTTPS without port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
},
url: "https://foo:8000",
@ -89,7 +89,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "redirection to HTTPS without port from an URL already in https",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
},
url: "https://foo:8000/theother",
@ -98,7 +98,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP to HTTPS permanent",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
Port: "8443",
Permanent: true,
@ -109,7 +109,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "to HTTP 80",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "http",
Port: "80",
},
@ -119,7 +119,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP to wss",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "wss",
Port: "9443",
},
@ -129,7 +129,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP to wss without port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "wss",
},
url: "http://foo",
@ -138,7 +138,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP with port to wss without port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "wss",
},
url: "http://foo:5678",
@ -147,7 +147,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP to HTTPS without port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
},
url: "http://foo:443",
@ -156,7 +156,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTP port redirection",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "http",
Port: "8181",
},
@ -166,7 +166,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
},
{
desc: "HTTPS with port 80 to HTTPS without port",
config: config.RedirectScheme{
config: dynamic.RedirectScheme{
Scheme: "https",
},
url: "https://foo:80",

View file

@ -4,7 +4,7 @@ import (
"context"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -24,7 +24,7 @@ type replacePath struct {
}
// New creates a new replace path middleware.
func New(ctx context.Context, next http.Handler, config config.ReplacePath, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.ReplacePath, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
return &replacePath{

View file

@ -5,14 +5,14 @@ import (
"net/http"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestReplacePath(t *testing.T) {
var replacementConfig = config.ReplacePath{
var replacementConfig = dynamic.ReplacePath{
Path: "/replacement-path",
}

View file

@ -7,7 +7,7 @@ import (
"regexp"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/middlewares/replacepath"
"github.com/containous/traefik/pkg/tracing"
@ -27,7 +27,7 @@ type replacePathRegex struct {
}
// New creates a new replace path regex middleware.
func New(ctx context.Context, next http.Handler, config config.ReplacePathRegex, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.ReplacePathRegex, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
exp, err := regexp.Compile(strings.TrimSpace(config.Regex))

View file

@ -5,7 +5,7 @@ import (
"net/http"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/replacepath"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
@ -16,7 +16,7 @@ func TestReplacePathRegex(t *testing.T) {
testCases := []struct {
desc string
path string
config config.ReplacePathRegex
config dynamic.ReplacePathRegex
expectedPath string
expectedHeader string
expectsError bool
@ -24,7 +24,7 @@ func TestReplacePathRegex(t *testing.T) {
{
desc: "simple regex",
path: "/whoami/and/whoami",
config: config.ReplacePathRegex{
config: dynamic.ReplacePathRegex{
Replacement: "/who-am-i/$1",
Regex: `^/whoami/(.*)`,
},
@ -34,7 +34,7 @@ func TestReplacePathRegex(t *testing.T) {
{
desc: "simple replace (no regex)",
path: "/whoami/and/whoami",
config: config.ReplacePathRegex{
config: dynamic.ReplacePathRegex{
Replacement: "/who-am-i",
Regex: `/whoami`,
},
@ -44,7 +44,7 @@ func TestReplacePathRegex(t *testing.T) {
{
desc: "no match",
path: "/whoami/and/whoami",
config: config.ReplacePathRegex{
config: dynamic.ReplacePathRegex{
Replacement: "/whoami",
Regex: `/no-match`,
},
@ -53,7 +53,7 @@ func TestReplacePathRegex(t *testing.T) {
{
desc: "multiple replacement",
path: "/downloads/src/source.go",
config: config.ReplacePathRegex{
config: dynamic.ReplacePathRegex{
Replacement: "/downloads/$1-$2",
Regex: `^(?i)/downloads/([^/]+)/([^/]+)$`,
},
@ -63,7 +63,7 @@ func TestReplacePathRegex(t *testing.T) {
{
desc: "invalid regular expression",
path: "/invalid/regexp/test",
config: config.ReplacePathRegex{
config: dynamic.ReplacePathRegex{
Replacement: "/valid/regexp/$1",
Regex: `^(?err)/invalid/regexp/([^/]+)$`,
},

View file

@ -9,7 +9,7 @@ import (
"net/http"
"net/http/httptrace"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -42,7 +42,7 @@ type retry struct {
}
// New returns a new retry middleware.
func New(ctx context.Context, next http.Handler, config config.Retry, listener Listener, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.Retry, listener Listener, name string) (http.Handler, error) {
logger := middlewares.GetLogger(ctx, name, typeName)
logger.Debug("Creating middleware")

View file

@ -9,7 +9,7 @@ import (
"strings"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/emptybackendhandler"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/gorilla/websocket"
@ -22,42 +22,42 @@ import (
func TestRetry(t *testing.T) {
testCases := []struct {
desc string
config config.Retry
config dynamic.Retry
wantRetryAttempts int
wantResponseStatus int
amountFaultyEndpoints int
}{
{
desc: "no retry on success",
config: config.Retry{Attempts: 1},
config: dynamic.Retry{Attempts: 1},
wantRetryAttempts: 0,
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 0,
},
{
desc: "no retry when max request attempts is one",
config: config.Retry{Attempts: 1},
config: dynamic.Retry{Attempts: 1},
wantRetryAttempts: 0,
wantResponseStatus: http.StatusInternalServerError,
amountFaultyEndpoints: 1,
},
{
desc: "one retry when one server is faulty",
config: config.Retry{Attempts: 2},
config: dynamic.Retry{Attempts: 2},
wantRetryAttempts: 1,
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 1,
},
{
desc: "two retries when two servers are faulty",
config: config.Retry{Attempts: 3},
config: dynamic.Retry{Attempts: 3},
wantRetryAttempts: 2,
wantResponseStatus: http.StatusOK,
amountFaultyEndpoints: 2,
},
{
desc: "max attempts exhausted delivers the 5xx response",
config: config.Retry{Attempts: 3},
config: dynamic.Retry{Attempts: 3},
wantRetryAttempts: 2,
wantResponseStatus: http.StatusInternalServerError,
amountFaultyEndpoints: 3,
@ -124,7 +124,7 @@ func TestRetryEmptyServerList(t *testing.T) {
next := emptybackendhandler.New(loadBalancer)
retryListener := &countingRetryListener{}
retry, err := New(context.Background(), next, config.Retry{Attempts: 3}, retryListener, "traefikTest")
retry, err := New(context.Background(), next, dynamic.Retry{Attempts: 3}, retryListener, "traefikTest")
require.NoError(t, err)
recorder := httptest.NewRecorder()
@ -172,7 +172,7 @@ func TestMultipleRetriesShouldNotLooseHeaders(t *testing.T) {
rw.WriteHeader(http.StatusNoContent)
})
retry, err := New(context.Background(), next, config.Retry{Attempts: 3}, &countingRetryListener{}, "traefikTest")
retry, err := New(context.Background(), next, dynamic.Retry{Attempts: 3}, &countingRetryListener{}, "traefikTest")
require.NoError(t, err)
responseRecorder := httptest.NewRecorder()
@ -218,7 +218,7 @@ func TestRetryWithFlush(t *testing.T) {
}
})
retry, err := New(context.Background(), next, config.Retry{Attempts: 1}, &countingRetryListener{}, "traefikTest")
retry, err := New(context.Background(), next, dynamic.Retry{Attempts: 1}, &countingRetryListener{}, "traefikTest")
require.NoError(t, err)
responseRecorder := httptest.NewRecorder()
@ -293,7 +293,7 @@ func TestRetryWebsocket(t *testing.T) {
}
retryListener := &countingRetryListener{}
retryH, err := New(context.Background(), loadBalancer, config.Retry{Attempts: test.maxRequestAttempts}, retryListener, "traefikTest")
retryH, err := New(context.Background(), loadBalancer, dynamic.Retry{Attempts: test.maxRequestAttempts}, retryListener, "traefikTest")
require.NoError(t, err)
retryServer := httptest.NewServer(retryH)

View file

@ -5,7 +5,7 @@ import (
"net/http"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/tracing"
"github.com/opentracing/opentracing-go/ext"
@ -25,7 +25,7 @@ type stripPrefix struct {
}
// New creates a new strip prefix middleware.
func New(ctx context.Context, next http.Handler, config config.StripPrefix, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.StripPrefix, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
return &stripPrefix{
prefixes: config.Prefixes,

View file

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -15,7 +15,7 @@ import (
func TestStripPrefix(t *testing.T) {
testCases := []struct {
desc string
config config.StripPrefix
config dynamic.StripPrefix
path string
expectedStatusCode int
expectedPath string
@ -24,7 +24,7 @@ func TestStripPrefix(t *testing.T) {
}{
{
desc: "no prefixes configured",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{},
},
path: "/noprefixes",
@ -32,7 +32,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "wildcard (.*) requests",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/"},
},
path: "/",
@ -42,7 +42,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "prefix and path matching",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat"},
},
path: "/stat",
@ -52,7 +52,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "path prefix on exactly matching path",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat/"},
},
path: "/stat/",
@ -62,7 +62,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "path prefix on matching longer path",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat/"},
},
path: "/stat/us",
@ -72,7 +72,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "path prefix on mismatching path",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat/"},
},
path: "/status",
@ -80,7 +80,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "general prefix on matching path",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat"},
},
path: "/stat/",
@ -90,7 +90,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "earlier prefix matching",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat", "/stat/us"},
},
@ -101,7 +101,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "later prefix matching",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/mismatch", "/stat"},
},
path: "/stat",
@ -111,7 +111,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "prefix matching within slash boundaries",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat"},
},
path: "/status",
@ -121,7 +121,7 @@ func TestStripPrefix(t *testing.T) {
},
{
desc: "raw path is also stripped",
config: config.StripPrefix{
config: dynamic.StripPrefix{
Prefixes: []string{"/stat"},
},
path: "/stat/a%2Fb",

View file

@ -6,7 +6,7 @@ import (
"strings"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares"
"github.com/containous/traefik/pkg/middlewares/stripprefix"
"github.com/containous/traefik/pkg/tracing"
@ -25,7 +25,7 @@ type stripPrefixRegex struct {
}
// New builds a new StripPrefixRegex middleware.
func New(ctx context.Context, next http.Handler, config config.StripPrefixRegex, name string) (http.Handler, error) {
func New(ctx context.Context, next http.Handler, config dynamic.StripPrefixRegex, name string) (http.Handler, error) {
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
stripPrefix := stripPrefixRegex{

View file

@ -6,7 +6,7 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/stripprefix"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
@ -14,7 +14,7 @@ import (
)
func TestStripPrefixRegex(t *testing.T) {
testPrefixRegex := config.StripPrefixRegex{
testPrefixRegex := dynamic.StripPrefixRegex{
Regex: []string{"/a/api/", "/b/{regex}/", "/c/{category}/{id:[0-9]+}/"},
}

View file

@ -14,7 +14,7 @@ import (
"sync"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/rules"
"github.com/containous/traefik/pkg/safe"
@ -89,10 +89,10 @@ type Provider struct {
account *Account
client *lego.Client
certsChan chan *Certificate
configurationChan chan<- config.Message
configurationChan chan<- dynamic.Message
tlsManager *traefiktls.Manager
clientMutex sync.Mutex
configFromListenerChan chan config.Configuration
configFromListenerChan chan dynamic.Configuration
pool *safe.Pool
resolvingDomains map[string]struct{}
resolvingDomainsMutex sync.RWMutex
@ -104,12 +104,12 @@ func (p *Provider) SetTLSManager(tlsManager *traefiktls.Manager) {
}
// SetConfigListenerChan initializes the configFromListenerChan
func (p *Provider) SetConfigListenerChan(configFromListenerChan chan config.Configuration) {
func (p *Provider) SetConfigListenerChan(configFromListenerChan chan dynamic.Configuration) {
p.configFromListenerChan = configFromListenerChan
}
// ListenConfiguration sets a new Configuration into the configFromListenerChan
func (p *Provider) ListenConfiguration(config config.Configuration) {
func (p *Provider) ListenConfiguration(config dynamic.Configuration) {
p.configFromListenerChan <- config
}
@ -187,7 +187,7 @@ func isAccountMatchingCaServer(ctx context.Context, accountURI string, serverURI
// Provide allows the file 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 {
ctx := log.With(context.Background(), log.Str(log.ProviderName, "acme"))
p.pool = pool
@ -581,15 +581,15 @@ func (p *Provider) saveCertificates() error {
}
func (p *Provider) refreshCertificates() {
conf := config.Message{
conf := dynamic.Message{
ProviderName: "ACME",
Configuration: &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
Configuration: &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
TLS: &config.TLSConfiguration{},
TLS: &dynamic.TLSConfiguration{},
},
}

View file

@ -3,7 +3,7 @@ package aggregator
import (
"encoding/json"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
@ -80,7 +80,7 @@ func (p ProviderAggregator) Init() error {
}
// Provide calls the provide method of every providers
func (p ProviderAggregator) Provide(configurationChan chan<- config.Message, pool *safe.Pool) error {
func (p ProviderAggregator) Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error {
if p.fileProvider != nil {
launchProvider(configurationChan, pool, p.fileProvider)
}
@ -94,7 +94,7 @@ func (p ProviderAggregator) Provide(configurationChan chan<- config.Message, poo
return nil
}
func launchProvider(configurationChan chan<- config.Message, pool *safe.Pool, prd provider.Provider) {
func launchProvider(configurationChan chan<- dynamic.Message, pool *safe.Pool, prd provider.Provider) {
jsonConf, err := json.Marshal(prd)
if err != nil {
log.WithoutContext().Debugf("Cannot marshal the provider configuration %T: %v", prd, err)

View file

@ -10,23 +10,23 @@ import (
"unicode"
"github.com/Masterminds/sprig"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
)
// Merge Merges multiple configurations.
func Merge(ctx context.Context, configurations map[string]*config.Configuration) *config.Configuration {
func Merge(ctx context.Context, configurations map[string]*dynamic.Configuration) *dynamic.Configuration {
logger := log.FromContext(ctx)
configuration := &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: make(map[string]*config.Router),
Middlewares: make(map[string]*config.Middleware),
Services: make(map[string]*config.Service),
configuration := &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: make(map[string]*dynamic.Router),
Middlewares: make(map[string]*dynamic.Middleware),
Services: make(map[string]*dynamic.Service),
},
TCP: &config.TCPConfiguration{
Routers: make(map[string]*config.TCPRouter),
Services: make(map[string]*config.TCPService),
TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService),
},
}
@ -123,7 +123,7 @@ func Merge(ctx context.Context, configurations map[string]*config.Configuration)
}
// AddServiceTCP Adds a service to a configurations.
func AddServiceTCP(configuration *config.TCPConfiguration, serviceName string, service *config.TCPService) bool {
func AddServiceTCP(configuration *dynamic.TCPConfiguration, serviceName string, service *dynamic.TCPService) bool {
if _, ok := configuration.Services[serviceName]; !ok {
configuration.Services[serviceName] = service
return true
@ -138,7 +138,7 @@ func AddServiceTCP(configuration *config.TCPConfiguration, serviceName string, s
}
// AddRouterTCP Adds a router to a configurations.
func AddRouterTCP(configuration *config.TCPConfiguration, routerName string, router *config.TCPRouter) bool {
func AddRouterTCP(configuration *dynamic.TCPConfiguration, routerName string, router *dynamic.TCPRouter) bool {
if _, ok := configuration.Routers[routerName]; !ok {
configuration.Routers[routerName] = router
return true
@ -148,7 +148,7 @@ func AddRouterTCP(configuration *config.TCPConfiguration, routerName string, rou
}
// AddService Adds a service to a configurations.
func AddService(configuration *config.HTTPConfiguration, serviceName string, service *config.Service) bool {
func AddService(configuration *dynamic.HTTPConfiguration, serviceName string, service *dynamic.Service) bool {
if _, ok := configuration.Services[serviceName]; !ok {
configuration.Services[serviceName] = service
return true
@ -163,7 +163,7 @@ func AddService(configuration *config.HTTPConfiguration, serviceName string, ser
}
// AddRouter Adds a router to a configurations.
func AddRouter(configuration *config.HTTPConfiguration, routerName string, router *config.Router) bool {
func AddRouter(configuration *dynamic.HTTPConfiguration, routerName string, router *dynamic.Router) bool {
if _, ok := configuration.Routers[routerName]; !ok {
configuration.Routers[routerName] = router
return true
@ -173,7 +173,7 @@ func AddRouter(configuration *config.HTTPConfiguration, routerName string, route
}
// AddMiddleware Adds a middleware to a configurations.
func AddMiddleware(configuration *config.HTTPConfiguration, middlewareName string, middleware *config.Middleware) bool {
func AddMiddleware(configuration *dynamic.HTTPConfiguration, middlewareName string, middleware *dynamic.Middleware) bool {
if _, ok := configuration.Middlewares[middlewareName]; !ok {
configuration.Middlewares[middlewareName] = middleware
return true
@ -195,7 +195,7 @@ func MakeDefaultRuleTemplate(defaultRule string, funcMap template.FuncMap) (*tem
}
// BuildTCPRouterConfiguration Builds a router configuration.
func BuildTCPRouterConfiguration(ctx context.Context, configuration *config.TCPConfiguration) {
func BuildTCPRouterConfiguration(ctx context.Context, configuration *dynamic.TCPConfiguration) {
for routerName, router := range configuration.Routers {
loggerRouter := log.FromContext(ctx).WithField(log.RouterName, routerName)
if len(router.Rule) == 0 {
@ -220,13 +220,13 @@ func BuildTCPRouterConfiguration(ctx context.Context, configuration *config.TCPC
}
// BuildRouterConfiguration Builds a router configuration.
func BuildRouterConfiguration(ctx context.Context, configuration *config.HTTPConfiguration, defaultRouterName string, defaultRuleTpl *template.Template, model interface{}) {
func BuildRouterConfiguration(ctx context.Context, configuration *dynamic.HTTPConfiguration, defaultRouterName string, defaultRuleTpl *template.Template, model interface{}) {
if len(configuration.Routers) == 0 {
if len(configuration.Services) > 1 {
log.FromContext(ctx).Info("Could not create a router for the container: too many services")
} else {
configuration.Routers = make(map[string]*config.Router)
configuration.Routers[defaultRouterName] = &config.Router{}
configuration.Routers = make(map[string]*dynamic.Router)
configuration.Routers[defaultRouterName] = &dynamic.Router{}
}
}

View file

@ -7,7 +7,7 @@ import (
"net"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/label"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
@ -15,8 +15,8 @@ import (
"github.com/docker/go-connections/nat"
)
func (p *Provider) buildConfiguration(ctx context.Context, containersInspected []dockerData) *config.Configuration {
configurations := make(map[string]*config.Configuration)
func (p *Provider) buildConfiguration(ctx context.Context, containersInspected []dockerData) *dynamic.Configuration {
configurations := make(map[string]*dynamic.Configuration)
for _, container := range containersInspected {
containerName := getServiceName(container) + "-" + container.ID
@ -73,13 +73,13 @@ func (p *Provider) buildConfiguration(ctx context.Context, containersInspected [
return provider.Merge(ctx, configurations)
}
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, container dockerData, configuration *config.TCPConfiguration) error {
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, container dockerData, configuration *dynamic.TCPConfiguration) error {
serviceName := getServiceName(container)
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*config.TCPService)
lb := &config.TCPLoadBalancerService{}
configuration.Services[serviceName] = &config.TCPService{
configuration.Services = make(map[string]*dynamic.TCPService)
lb := &dynamic.TCPLoadBalancerService{}
configuration.Services[serviceName] = &dynamic.TCPService{
LoadBalancer: lb,
}
}
@ -94,14 +94,14 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, container d
return nil
}
func (p *Provider) buildServiceConfiguration(ctx context.Context, container dockerData, configuration *config.HTTPConfiguration) error {
func (p *Provider) buildServiceConfiguration(ctx context.Context, container dockerData, configuration *dynamic.HTTPConfiguration) error {
serviceName := getServiceName(container)
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*config.Service)
lb := &config.LoadBalancerService{}
configuration.Services = make(map[string]*dynamic.Service)
lb := &dynamic.LoadBalancerService{}
lb.SetDefaults()
configuration.Services[serviceName] = &config.Service{
configuration.Services[serviceName] = &dynamic.Service{
LoadBalancer: lb,
}
}
@ -142,7 +142,7 @@ func (p *Provider) keepContainer(ctx context.Context, container dockerData) bool
return true
}
func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadBalancer *config.TCPLoadBalancerService) error {
func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadBalancer *dynamic.TCPLoadBalancerService) error {
serverPort := ""
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
serverPort = loadBalancer.Servers[0].Port
@ -153,9 +153,9 @@ func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadB
}
if len(loadBalancer.Servers) == 0 {
server := config.TCPServer{}
server := dynamic.TCPServer{}
loadBalancer.Servers = []config.TCPServer{server}
loadBalancer.Servers = []dynamic.TCPServer{server}
}
if serverPort != "" {
@ -171,7 +171,7 @@ func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadB
return nil
}
func (p *Provider) addServer(ctx context.Context, container dockerData, loadBalancer *config.LoadBalancerService) error {
func (p *Provider) addServer(ctx context.Context, container dockerData, loadBalancer *dynamic.LoadBalancerService) error {
serverPort := getLBServerPort(loadBalancer)
ip, port, err := p.getIPPort(ctx, container, serverPort)
if err != nil {
@ -179,10 +179,10 @@ func (p *Provider) addServer(ctx context.Context, container dockerData, loadBala
}
if len(loadBalancer.Servers) == 0 {
server := config.Server{}
server := dynamic.Server{}
server.SetDefaults()
loadBalancer.Servers = []config.Server{server}
loadBalancer.Servers = []dynamic.Server{server}
}
if serverPort != "" {
@ -291,7 +291,7 @@ func (p *Provider) getPortBinding(container dockerData, serverPort string) (*nat
return nil, fmt.Errorf("unable to find the external IP:Port for the container %q", container.Name)
}
func getLBServerPort(loadBalancer *config.LoadBalancerService) string {
func getLBServerPort(loadBalancer *dynamic.LoadBalancerService) string {
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
return loadBalancer.Servers[0].Port
}

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,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/provider"
@ -146,7 +146,7 @@ func (p *Provider) createClient() (client.APIClient, error) {
}
// Provide allows the docker 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 {
pool.GoCtx(func(routineCtx context.Context) {
ctxLog := log.With(routineCtx, log.Str(log.ProviderName, "docker"))
logger := log.FromContext(ctxLog)
@ -186,7 +186,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
}
configuration := p.buildConfiguration(ctxLog, dockerDataList)
configurationChan <- config.Message{
configurationChan <- dynamic.Message{
ProviderName: "docker",
Configuration: configuration,
}
@ -213,7 +213,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
configuration := p.buildConfiguration(ctx, services)
if configuration != nil {
configurationChan <- config.Message{
configurationChan <- dynamic.Message{
ProviderName: "docker",
Configuration: configuration,
}
@ -248,7 +248,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
configuration := p.buildConfiguration(ctx, containers)
if configuration != nil {
message := config.Message{
message := dynamic.Message{
ProviderName: "docker",
Configuration: configuration,
}

View file

@ -13,7 +13,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/Masterminds/sprig"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
"github.com/containous/traefik/pkg/safe"
@ -48,7 +48,7 @@ func (p *Provider) Init() error {
// Provide allows the file 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 {
configuration, err := p.BuildConfiguration()
if err != nil {
@ -78,7 +78,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
// BuildConfiguration loads configuration either from file or a directory specified by 'Filename'/'Directory'
// and returns a 'Configuration' object
func (p *Provider) BuildConfiguration() (*config.Configuration, error) {
func (p *Provider) BuildConfiguration() (*dynamic.Configuration, error) {
ctx := log.With(context.Background(), log.Str(log.ProviderName, providerName))
if len(p.Directory) > 0 {
@ -96,7 +96,7 @@ func (p *Provider) BuildConfiguration() (*config.Configuration, error) {
return nil, errors.New("error using file configuration backend, no filename defined")
}
func (p *Provider) addWatcher(pool *safe.Pool, directory string, configurationChan chan<- config.Message, callback func(chan<- config.Message, fsnotify.Event)) error {
func (p *Provider) addWatcher(pool *safe.Pool, directory string, configurationChan chan<- dynamic.Message, callback func(chan<- dynamic.Message, fsnotify.Event)) error {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return fmt.Errorf("error creating file watcher: %s", err)
@ -139,7 +139,7 @@ func (p *Provider) addWatcher(pool *safe.Pool, directory string, configurationCh
return nil
}
func (p *Provider) watcherCallback(configurationChan chan<- config.Message, event fsnotify.Event) {
func (p *Provider) watcherCallback(configurationChan chan<- dynamic.Message, event fsnotify.Event) {
watchItem := p.TraefikFile
if len(p.Directory) > 0 {
watchItem = p.Directory
@ -163,16 +163,16 @@ func (p *Provider) watcherCallback(configurationChan chan<- config.Message, even
sendConfigToChannel(configurationChan, configuration)
}
func sendConfigToChannel(configurationChan chan<- config.Message, configuration *config.Configuration) {
configurationChan <- config.Message{
func sendConfigToChannel(configurationChan chan<- dynamic.Message, configuration *dynamic.Configuration) {
configurationChan <- dynamic.Message{
ProviderName: "file",
Configuration: configuration,
}
}
func (p *Provider) loadFileConfig(filename string, parseTemplate bool) (*config.Configuration, error) {
func (p *Provider) loadFileConfig(filename string, parseTemplate bool) (*dynamic.Configuration, error) {
var err error
var configuration *config.Configuration
var configuration *dynamic.Configuration
if parseTemplate {
configuration, err = p.CreateConfiguration(filename, template.FuncMap{}, false)
} else {
@ -189,7 +189,7 @@ func (p *Provider) loadFileConfig(filename string, parseTemplate bool) (*config.
return configuration, nil
}
func flattenCertificates(tlsConfig *config.TLSConfiguration) []*tls.CertAndStores {
func flattenCertificates(tlsConfig *dynamic.TLSConfiguration) []*tls.CertAndStores {
var certs []*tls.CertAndStores
for _, cert := range tlsConfig.Certificates {
content, err := cert.Certificate.CertFile.Read()
@ -212,7 +212,7 @@ func flattenCertificates(tlsConfig *config.TLSConfiguration) []*tls.CertAndStore
return certs
}
func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory string, configuration *config.Configuration) (*config.Configuration, error) {
func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory string, configuration *dynamic.Configuration) (*dynamic.Configuration, error) {
logger := log.FromContext(ctx)
fileList, err := ioutil.ReadDir(directory)
@ -221,17 +221,17 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
}
if configuration == nil {
configuration = &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: make(map[string]*config.Router),
Middlewares: make(map[string]*config.Middleware),
Services: make(map[string]*config.Service),
configuration = &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: make(map[string]*dynamic.Router),
Middlewares: make(map[string]*dynamic.Middleware),
Services: make(map[string]*dynamic.Service),
},
TCP: &config.TCPConfiguration{
Routers: make(map[string]*config.TCPRouter),
Services: make(map[string]*config.TCPService),
TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService),
},
TLS: &config.TLSConfiguration{
TLS: &dynamic.TLSConfiguration{
Stores: make(map[string]tls.Store),
Options: make(map[string]tls.Options),
},
@ -256,7 +256,7 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
continue
}
var c *config.Configuration
var c *dynamic.Configuration
c, err = p.loadFileConfig(filepath.Join(directory, item.Name()), true)
if err != nil {
return configuration, err
@ -312,7 +312,7 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
}
if len(configTLSMaps) > 0 {
configuration.TLS = &config.TLSConfiguration{}
configuration.TLS = &dynamic.TLSConfiguration{}
}
for conf := range configTLSMaps {
@ -323,7 +323,7 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
}
// CreateConfiguration creates a provider configuration from content using templating.
func (p *Provider) CreateConfiguration(filename string, funcMap template.FuncMap, templateObjects interface{}) (*config.Configuration, error) {
func (p *Provider) CreateConfiguration(filename string, funcMap template.FuncMap, templateObjects interface{}) (*dynamic.Configuration, error) {
tmplContent, err := readFile(filename)
if err != nil {
return nil, fmt.Errorf("error reading configuration file: %s - %s", filename, err)
@ -360,7 +360,7 @@ func (p *Provider) CreateConfiguration(filename string, funcMap template.FuncMap
}
// DecodeConfiguration Decodes a *types.Configuration from a content.
func (p *Provider) DecodeConfiguration(filename string) (*config.Configuration, error) {
func (p *Provider) DecodeConfiguration(filename string) (*dynamic.Configuration, error) {
content, err := readFile(filename)
if err != nil {
return nil, fmt.Errorf("error reading configuration file: %s - %s", filename, err)
@ -369,18 +369,18 @@ func (p *Provider) DecodeConfiguration(filename string) (*config.Configuration,
return p.decodeConfiguration(filename, content)
}
func (p *Provider) decodeConfiguration(filePath string, content string) (*config.Configuration, error) {
configuration := &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: make(map[string]*config.Router),
Middlewares: make(map[string]*config.Middleware),
Services: make(map[string]*config.Service),
func (p *Provider) decodeConfiguration(filePath string, content string) (*dynamic.Configuration, error) {
configuration := &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: make(map[string]*dynamic.Router),
Middlewares: make(map[string]*dynamic.Middleware),
Services: make(map[string]*dynamic.Service),
},
TCP: &config.TCPConfiguration{
Routers: make(map[string]*config.TCPRouter),
Services: make(map[string]*config.TCPService),
TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService),
},
TLS: &config.TLSConfiguration{
TLS: &dynamic.TLSConfiguration{
Stores: make(map[string]tls.Store),
Options: make(map[string]tls.Options),
},

View file

@ -10,7 +10,7 @@ import (
"testing"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/safe"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -55,7 +55,7 @@ func TestTLSContent(t *testing.T) {
func TestErrorWhenEmptyConfig(t *testing.T) {
provider := &Provider{}
configChan := make(chan config.Message)
configChan := make(chan dynamic.Message)
errorChan := make(chan struct{})
go func() {
err := provider.Provide(configChan, safe.NewPool(context.Background()))
@ -78,7 +78,7 @@ func TestProvideWithoutWatch(t *testing.T) {
t.Run(test.desc+" without watch", func(t *testing.T) {
provider, clean := createProvider(t, test, false)
defer clean()
configChan := make(chan config.Message)
configChan := make(chan dynamic.Message)
provider.DebugLogGeneratedTemplate = true
@ -107,7 +107,7 @@ func TestProvideWithWatch(t *testing.T) {
t.Run(test.desc+" with watch", func(t *testing.T) {
provider, clean := createProvider(t, test, true)
defer clean()
configChan := make(chan config.Message)
configChan := make(chan dynamic.Message)
go func() {
err := provider.Provide(configChan, safe.NewPool(context.Background()))

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/provider/kubernetes/crd/traefik/v1alpha1"
@ -80,7 +80,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, "kubernetescrd"))
logger := log.FromContext(ctxLog)
// Tell glog (used by client-go) to log into STDERR. Otherwise, we risk
@ -124,7 +124,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: "kubernetescrd",
Configuration: conf,
}
@ -150,7 +150,7 @@ func checkStringQuoteValidity(value string) error {
return err
}
func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([]config.TCPServer, error) {
func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([]dynamic.TCPServer, error) {
service, exists, err := client.GetService(namespace, svc.Name)
if err != nil {
return nil, err
@ -172,9 +172,9 @@ func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([
return nil, errors.New("service port not found")
}
var servers []config.TCPServer
var servers []dynamic.TCPServer
if service.Spec.Type == corev1.ServiceTypeExternalName {
servers = append(servers, config.TCPServer{
servers = append(servers, dynamic.TCPServer{
Address: fmt.Sprintf("%s:%d", service.Spec.ExternalName, portSpec.Port),
})
} else {
@ -205,7 +205,7 @@ func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([
}
for _, addr := range subset.Addresses {
servers = append(servers, config.TCPServer{
servers = append(servers, dynamic.TCPServer{
Address: fmt.Sprintf("%s:%d", addr.IP, port),
})
}
@ -215,7 +215,7 @@ func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([
return servers, nil
}
func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]config.Server, error) {
func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]dynamic.Server, error) {
strategy := svc.Strategy
if strategy == "" {
strategy = "RoundRobin"
@ -245,9 +245,9 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
return nil, errors.New("service port not found")
}
var servers []config.Server
var servers []dynamic.Server
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 {
@ -290,7 +290,7 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
}
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),
})
}
@ -347,11 +347,11 @@ func buildTLSOptions(ctx context.Context, client Client) map[string]tls.Options
return tlsOptions
}
func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *config.HTTPConfiguration {
conf := &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.HTTPConfiguration {
conf := &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
}
for _, ingressRoute := range client.GetIngressRoutes() {
@ -388,7 +388,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
continue
}
var allServers []config.Server
var allServers []dynamic.Server
for _, service := range route.Services {
servers, err := loadServers(client, ingressRoute.Namespace, service)
if err != nil {
@ -429,7 +429,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
serviceName := makeID(ingressRoute.Namespace, key)
conf.Routers[serviceName] = &config.Router{
conf.Routers[serviceName] = &dynamic.Router{
Middlewares: mds,
Priority: route.Priority,
EntryPoints: ingressRoute.Spec.EntryPoints,
@ -438,7 +438,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
}
if ingressRoute.Spec.TLS != nil {
tlsConf := &config.RouterTLSConfig{}
tlsConf := &dynamic.RouterTLSConfig{}
if ingressRoute.Spec.TLS.Options != nil && len(ingressRoute.Spec.TLS.Options.Name) > 0 {
tlsOptionsName := ingressRoute.Spec.TLS.Options.Name
// Is a Kubernetes CRD reference, (i.e. not a cross-provider reference)
@ -459,8 +459,8 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
conf.Routers[serviceName].TLS = tlsConf
}
conf.Services[serviceName] = &config.Service{
LoadBalancer: &config.LoadBalancerService{
conf.Services[serviceName] = &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: allServers,
// TODO: support other strategies.
PassHostHeader: true,
@ -472,10 +472,10 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
return conf
}
func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *config.TCPConfiguration {
conf := &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.TCPConfiguration {
conf := &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
}
for _, ingressRouteTCP := range client.GetIngressRouteTCPs() {
@ -508,7 +508,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
continue
}
var allServers []config.TCPServer
var allServers []dynamic.TCPServer
for _, service := range route.Services {
servers, err := loadTCPServers(client, ingressRouteTCP.Namespace, service)
if err != nil {
@ -529,14 +529,14 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
}
serviceName := makeID(ingressRouteTCP.Namespace, key)
conf.Routers[serviceName] = &config.TCPRouter{
conf.Routers[serviceName] = &dynamic.TCPRouter{
EntryPoints: ingressRouteTCP.Spec.EntryPoints,
Rule: route.Match,
Service: serviceName,
}
if ingressRouteTCP.Spec.TLS != nil {
conf.Routers[serviceName].TLS = &config.RouterTCPTLSConfig{
conf.Routers[serviceName].TLS = &dynamic.RouterTCPTLSConfig{
Passthrough: ingressRouteTCP.Spec.TLS.Passthrough,
}
@ -560,8 +560,8 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
}
}
conf.Services[serviceName] = &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
conf.Services[serviceName] = &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: allServers,
},
}
@ -571,12 +571,12 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
return conf
}
func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client) *config.Configuration {
func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client) *dynamic.Configuration {
tlsConfigs := make(map[string]*tls.CertAndStores)
conf := &config.Configuration{
conf := &dynamic.Configuration{
HTTP: p.loadIngressRouteConfiguration(ctx, client, tlsConfigs),
TCP: p.loadIngressRouteTCPConfiguration(ctx, client, tlsConfigs),
TLS: &config.TLSConfiguration{
TLS: &dynamic.TLSConfiguration{
Certificates: getTLSConfig(tlsConfigs),
Options: buildTLSOptions(ctx, client),
},

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
package v1alpha1
import (
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@ -13,7 +13,7 @@ type Middleware struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`
Spec config.Middleware `json:"spec"`
Spec dynamic.Middleware `json:"spec"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

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{},
},
},
},

View file

@ -9,7 +9,7 @@ import (
"strconv"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/label"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
@ -17,8 +17,8 @@ import (
"github.com/gambol99/go-marathon"
)
func (p *Provider) buildConfiguration(ctx context.Context, applications *marathon.Applications) *config.Configuration {
configurations := make(map[string]*config.Configuration)
func (p *Provider) buildConfiguration(ctx context.Context, applications *marathon.Applications) *dynamic.Configuration {
configurations := make(map[string]*dynamic.Configuration)
for _, app := range applications.Apps {
ctxApp := log.With(ctx, log.Str("applicationID", app.ID))
@ -92,23 +92,23 @@ func getServiceName(app marathon.Application) string {
return strings.Replace(strings.TrimPrefix(app.ID, "/"), "/", "_", -1)
}
func (p *Provider) buildServiceConfiguration(ctx context.Context, app marathon.Application, extraConf configuration, conf *config.HTTPConfiguration) error {
func (p *Provider) buildServiceConfiguration(ctx context.Context, app marathon.Application, extraConf configuration, conf *dynamic.HTTPConfiguration) error {
appName := getServiceName(app)
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
if len(conf.Services) == 0 {
conf.Services = make(map[string]*config.Service)
lb := &config.LoadBalancerService{}
conf.Services = make(map[string]*dynamic.Service)
lb := &dynamic.LoadBalancerService{}
lb.SetDefaults()
conf.Services[appName] = &config.Service{
conf.Services[appName] = &dynamic.Service{
LoadBalancer: lb,
}
}
for serviceName, service := range conf.Services {
var servers []config.Server
var servers []dynamic.Server
defaultServer := config.Server{}
defaultServer := dynamic.Server{}
defaultServer.SetDefaults()
if len(service.LoadBalancer.Servers) > 0 {
@ -134,22 +134,22 @@ func (p *Provider) buildServiceConfiguration(ctx context.Context, app marathon.A
return nil
}
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, app marathon.Application, extraConf configuration, conf *config.TCPConfiguration) error {
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, app marathon.Application, extraConf configuration, conf *dynamic.TCPConfiguration) error {
appName := getServiceName(app)
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
if len(conf.Services) == 0 {
conf.Services = make(map[string]*config.TCPService)
lb := &config.TCPLoadBalancerService{}
conf.Services[appName] = &config.TCPService{
conf.Services = make(map[string]*dynamic.TCPService)
lb := &dynamic.TCPLoadBalancerService{}
conf.Services[appName] = &dynamic.TCPService{
LoadBalancer: lb,
}
}
for serviceName, service := range conf.Services {
var servers []config.TCPServer
var servers []dynamic.TCPServer
defaultServer := config.TCPServer{}
defaultServer := dynamic.TCPServer{}
if len(service.LoadBalancer.Servers) > 0 {
defaultServer = service.LoadBalancer.Servers[0]
@ -210,36 +210,36 @@ func (p *Provider) taskFilter(ctx context.Context, task marathon.Task, applicati
return true
}
func (p *Provider) getTCPServer(app marathon.Application, task marathon.Task, extraConf configuration, defaultServer config.TCPServer) (config.TCPServer, error) {
func (p *Provider) getTCPServer(app marathon.Application, task marathon.Task, extraConf configuration, defaultServer dynamic.TCPServer) (dynamic.TCPServer, error) {
host, err := p.getServerHost(task, app, extraConf)
if len(host) == 0 {
return config.TCPServer{}, err
return dynamic.TCPServer{}, err
}
port, err := getPort(task, app, defaultServer.Port)
if err != nil {
return config.TCPServer{}, err
return dynamic.TCPServer{}, err
}
server := config.TCPServer{
server := dynamic.TCPServer{
Address: net.JoinHostPort(host, port),
}
return server, nil
}
func (p *Provider) getServer(app marathon.Application, task marathon.Task, extraConf configuration, defaultServer config.Server) (config.Server, error) {
func (p *Provider) getServer(app marathon.Application, task marathon.Task, extraConf configuration, defaultServer dynamic.Server) (dynamic.Server, error) {
host, err := p.getServerHost(task, app, extraConf)
if len(host) == 0 {
return config.Server{}, err
return dynamic.Server{}, err
}
port, err := getPort(task, app, defaultServer.Port)
if err != nil {
return config.Server{}, err
return dynamic.Server{}, err
}
server := config.Server{
server := dynamic.Server{
URL: fmt.Sprintf("%s://%s", defaultServer.Scheme, net.JoinHostPort(host, port)),
}

File diff suppressed because it is too large Load diff

View file

@ -10,7 +10,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/provider"
@ -106,7 +106,7 @@ func (p *Provider) Init() error {
// Provide allows the marathon 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 {
ctx := log.With(context.Background(), log.Str(log.ProviderName, "marathon"))
logger := log.FromContext(ctx)
@ -171,7 +171,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
conf := p.getConfigurations(ctx)
if conf != nil {
configurationChan <- config.Message{
configurationChan <- dynamic.Message{
ProviderName: "marathon",
Configuration: conf,
}
@ -182,7 +182,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
}
configuration := p.getConfigurations(ctx)
configurationChan <- config.Message{
configurationChan <- dynamic.Message{
ProviderName: "marathon",
Configuration: configuration,
}
@ -199,7 +199,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
return nil
}
func (p *Provider) getConfigurations(ctx context.Context) *config.Configuration {
func (p *Provider) getConfigurations(ctx context.Context) *dynamic.Configuration {
applications, err := p.getApplications()
if err != nil {
log.FromContext(ctx).Errorf("Failed to retrieve Marathon applications: %v", err)

View file

@ -1,7 +1,7 @@
package provider
import (
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/safe"
)
@ -9,6 +9,6 @@ import (
type Provider interface {
// Provide allows the provider to provide configurations to traefik
// using the given configuration channel.
Provide(configurationChan chan<- config.Message, pool *safe.Pool) error
Provide(configurationChan chan<- dynamic.Message, pool *safe.Pool) error
Init() error
}

View file

@ -7,15 +7,15 @@ import (
"net"
"strings"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/label"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
"github.com/containous/traefik/pkg/provider/constraints"
)
func (p *Provider) buildConfiguration(ctx context.Context, services []rancherData) *config.Configuration {
configurations := make(map[string]*config.Configuration)
func (p *Provider) buildConfiguration(ctx context.Context, services []rancherData) *dynamic.Configuration {
configurations := make(map[string]*dynamic.Configuration)
for _, service := range services {
ctxService := log.With(ctx, log.Str("service", service.Name))
@ -69,13 +69,13 @@ func (p *Provider) buildConfiguration(ctx context.Context, services []rancherDat
return provider.Merge(ctx, configurations)
}
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, service rancherData, configuration *config.TCPConfiguration) error {
func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, service rancherData, configuration *dynamic.TCPConfiguration) error {
serviceName := service.Name
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*config.TCPService)
lb := &config.TCPLoadBalancerService{}
configuration.Services[serviceName] = &config.TCPService{
configuration.Services = make(map[string]*dynamic.TCPService)
lb := &dynamic.TCPLoadBalancerService{}
configuration.Services[serviceName] = &dynamic.TCPService{
LoadBalancer: lb,
}
}
@ -90,15 +90,15 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, service ran
return nil
}
func (p *Provider) buildServiceConfiguration(ctx context.Context, service rancherData, configuration *config.HTTPConfiguration) error {
func (p *Provider) buildServiceConfiguration(ctx context.Context, service rancherData, configuration *dynamic.HTTPConfiguration) error {
serviceName := service.Name
if len(configuration.Services) == 0 {
configuration.Services = make(map[string]*config.Service)
lb := &config.LoadBalancerService{}
configuration.Services = make(map[string]*dynamic.Service)
lb := &dynamic.LoadBalancerService{}
lb.SetDefaults()
configuration.Services[serviceName] = &config.Service{
configuration.Services[serviceName] = &dynamic.Service{
LoadBalancer: lb,
}
}
@ -145,7 +145,7 @@ func (p *Provider) keepService(ctx context.Context, service rancherData) bool {
return true
}
func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBalancer *config.TCPLoadBalancerService) error {
func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBalancer *dynamic.TCPLoadBalancerService) error {
log.FromContext(ctx).Debugf("Trying to add servers for service %s \n", service.Name)
serverPort := ""
@ -157,9 +157,9 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
port := getServicePort(service)
if len(loadBalancer.Servers) == 0 {
server := config.TCPServer{}
server := dynamic.TCPServer{}
loadBalancer.Servers = []config.TCPServer{server}
loadBalancer.Servers = []dynamic.TCPServer{server}
}
if serverPort != "" {
@ -171,9 +171,9 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
return errors.New("port is missing")
}
var servers []config.TCPServer
var servers []dynamic.TCPServer
for _, containerIP := range service.Containers {
servers = append(servers, config.TCPServer{
servers = append(servers, dynamic.TCPServer{
Address: net.JoinHostPort(containerIP, port),
})
}
@ -183,17 +183,17 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
}
func (p *Provider) addServers(ctx context.Context, service rancherData, loadBalancer *config.LoadBalancerService) error {
func (p *Provider) addServers(ctx context.Context, service rancherData, loadBalancer *dynamic.LoadBalancerService) error {
log.FromContext(ctx).Debugf("Trying to add servers for service %s \n", service.Name)
serverPort := getLBServerPort(loadBalancer)
port := getServicePort(service)
if len(loadBalancer.Servers) == 0 {
server := config.Server{}
server := dynamic.Server{}
server.SetDefaults()
loadBalancer.Servers = []config.Server{server}
loadBalancer.Servers = []dynamic.Server{server}
}
if serverPort != "" {
@ -205,9 +205,9 @@ func (p *Provider) addServers(ctx context.Context, service rancherData, loadBala
return errors.New("port is missing")
}
var servers []config.Server
var servers []dynamic.Server
for _, containerIP := range service.Containers {
servers = append(servers, config.Server{
servers = append(servers, dynamic.Server{
URL: fmt.Sprintf("%s://%s", loadBalancer.Servers[0].Scheme, net.JoinHostPort(containerIP, port)),
})
}
@ -216,7 +216,7 @@ func (p *Provider) addServers(ctx context.Context, service rancherData, loadBala
return nil
}
func getLBServerPort(loadBalancer *config.LoadBalancerService) string {
func getLBServerPort(loadBalancer *dynamic.LoadBalancerService) string {
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
return loadBalancer.Servers[0].Port
}

View file

@ -4,7 +4,7 @@ import (
"context"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@ -14,7 +14,7 @@ func Test_buildConfiguration(t *testing.T) {
desc string
containers []rancherData
constraints string
expected *config.Configuration
expected *dynamic.Configuration
}{
{
desc: "one service no label",
@ -28,23 +28,23 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -76,13 +76,13 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
@ -92,11 +92,11 @@ func Test_buildConfiguration(t *testing.T) {
Rule: "Host(`Test2.traefik.wtf`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -105,8 +105,8 @@ func Test_buildConfiguration(t *testing.T) {
},
},
"Test2": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.2:80",
},
@ -138,13 +138,13 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test1": {
Service: "Test1",
Rule: "Host(`Test1.traefik.wtf`)",
@ -154,11 +154,11 @@ func Test_buildConfiguration(t *testing.T) {
Rule: "Host(`Test2.traefik.wtf`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -170,8 +170,8 @@ func Test_buildConfiguration(t *testing.T) {
},
},
"Test2": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://128.0.0.1:80",
},
@ -199,23 +199,23 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Router1": {
Service: "Service1",
Rule: "Host(`foo.com`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Service1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -238,15 +238,15 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
@ -261,15 +261,15 @@ func Test_buildConfiguration(t *testing.T) {
State: "upgradefailed",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
@ -287,23 +287,23 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Router1": {
Service: "Test",
Rule: "Host(`foo.com`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -330,15 +330,15 @@ func Test_buildConfiguration(t *testing.T) {
},
},
constraints: `Label("traefik.tags", "bar")`,
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
@ -357,23 +357,23 @@ func Test_buildConfiguration(t *testing.T) {
},
},
constraints: `Label("traefik.tags", "foo")`,
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -400,22 +400,22 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
Middlewares: []string{"Middleware1"},
},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"Middleware1": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
@ -423,10 +423,10 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"Test": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -452,23 +452,23 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{},
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Test",
Rule: "Host(`Test.traefik.wtf`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Test": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -495,19 +495,19 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"foo": {
Service: "Test",
Rule: "HostSNI(`foo.bar`)",
TLS: &config.RouterTCPTLSConfig{},
TLS: &dynamic.RouterTCPTLSConfig{},
},
},
Services: map[string]*config.TCPService{
Services: map[string]*dynamic.TCPService{
"Test": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
@ -516,10 +516,10 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
@ -537,13 +537,13 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{
"Test": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
@ -552,10 +552,10 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
@ -574,18 +574,18 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"foo": {
Service: "foo",
Rule: "HostSNI(`foo.bar`)",
},
},
Services: map[string]*config.TCPService{
Services: map[string]*dynamic.TCPService{
"foo": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:8080",
},
@ -594,10 +594,10 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},
@ -618,19 +618,19 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"foo": {
Service: "foo",
Rule: "HostSNI(`foo.bar`)",
TLS: &config.RouterTCPTLSConfig{},
TLS: &dynamic.RouterTCPTLSConfig{},
},
},
Services: map[string]*config.TCPService{
Services: map[string]*dynamic.TCPService{
"foo": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:8080",
},
@ -642,18 +642,18 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"Test": {
Service: "Service1",
Rule: "Host(`Test.traefik.wtf`)",
},
},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{
"Service1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:80",
},
@ -682,13 +682,13 @@ func Test_buildConfiguration(t *testing.T) {
State: "",
},
},
expected: &config.Configuration{
TCP: &config.TCPConfiguration{
Routers: map[string]*config.TCPRouter{},
Services: map[string]*config.TCPService{
expected: &dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{},
Services: map[string]*dynamic.TCPService{
"foo": {
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:8080",
},
@ -697,10 +697,10 @@ func Test_buildConfiguration(t *testing.T) {
},
},
},
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{},
Middlewares: map[string]*config.Middleware{},
Services: map[string]*config.Service{},
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{},
Middlewares: map[string]*dynamic.Middleware{},
Services: map[string]*dynamic.Service{},
},
},
},

View file

@ -7,7 +7,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/provider"
@ -94,7 +94,7 @@ func (p *Provider) createClient(ctx context.Context) (rancher.Client, error) {
}
// Provide allows the rancher 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 {
pool.GoCtx(func(routineCtx context.Context) {
ctxLog := log.With(routineCtx, log.Str(log.ProviderName, "rancher"))
logger := log.FromContext(ctxLog)
@ -118,7 +118,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
logger.Printf("Received Rancher data %+v", rancherData)
configuration := p.buildConfiguration(ctxLog, rancherData)
configurationChan <- config.Message{
configurationChan <- dynamic.Message{
ProviderName: "rancher",
Configuration: configuration,
}

View file

@ -7,7 +7,7 @@ import (
"net/http"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/provider"
"github.com/containous/traefik/pkg/safe"
@ -18,7 +18,7 @@ var _ provider.Provider = (*Provider)(nil)
// Provider is a provider.Provider implementation that provides a Rest API.
type Provider struct {
configurationChan chan<- config.Message
configurationChan chan<- dynamic.Message
EntryPoint string `description:"EntryPoint." json:"entryPoint,omitempty" toml:"entryPoint,omitempty" yaml:"entryPoint,omitempty" export:"true"`
}
@ -48,7 +48,7 @@ func (p *Provider) Append(systemRouter *mux.Router) {
return
}
configuration := new(config.HTTPConfiguration)
configuration := new(dynamic.HTTPConfiguration)
body, _ := ioutil.ReadAll(request.Body)
if err := json.Unmarshal(body, configuration); err != nil {
@ -57,7 +57,7 @@ func (p *Provider) Append(systemRouter *mux.Router) {
return
}
p.configurationChan <- config.Message{ProviderName: "rest", Configuration: &config.Configuration{
p.configurationChan <- dynamic.Message{ProviderName: "rest", Configuration: &dynamic.Configuration{
HTTP: configuration,
}}
if err := templatesRenderer.JSON(response, http.StatusOK, configuration); err != nil {
@ -68,7 +68,7 @@ func (p *Provider) Append(systemRouter *mux.Router) {
// Provide allows the 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 {
p.configurationChan = configurationChan
return nil
}

View file

@ -3,12 +3,12 @@ package responsemodifiers
import (
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/headers"
"github.com/unrolled/secure"
)
func buildHeaders(hdrs *config.Headers) func(*http.Response) error {
func buildHeaders(hdrs *dynamic.Headers) func(*http.Response) error {
opt := secure.Options{
BrowserXssFilter: hdrs.BrowserXSSFilter,
ContentTypeNosniff: hdrs.ContentTypeNosniff,

View file

@ -4,17 +4,17 @@ import (
"context"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
)
// NewBuilder creates a builder.
func NewBuilder(configs map[string]*config.MiddlewareInfo) *Builder {
func NewBuilder(configs map[string]*dynamic.MiddlewareInfo) *Builder {
return &Builder{configs: configs}
}
// Builder holds builder configuration.
type Builder struct {
configs map[string]*config.MiddlewareInfo
configs map[string]*dynamic.MiddlewareInfo
}
// Build Builds the response modifier.

View file

@ -6,13 +6,13 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/headers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func stubResponse(_ map[string]*config.Middleware) *http.Response {
func stubResponse(_ map[string]*dynamic.Middleware) *http.Response {
return &http.Response{Header: make(http.Header)}
}
@ -21,24 +21,24 @@ func TestBuilderBuild(t *testing.T) {
desc string
middlewares []string
// buildResponse is needed because secure use a private context key
buildResponse func(map[string]*config.Middleware) *http.Response
conf map[string]*config.Middleware
buildResponse func(map[string]*dynamic.Middleware) *http.Response
conf map[string]*dynamic.Middleware
assertResponse func(*testing.T, *http.Response)
}{
{
desc: "no configuration",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{},
conf: map[string]*dynamic.Middleware{},
assertResponse: func(t *testing.T, resp *http.Response) {},
},
{
desc: "one modifier",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
@ -52,7 +52,7 @@ func TestBuilderBuild(t *testing.T) {
{
desc: "secure: one modifier",
middlewares: []string{"foo", "bar"},
buildResponse: func(middlewares map[string]*config.Middleware) *http.Response {
buildResponse: func(middlewares map[string]*dynamic.Middleware) *http.Response {
ctx := context.Background()
var request *http.Request
@ -69,14 +69,14 @@ func TestBuilderBuild(t *testing.T) {
return &http.Response{Header: make(http.Header), Request: request}
},
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
ReferrerPolicy: "no-referrer",
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
},
},
@ -91,14 +91,14 @@ func TestBuilderBuild(t *testing.T) {
desc: "two modifiers",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
},
},
@ -114,14 +114,14 @@ func TestBuilderBuild(t *testing.T) {
desc: "modifier order",
middlewares: []string{"foo", "bar"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
},
},
@ -136,19 +136,19 @@ func TestBuilderBuild(t *testing.T) {
desc: "chain",
middlewares: []string{"chain"},
buildResponse: stubResponse,
conf: map[string]*config.Middleware{
conf: map[string]*dynamic.Middleware{
"foo": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
},
},
"bar": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
},
},
"chain": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"foo", "bar"},
},
},
@ -166,8 +166,8 @@ func TestBuilderBuild(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Middlewares: test.conf,
},
})

View file

@ -1,24 +1,24 @@
package server
import (
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/server/internal"
"github.com/containous/traefik/pkg/tls"
)
func mergeConfiguration(configurations config.Configurations) config.Configuration {
conf := config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: make(map[string]*config.Router),
Middlewares: make(map[string]*config.Middleware),
Services: make(map[string]*config.Service),
func mergeConfiguration(configurations dynamic.Configurations) dynamic.Configuration {
conf := dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: make(map[string]*dynamic.Router),
Middlewares: make(map[string]*dynamic.Middleware),
Services: make(map[string]*dynamic.Service),
},
TCP: &config.TCPConfiguration{
Routers: make(map[string]*config.TCPRouter),
Services: make(map[string]*config.TCPService),
TCP: &dynamic.TCPConfiguration{
Routers: make(map[string]*dynamic.TCPRouter),
Services: make(map[string]*dynamic.TCPService),
},
TLS: &config.TLSConfiguration{
TLS: &dynamic.TLSConfiguration{
Stores: make(map[string]tls.Store),
Options: make(map[string]tls.Options),
},

View file

@ -3,7 +3,7 @@ package server
import (
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/tls"
"github.com/stretchr/testify/assert"
)
@ -11,87 +11,87 @@ import (
func TestAggregator(t *testing.T) {
testCases := []struct {
desc string
given config.Configurations
expected *config.HTTPConfiguration
given dynamic.Configurations
expected *dynamic.HTTPConfiguration
}{
{
desc: "Nil returns an empty configuration",
given: nil,
expected: &config.HTTPConfiguration{
Routers: make(map[string]*config.Router),
Middlewares: make(map[string]*config.Middleware),
Services: make(map[string]*config.Service),
expected: &dynamic.HTTPConfiguration{
Routers: make(map[string]*dynamic.Router),
Middlewares: make(map[string]*dynamic.Middleware),
Services: make(map[string]*dynamic.Service),
},
},
{
desc: "Returns fully qualified elements from a mono-provider configuration map",
given: config.Configurations{
"provider-1": &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router-1": {},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"middleware-1": {},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"service-1": {},
},
},
},
},
expected: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
expected: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router-1@provider-1": {},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"middleware-1@provider-1": {},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"service-1@provider-1": {},
},
},
},
{
desc: "Returns fully qualified elements from a multi-provider configuration map",
given: config.Configurations{
"provider-1": &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router-1": {},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"middleware-1": {},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"service-1": {},
},
},
},
"provider-2": &config.Configuration{
HTTP: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
"provider-2": &dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router-1": {},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"middleware-1": {},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"service-1": {},
},
},
},
},
expected: &config.HTTPConfiguration{
Routers: map[string]*config.Router{
expected: &dynamic.HTTPConfiguration{
Routers: map[string]*dynamic.Router{
"router-1@provider-1": {},
"router-1@provider-2": {},
},
Middlewares: map[string]*config.Middleware{
Middlewares: map[string]*dynamic.Middleware{
"middleware-1@provider-1": {},
"middleware-1@provider-2": {},
},
Services: map[string]*config.Service{
Services: map[string]*dynamic.Service{
"service-1@provider-1": {},
"service-1@provider-2": {},
},
@ -113,7 +113,7 @@ func TestAggregator(t *testing.T) {
func TestAggregator_tlsoptions(t *testing.T) {
testCases := []struct {
desc string
given config.Configurations
given dynamic.Configurations
expected map[string]tls.Options
}{
{
@ -125,9 +125,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
{
desc: "Returns fully qualified elements from a mono-provider configuration map",
given: config.Configurations{
"provider-1": &config.Configuration{
TLS: &config.TLSConfiguration{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS12",
@ -145,9 +145,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
{
desc: "Returns fully qualified elements from a multi-provider configuration map",
given: config.Configurations{
"provider-1": &config.Configuration{
TLS: &config.TLSConfiguration{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS13",
@ -155,8 +155,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
},
},
"provider-2": &config.Configuration{
TLS: &config.TLSConfiguration{
"provider-2": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS12",
@ -177,9 +177,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
{
desc: "Create a valid default tls option when appears only in one provider",
given: config.Configurations{
"provider-1": &config.Configuration{
TLS: &config.TLSConfiguration{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS13",
@ -190,8 +190,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
},
},
"provider-2": &config.Configuration{
TLS: &config.TLSConfiguration{
"provider-2": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS12",
@ -214,9 +214,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
{
desc: "No default tls option if it is defined in multiple providers",
given: config.Configurations{
"provider-1": &config.Configuration{
TLS: &config.TLSConfiguration{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS12",
@ -227,8 +227,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
},
},
"provider-2": &config.Configuration{
TLS: &config.TLSConfiguration{
"provider-2": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS13",
@ -251,9 +251,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
{
desc: "Create a default TLS Options configuration if none was provided",
given: config.Configurations{
"provider-1": &config.Configuration{
TLS: &config.TLSConfiguration{
given: dynamic.Configurations{
"provider-1": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS12",
@ -261,8 +261,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
},
},
},
"provider-2": &config.Configuration{
TLS: &config.TLSConfiguration{
"provider-2": &dynamic.Configuration{
TLS: &dynamic.TLSConfiguration{
Options: map[string]tls.Options{
"foo": {
MinVersion: "VersionTLS13",

View file

@ -8,7 +8,7 @@ import (
"strings"
"github.com/containous/alice"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/middlewares/addprefix"
"github.com/containous/traefik/pkg/middlewares/auth"
"github.com/containous/traefik/pkg/middlewares/buffering"
@ -39,7 +39,7 @@ const (
// Builder the middleware builder
type Builder struct {
configs map[string]*config.MiddlewareInfo
configs map[string]*dynamic.MiddlewareInfo
serviceBuilder serviceBuilder
}
@ -48,7 +48,7 @@ type serviceBuilder interface {
}
// NewBuilder creates a new Builder
func NewBuilder(configs map[string]*config.MiddlewareInfo, serviceBuilder serviceBuilder) *Builder {
func NewBuilder(configs map[string]*dynamic.MiddlewareInfo, serviceBuilder serviceBuilder) *Builder {
return &Builder{configs: configs, serviceBuilder: serviceBuilder}
}

View file

@ -7,14 +7,14 @@ import (
"net/http/httptest"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/server/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBuilder_BuildChainNilConfig(t *testing.T) {
testConfig := map[string]*config.MiddlewareInfo{
testConfig := map[string]*dynamic.MiddlewareInfo{
"empty": {},
}
middlewaresBuilder := NewBuilder(testConfig, nil)
@ -25,7 +25,7 @@ func TestBuilder_BuildChainNilConfig(t *testing.T) {
}
func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
testConfig := map[string]*config.MiddlewareInfo{
testConfig := map[string]*dynamic.MiddlewareInfo{
"foobar": {},
}
middlewaresBuilder := NewBuilder(testConfig, nil)
@ -39,7 +39,7 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
testCases := []struct {
desc string
buildChain []string
configuration map[string]*config.Middleware
configuration map[string]*dynamic.Middleware
expected map[string]string
contextProvider string
expectedError error
@ -47,9 +47,9 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Simple middleware",
buildChain: []string{"middleware-1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"middleware-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
},
},
@ -59,14 +59,14 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Middleware that references a chain",
buildChain: []string{"middleware-chain-1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"middleware-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
},
},
"middleware-chain-1": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"middleware-1"},
},
},
@ -76,9 +76,9 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Should suffix the middlewareName with the provider in the context",
buildChain: []string{"middleware-1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"middleware-1@provider-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-1@provider-1": "value-middleware-1"},
},
},
@ -89,9 +89,9 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Should not suffix a qualified middlewareName with the provider in the context",
buildChain: []string{"middleware-1@provider-1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"middleware-1@provider-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-1@provider-1": "value-middleware-1"},
},
},
@ -102,14 +102,14 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Should be context aware if a chain references another middleware",
buildChain: []string{"middleware-chain-1@provider-1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"middleware-1@provider-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
},
},
"middleware-chain-1@provider-1": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"middleware-1"},
},
},
@ -119,29 +119,29 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Should handle nested chains with different context",
buildChain: []string{"middleware-chain-1@provider-1", "middleware-chain-1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"middleware-1@provider-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
},
},
"middleware-2@provider-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"middleware-2": "value-middleware-2"},
},
},
"middleware-chain-1@provider-1": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"middleware-1"},
},
},
"middleware-chain-2@provider-1": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"middleware-2"},
},
},
"middleware-chain-1@provider-2": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"middleware-2@provider-1", "middleware-chain-2@provider-1"},
},
},
@ -152,22 +152,22 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Detects recursion in Middleware chain",
buildChain: []string{"m1"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"ok": {
Retry: &config.Retry{},
Retry: &dynamic.Retry{},
},
"m1": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m2"},
},
},
"m2": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"ok", "m3"},
},
},
"m3": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m1"},
},
},
@ -177,22 +177,22 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Detects recursion in Middleware chain",
buildChain: []string{"m1@provider"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"ok@provider2": {
Retry: &config.Retry{},
Retry: &dynamic.Retry{},
},
"m1@provider": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m2@provider2"},
},
},
"m2@provider2": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"ok", "m3@provider"},
},
},
"m3@provider": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m1"},
},
},
@ -201,12 +201,12 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
},
{
buildChain: []string{"ok", "m0"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"ok": {
Retry: &config.Retry{},
Retry: &dynamic.Retry{},
},
"m0": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m0"},
},
},
@ -216,24 +216,24 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "Detects MiddlewareChain that references a Chain that references a Chain with a missing middleware",
buildChain: []string{"m0"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"m0": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m1"},
},
},
"m1": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m2"},
},
},
"m2": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m3"},
},
},
"m3": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m2"},
},
},
@ -243,9 +243,9 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
{
desc: "--",
buildChain: []string{"m0"},
configuration: map[string]*config.Middleware{
configuration: map[string]*dynamic.Middleware{
"m0": {
Chain: &config.Chain{
Chain: &dynamic.Chain{
Middlewares: []string{"m0"},
},
},
@ -264,8 +264,8 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
ctx = internal.AddProviderInContext(ctx, "foobar@"+test.contextProvider)
}
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Middlewares: test.configuration,
},
})
@ -292,31 +292,31 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
}
func TestBuilder_buildConstructor(t *testing.T) {
testConfig := map[string]*config.Middleware{
testConfig := map[string]*dynamic.Middleware{
"cb-empty": {
CircuitBreaker: &config.CircuitBreaker{
CircuitBreaker: &dynamic.CircuitBreaker{
Expression: "",
},
},
"cb-foo": {
CircuitBreaker: &config.CircuitBreaker{
CircuitBreaker: &dynamic.CircuitBreaker{
Expression: "NetworkErrorRatio() > 0.5",
},
},
"ap-empty": {
AddPrefix: &config.AddPrefix{
AddPrefix: &dynamic.AddPrefix{
Prefix: "",
},
},
"ap-foo": {
AddPrefix: &config.AddPrefix{
AddPrefix: &dynamic.AddPrefix{
Prefix: "foo/",
},
},
}
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Middlewares: testConfig,
},
})

View file

@ -6,7 +6,7 @@ import (
"github.com/containous/alice"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/api"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/metrics"
@ -20,7 +20,7 @@ type chainBuilder interface {
// NewRouteAppenderAggregator Creates a new RouteAppenderAggregator
func NewRouteAppenderAggregator(ctx context.Context, chainBuilder chainBuilder, conf static.Configuration,
entryPointName string, runtimeConfiguration *config.RuntimeConfiguration) *RouteAppenderAggregator {
entryPointName string, runtimeConfiguration *dynamic.RuntimeConfiguration) *RouteAppenderAggregator {
aggregator := &RouteAppenderAggregator{}
if conf.Providers != nil && conf.Providers.Rest != nil {

View file

@ -3,7 +3,7 @@ package router
import (
"context"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/provider/acme"
"github.com/containous/traefik/pkg/server/middleware"
@ -27,7 +27,7 @@ type RouteAppenderFactory struct {
}
// NewAppender Creates a new RouteAppender
func (r *RouteAppenderFactory) NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *config.RuntimeConfiguration) types.RouteAppender {
func (r *RouteAppenderFactory) NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *dynamic.RuntimeConfiguration) types.RouteAppender {
aggregator := NewRouteAppenderAggregator(ctx, middlewaresBuilder, r.staticConfiguration, r.entryPointName, runtimeConfiguration)
if r.acmeProvider != nil && r.acmeProvider.HTTPChallenge != nil && r.acmeProvider.HTTPChallenge.EntryPoint == r.entryPointName {

View file

@ -5,7 +5,7 @@ import (
"net/http"
"github.com/containous/alice"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/middlewares/accesslog"
"github.com/containous/traefik/pkg/middlewares/recovery"
@ -22,7 +22,7 @@ const (
)
// NewManager Creates a new Manager
func NewManager(conf *config.RuntimeConfiguration,
func NewManager(conf *dynamic.RuntimeConfiguration,
serviceManager *service.Manager,
middlewaresBuilder *middleware.Builder,
modifierBuilder *responsemodifiers.Builder,
@ -42,15 +42,15 @@ type Manager struct {
serviceManager *service.Manager
middlewaresBuilder *middleware.Builder
modifierBuilder *responsemodifiers.Builder
conf *config.RuntimeConfiguration
conf *dynamic.RuntimeConfiguration
}
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*config.RouterInfo {
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*dynamic.RouterInfo {
if m.conf != nil {
return m.conf.GetRoutersByEntrypoints(ctx, entryPoints, tls)
}
return make(map[string]map[string]*config.RouterInfo)
return make(map[string]map[string]*dynamic.RouterInfo)
}
// BuildHandlers Builds handler for all entry points
@ -83,7 +83,7 @@ func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string, t
return entryPointHandlers
}
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*config.RouterInfo) (http.Handler, error) {
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*dynamic.RouterInfo) (http.Handler, error) {
router, err := rules.NewRouter()
if err != nil {
return nil, err
@ -118,7 +118,7 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
return chain.Then(router)
}
func (m *Manager) buildRouterHandler(ctx context.Context, routerName string, routerConfig *config.RouterInfo) (http.Handler, error) {
func (m *Manager) buildRouterHandler(ctx context.Context, routerName string, routerConfig *dynamic.RouterInfo) (http.Handler, error) {
if handler, ok := m.routerHandlers[routerName]; ok {
return handler, nil
}
@ -141,7 +141,7 @@ func (m *Manager) buildRouterHandler(ctx context.Context, routerName string, rou
return m.routerHandlers[routerName], nil
}
func (m *Manager) buildHTTPHandler(ctx context.Context, router *config.RouterInfo, routerName string) (http.Handler, error) {
func (m *Manager) buildHTTPHandler(ctx context.Context, router *dynamic.RouterInfo, routerName string) (http.Handler, error) {
qualifiedNames := make([]string, len(router.Middlewares))
for i, name := range router.Middlewares {
qualifiedNames[i] = internal.GetQualifiedName(ctx, name)

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/middlewares/accesslog"
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
"github.com/containous/traefik/pkg/responsemodifiers"
@ -30,25 +30,25 @@ func TestRouterManager_Get(t *testing.T) {
testCases := []struct {
desc string
routersConfig map[string]*config.Router
serviceConfig map[string]*config.Service
middlewaresConfig map[string]*config.Middleware
routersConfig map[string]*dynamic.Router
serviceConfig map[string]*dynamic.Service
middlewaresConfig map[string]*dynamic.Middleware
entryPoints []string
expected ExpectedResult
}{
{
desc: "no middleware",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -61,14 +61,14 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "no load balancer",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {},
},
entryPoints: []string{"web"},
@ -76,16 +76,16 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "no middleware, default entry point",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
Service: "foo-service",
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -98,17 +98,17 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "no middleware, no matching",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "Host(`bar.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -121,7 +121,7 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "middleware: headers > auth",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Middlewares: []string{"headers-middle", "auth-middle"},
@ -129,10 +129,10 @@ func TestRouterManager_Get(t *testing.T) {
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -140,14 +140,14 @@ func TestRouterManager_Get(t *testing.T) {
},
},
},
middlewaresConfig: map[string]*config.Middleware{
middlewaresConfig: map[string]*dynamic.Middleware{
"auth-middle": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"toto:titi"},
},
},
"headers-middle": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
},
},
@ -162,7 +162,7 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "middleware: auth > header",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Middlewares: []string{"auth-middle", "headers-middle"},
@ -170,10 +170,10 @@ func TestRouterManager_Get(t *testing.T) {
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -181,14 +181,14 @@ func TestRouterManager_Get(t *testing.T) {
},
},
},
middlewaresConfig: map[string]*config.Middleware{
middlewaresConfig: map[string]*dynamic.Middleware{
"auth-middle": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"toto:titi"},
},
},
"headers-middle": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
},
},
@ -203,17 +203,17 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "no middleware with provider name",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo@provider-1": {
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service@provider-1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -226,17 +226,17 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "no middleware with specified provider name",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo@provider-1": {
EntryPoints: []string{"web"},
Service: "foo-service@provider-2",
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service@provider-2": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -249,7 +249,7 @@ func TestRouterManager_Get(t *testing.T) {
},
{
desc: "middleware: chain with provider name",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo@provider-1": {
EntryPoints: []string{"web"},
Middlewares: []string{"chain-middle@provider-2", "headers-middle"},
@ -257,10 +257,10 @@ func TestRouterManager_Get(t *testing.T) {
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service@provider-1": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -268,17 +268,17 @@ func TestRouterManager_Get(t *testing.T) {
},
},
},
middlewaresConfig: map[string]*config.Middleware{
middlewaresConfig: map[string]*dynamic.Middleware{
"chain-middle@provider-2": {
Chain: &config.Chain{Middlewares: []string{"auth-middle"}},
Chain: &dynamic.Chain{Middlewares: []string{"auth-middle"}},
},
"auth-middle@provider-2": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"toto:titi"},
},
},
"headers-middle@provider-1": {
Headers: &config.Headers{
Headers: &dynamic.Headers{
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
},
},
@ -298,8 +298,8 @@ func TestRouterManager_Get(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Services: test.serviceConfig,
Routers: test.routersConfig,
Middlewares: test.middlewaresConfig,
@ -332,15 +332,15 @@ func TestAccessLog(t *testing.T) {
testCases := []struct {
desc string
routersConfig map[string]*config.Router
serviceConfig map[string]*config.Service
middlewaresConfig map[string]*config.Middleware
routersConfig map[string]*dynamic.Router
serviceConfig map[string]*dynamic.Service
middlewaresConfig map[string]*dynamic.Middleware
entryPoints []string
expected string
}{
{
desc: "apply routerName in accesslog (first match)",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -352,10 +352,10 @@ func TestAccessLog(t *testing.T) {
Rule: "Host(`bar.foo`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -368,7 +368,7 @@ func TestAccessLog(t *testing.T) {
},
{
desc: "apply routerName in accesslog (second match)",
routersConfig: map[string]*config.Router{
routersConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -380,10 +380,10 @@ func TestAccessLog(t *testing.T) {
Rule: "Host(`foo.bar`)",
},
},
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -399,8 +399,8 @@ func TestAccessLog(t *testing.T) {
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Services: test.serviceConfig,
Routers: test.routersConfig,
Middlewares: test.middlewaresConfig,
@ -438,17 +438,17 @@ func TestAccessLog(t *testing.T) {
func TestRuntimeConfiguration(t *testing.T) {
testCases := []struct {
desc string
serviceConfig map[string]*config.Service
routerConfig map[string]*config.Router
middlewareConfig map[string]*config.Middleware
serviceConfig map[string]*dynamic.Service
routerConfig map[string]*dynamic.Router
middlewareConfig map[string]*dynamic.Middleware
expectedError int
}{
{
desc: "No error",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1:8085",
},
@ -456,14 +456,14 @@ func TestRuntimeConfiguration(t *testing.T) {
URL: "http://127.0.0.1:8086",
},
},
HealthCheck: &config.HealthCheck{
HealthCheck: &dynamic.HealthCheck{
Interval: "500ms",
Path: "/health",
},
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -479,10 +479,10 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "One router with wrong rule",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -490,7 +490,7 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -506,10 +506,10 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "All router with wrong rule",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -517,7 +517,7 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -533,10 +533,10 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "Router with unknown service",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -544,7 +544,7 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "wrong-service",
@ -560,12 +560,12 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "Router with broken service",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: nil,
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"bar": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -576,10 +576,10 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "Router with middleware",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -587,19 +587,19 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
middlewareConfig: map[string]*config.Middleware{
middlewareConfig: map[string]*dynamic.Middleware{
"auth": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
"addPrefixTest": {
AddPrefix: &config.AddPrefix{
AddPrefix: &dynamic.AddPrefix{
Prefix: "/toto",
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"bar": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -616,10 +616,10 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "Router with unknown middleware",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -627,14 +627,14 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
middlewareConfig: map[string]*config.Middleware{
middlewareConfig: map[string]*dynamic.Middleware{
"auth": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"admin:admin"},
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"bar": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -647,10 +647,10 @@ func TestRuntimeConfiguration(t *testing.T) {
{
desc: "Router with broken middleware",
serviceConfig: map[string]*config.Service{
serviceConfig: map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://127.0.0.1",
},
@ -658,14 +658,14 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
middlewareConfig: map[string]*config.Middleware{
middlewareConfig: map[string]*dynamic.Middleware{
"auth": {
BasicAuth: &config.BasicAuth{
BasicAuth: &dynamic.BasicAuth{
Users: []string{"foo"},
},
},
},
routerConfig: map[string]*config.Router{
routerConfig: map[string]*dynamic.Router{
"bar": {
EntryPoints: []string{"web"},
Service: "foo-service",
@ -685,8 +685,8 @@ func TestRuntimeConfiguration(t *testing.T) {
entryPoints := []string{"web"}
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Services: test.serviceConfig,
Routers: test.routerConfig,
Middlewares: test.middlewareConfig,
@ -694,7 +694,7 @@ func TestRuntimeConfiguration(t *testing.T) {
})
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport)
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
responseModifierFactory := responsemodifiers.NewBuilder(map[string]*config.MiddlewareInfo{})
responseModifierFactory := responsemodifiers.NewBuilder(map[string]*dynamic.MiddlewareInfo{})
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
_ = routerManager.BuildHandlers(context.Background(), entryPoints, false)
@ -739,17 +739,17 @@ func BenchmarkRouterServe(b *testing.B) {
StatusCode: 200,
Body: ioutil.NopCloser(strings.NewReader("")),
}
routersConfig := map[string]*config.Router{
routersConfig := map[string]*dynamic.Router{
"foo": {
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "Host(`foo.bar`) && Path(`/`)",
},
}
serviceConfig := map[string]*config.Service{
serviceConfig := map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server.URL,
},
@ -759,11 +759,11 @@ func BenchmarkRouterServe(b *testing.B) {
}
entryPoints := []string{"web"}
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Services: serviceConfig,
Routers: routersConfig,
Middlewares: map[string]*config.Middleware{},
Middlewares: map[string]*dynamic.Middleware{},
},
})
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res})
@ -790,10 +790,10 @@ func BenchmarkService(b *testing.B) {
Body: ioutil.NopCloser(strings.NewReader("")),
}
serviceConfig := map[string]*config.Service{
serviceConfig := map[string]*dynamic.Service{
"foo-service": {
LoadBalancer: &config.LoadBalancerService{
Servers: []config.Server{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "tchouck",
},
@ -802,8 +802,8 @@ func BenchmarkService(b *testing.B) {
},
}
rtConf := config.NewRuntimeConfig(config.Configuration{
HTTP: &config.HTTPConfiguration{
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{
Services: serviceConfig,
},
})

View file

@ -6,7 +6,7 @@ import (
"fmt"
"net/http"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/rules"
"github.com/containous/traefik/pkg/server/internal"
@ -16,7 +16,7 @@ import (
)
// NewManager Creates a new Manager
func NewManager(conf *config.RuntimeConfiguration,
func NewManager(conf *dynamic.RuntimeConfiguration,
serviceManager *tcpservice.Manager,
httpHandlers map[string]http.Handler,
httpsHandlers map[string]http.Handler,
@ -37,23 +37,23 @@ type Manager struct {
httpHandlers map[string]http.Handler
httpsHandlers map[string]http.Handler
tlsManager *traefiktls.Manager
conf *config.RuntimeConfiguration
conf *dynamic.RuntimeConfiguration
}
func (m *Manager) getTCPRouters(ctx context.Context, entryPoints []string) map[string]map[string]*config.TCPRouterInfo {
func (m *Manager) getTCPRouters(ctx context.Context, entryPoints []string) map[string]map[string]*dynamic.TCPRouterInfo {
if m.conf != nil {
return m.conf.GetTCPRoutersByEntrypoints(ctx, entryPoints)
}
return make(map[string]map[string]*config.TCPRouterInfo)
return make(map[string]map[string]*dynamic.TCPRouterInfo)
}
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*config.RouterInfo {
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*dynamic.RouterInfo {
if m.conf != nil {
return m.conf.GetRoutersByEntrypoints(ctx, entryPoints, tls)
}
return make(map[string]map[string]*config.RouterInfo)
return make(map[string]map[string]*dynamic.RouterInfo)
}
// BuildHandlers builds the handlers for the given entrypoints
@ -79,7 +79,7 @@ func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string) m
return entryPointHandlers
}
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*config.TCPRouterInfo, configsHTTP map[string]*config.RouterInfo, handlerHTTP http.Handler, handlerHTTPS http.Handler) (*tcp.Router, error) {
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*dynamic.TCPRouterInfo, configsHTTP map[string]*dynamic.RouterInfo, handlerHTTP http.Handler, handlerHTTPS http.Handler) (*tcp.Router, error) {
router := &tcp.Router{}
router.HTTPHandler(handlerHTTP)
const defaultTLSConfigName = "default"

View file

@ -4,7 +4,7 @@ import (
"context"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/server/service/tcp"
"github.com/containous/traefik/pkg/tls"
"github.com/stretchr/testify/assert"
@ -13,17 +13,17 @@ import (
func TestRuntimeConfiguration(t *testing.T) {
testCases := []struct {
desc string
serviceConfig map[string]*config.TCPServiceInfo
routerConfig map[string]*config.TCPRouterInfo
serviceConfig map[string]*dynamic.TCPServiceInfo
routerConfig map[string]*dynamic.TCPRouterInfo
expectedError int
}{
{
desc: "No error",
serviceConfig: map[string]*config.TCPServiceInfo{
serviceConfig: map[string]*dynamic.TCPServiceInfo{
"foo-service": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Port: "8085",
Address: "127.0.0.1:8085",
@ -37,25 +37,25 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.TCPRouterInfo{
routerConfig: map[string]*dynamic.TCPRouterInfo{
"foo": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "HostSNI(`bar.foo`)",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
Options: "foo",
},
},
},
"bar": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "HostSNI(`foo.bar`)",
TLS: &config.RouterTCPTLSConfig{
TLS: &dynamic.RouterTCPTLSConfig{
Passthrough: false,
Options: "bar",
},
@ -66,11 +66,11 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "One router with wrong rule",
serviceConfig: map[string]*config.TCPServiceInfo{
serviceConfig: map[string]*dynamic.TCPServiceInfo{
"foo-service": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
@ -79,9 +79,9 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.TCPRouterInfo{
routerConfig: map[string]*dynamic.TCPRouterInfo{
"foo": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "WrongRule(`bar.foo`)",
@ -89,7 +89,7 @@ func TestRuntimeConfiguration(t *testing.T) {
},
"bar": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "HostSNI(`foo.bar`)",
@ -100,11 +100,11 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "All router with wrong rule",
serviceConfig: map[string]*config.TCPServiceInfo{
serviceConfig: map[string]*dynamic.TCPServiceInfo{
"foo-service": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
@ -113,16 +113,16 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.TCPRouterInfo{
routerConfig: map[string]*dynamic.TCPRouterInfo{
"foo": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "WrongRule(`bar.foo`)",
},
},
"bar": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "WrongRule(`foo.bar`)",
@ -133,11 +133,11 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "Router with unknown service",
serviceConfig: map[string]*config.TCPServiceInfo{
serviceConfig: map[string]*dynamic.TCPServiceInfo{
"foo-service": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "127.0.0.1:80",
},
@ -146,16 +146,16 @@ func TestRuntimeConfiguration(t *testing.T) {
},
},
},
routerConfig: map[string]*config.TCPRouterInfo{
routerConfig: map[string]*dynamic.TCPRouterInfo{
"foo": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "wrong-service",
Rule: "HostSNI(`bar.foo`)",
},
},
"bar": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
@ -167,16 +167,16 @@ func TestRuntimeConfiguration(t *testing.T) {
},
{
desc: "Router with broken service",
serviceConfig: map[string]*config.TCPServiceInfo{
serviceConfig: map[string]*dynamic.TCPServiceInfo{
"foo-service": {
TCPService: &config.TCPService{
TCPService: &dynamic.TCPService{
LoadBalancer: nil,
},
},
},
routerConfig: map[string]*config.TCPRouterInfo{
routerConfig: map[string]*dynamic.TCPRouterInfo{
"bar": {
TCPRouter: &config.TCPRouter{
TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"},
Service: "foo-service",
Rule: "HostSNI(`foo.bar`)",
@ -195,7 +195,7 @@ func TestRuntimeConfiguration(t *testing.T) {
entryPoints := []string{"web"}
conf := &config.RuntimeConfiguration{
conf := &dynamic.RuntimeConfiguration{
TCPServices: test.serviceConfig,
TCPRouters: test.routerConfig,
}

View file

@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/metrics"
@ -27,19 +27,19 @@ import (
// Server is the reverse-proxy/load-balancer engine
type Server struct {
entryPointsTCP TCPEntryPoints
configurationChan chan config.Message
configurationValidatedChan chan config.Message
configurationChan chan dynamic.Message
configurationValidatedChan chan dynamic.Message
signals chan os.Signal
stopChan chan bool
currentConfigurations safe.Safe
providerConfigUpdateMap map[string]chan config.Message
providerConfigUpdateMap map[string]chan dynamic.Message
accessLoggerMiddleware *accesslog.Handler
tracer *tracing.Tracing
routinesPool *safe.Pool
defaultRoundTripper http.RoundTripper
metricsRegistry metrics.Registry
provider provider.Provider
configurationListeners []func(config.Configuration)
configurationListeners []func(dynamic.Configuration)
requestDecorator *requestdecorator.RequestDecorator
providersThrottleDuration time.Duration
tlsManager *tls.Manager
@ -47,7 +47,7 @@ type Server struct {
// RouteAppenderFactory the route appender factory interface
type RouteAppenderFactory interface {
NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *config.RuntimeConfiguration) types.RouteAppender
NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *dynamic.RuntimeConfiguration) types.RouteAppender
}
func setupTracing(conf *static.Tracing) tracing.Backend {
@ -104,14 +104,14 @@ func NewServer(staticConfiguration static.Configuration, provider provider.Provi
server.provider = provider
server.entryPointsTCP = entryPoints
server.configurationChan = make(chan config.Message, 100)
server.configurationValidatedChan = make(chan config.Message, 100)
server.configurationChan = make(chan dynamic.Message, 100)
server.configurationValidatedChan = make(chan dynamic.Message, 100)
server.signals = make(chan os.Signal, 1)
server.stopChan = make(chan bool, 1)
server.configureSignals()
currentConfigurations := make(config.Configurations)
currentConfigurations := make(dynamic.Configurations)
server.currentConfigurations.Set(currentConfigurations)
server.providerConfigUpdateMap = make(map[string]chan config.Message)
server.providerConfigUpdateMap = make(map[string]chan dynamic.Message)
server.tlsManager = tlsManager
if staticConfiguration.Providers != nil {
@ -236,7 +236,7 @@ func (s *Server) Close() {
func (s *Server) startTCPServers() {
// Use an empty configuration in order to initialize the default handlers with internal routes
routers := s.loadConfigurationTCP(config.Configurations{})
routers := s.loadConfigurationTCP(dynamic.Configurations{})
for entryPointName, router := range routers {
s.entryPointsTCP[entryPointName].switchRouter(router)
}
@ -266,9 +266,9 @@ func (s *Server) listenProviders(stop chan bool) {
}
// AddListener adds a new listener function used when new configuration is provided
func (s *Server) AddListener(listener func(config.Configuration)) {
func (s *Server) AddListener(listener func(dynamic.Configuration)) {
if s.configurationListeners == nil {
s.configurationListeners = make([]func(config.Configuration), 0)
s.configurationListeners = make([]func(dynamic.Configuration), 0)
}
s.configurationListeners = append(s.configurationListeners, listener)
}

View file

@ -9,7 +9,7 @@ import (
"github.com/containous/alice"
"github.com/containous/mux"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/middlewares/accesslog"
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
@ -26,8 +26,8 @@ import (
)
// loadConfiguration manages dynamically routers, middlewares, servers and TLS configurations
func (s *Server) loadConfiguration(configMsg config.Message) {
currentConfigurations := s.currentConfigurations.Get().(config.Configurations)
func (s *Server) loadConfiguration(configMsg dynamic.Message) {
currentConfigurations := s.currentConfigurations.Get().(dynamic.Configurations)
// Copy configurations to new map so we don't change current if LoadConfig fails
newConfigurations := currentConfigurations.DeepCopy()
@ -53,7 +53,7 @@ func (s *Server) loadConfiguration(configMsg config.Message) {
// loadConfigurationTCP returns a new gorilla.mux Route from the specified global configuration and the dynamic
// provider configurations.
func (s *Server) loadConfigurationTCP(configurations config.Configurations) map[string]*tcpCore.Router {
func (s *Server) loadConfigurationTCP(configurations dynamic.Configurations) map[string]*tcpCore.Router {
ctx := context.TODO()
var entryPoints []string
@ -65,7 +65,7 @@ func (s *Server) loadConfigurationTCP(configurations config.Configurations) map[
s.tlsManager.UpdateConfigs(conf.TLS.Stores, conf.TLS.Options, conf.TLS.Certificates)
rtConf := config.NewRuntimeConfig(conf)
rtConf := dynamic.NewRuntimeConfig(conf)
handlersNonTLS, handlersTLS := s.createHTTPHandlers(ctx, rtConf, entryPoints)
routersTCP := s.createTCPRouters(ctx, rtConf, entryPoints, handlersNonTLS, handlersTLS)
rtConf.PopulateUsedBy()
@ -74,7 +74,7 @@ func (s *Server) loadConfigurationTCP(configurations config.Configurations) map[
}
// the given configuration must not be nil. its fields will get mutated.
func (s *Server) createTCPRouters(ctx context.Context, configuration *config.RuntimeConfiguration, entryPoints []string, handlers map[string]http.Handler, handlersTLS map[string]http.Handler) map[string]*tcpCore.Router {
func (s *Server) createTCPRouters(ctx context.Context, configuration *dynamic.RuntimeConfiguration, entryPoints []string, handlers map[string]http.Handler, handlersTLS map[string]http.Handler) map[string]*tcpCore.Router {
if configuration == nil {
return make(map[string]*tcpCore.Router)
}
@ -87,7 +87,7 @@ func (s *Server) createTCPRouters(ctx context.Context, configuration *config.Run
}
// createHTTPHandlers returns, for the given configuration and entryPoints, the HTTP handlers for non-TLS connections, and for the TLS ones. the given configuration must not be nil. its fields will get mutated.
func (s *Server) createHTTPHandlers(ctx context.Context, configuration *config.RuntimeConfiguration, entryPoints []string) (map[string]http.Handler, map[string]http.Handler) {
func (s *Server) createHTTPHandlers(ctx context.Context, configuration *dynamic.RuntimeConfiguration, entryPoints []string) (map[string]http.Handler, map[string]http.Handler) {
serviceManager := service.NewManager(configuration.Services, s.defaultRoundTripper)
middlewaresBuilder := middleware.NewBuilder(configuration.Middlewares, serviceManager)
responseModifierFactory := responsemodifiers.NewBuilder(configuration.Middlewares)
@ -150,15 +150,15 @@ func (s *Server) createHTTPHandlers(ctx context.Context, configuration *config.R
return routerHandlers, handlersTLS
}
func isEmptyConfiguration(conf *config.Configuration) bool {
func isEmptyConfiguration(conf *dynamic.Configuration) bool {
if conf == nil {
return true
}
if conf.TCP == nil {
conf.TCP = &config.TCPConfiguration{}
conf.TCP = &dynamic.TCPConfiguration{}
}
if conf.HTTP == nil {
conf.HTTP = &config.HTTPConfiguration{}
conf.HTTP = &dynamic.HTTPConfiguration{}
}
return conf.HTTP.Routers == nil &&
@ -169,9 +169,9 @@ func isEmptyConfiguration(conf *config.Configuration) bool {
conf.TCP.Services == nil
}
func (s *Server) preLoadConfiguration(configMsg config.Message) {
func (s *Server) preLoadConfiguration(configMsg dynamic.Message) {
s.defaultConfigurationValues(configMsg.Configuration.HTTP)
currentConfigurations := s.currentConfigurations.Get().(config.Configurations)
currentConfigurations := s.currentConfigurations.Get().(dynamic.Configurations)
logger := log.WithoutContext().WithField(log.ProviderName, configMsg.ProviderName)
if log.GetLevel() == logrus.DebugLevel {
@ -191,7 +191,7 @@ func (s *Server) preLoadConfiguration(configMsg config.Message) {
providerConfigUpdateCh, ok := s.providerConfigUpdateMap[configMsg.ProviderName]
if !ok {
providerConfigUpdateCh = make(chan config.Message)
providerConfigUpdateCh = make(chan dynamic.Message)
s.providerConfigUpdateMap[configMsg.ProviderName] = providerConfigUpdateCh
s.routinesPool.Go(func(stop chan bool) {
s.throttleProviderConfigReload(s.providersThrottleDuration, s.configurationValidatedChan, providerConfigUpdateCh, stop)
@ -201,7 +201,7 @@ func (s *Server) preLoadConfiguration(configMsg config.Message) {
providerConfigUpdateCh <- configMsg
}
func (s *Server) defaultConfigurationValues(configuration *config.HTTPConfiguration) {
func (s *Server) defaultConfigurationValues(configuration *dynamic.HTTPConfiguration) {
// FIXME create a config hook
}
@ -223,7 +223,7 @@ func (s *Server) listenConfigurations(stop chan bool) {
// It will immediately publish a new configuration and then only publish the next configuration after the throttle duration.
// Note that in the case it receives N new configs in the timeframe of the throttle duration after publishing,
// it will publish the last of the newly received configurations.
func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish chan<- config.Message, in <-chan config.Message, stop chan bool) {
func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish chan<- dynamic.Message, in <-chan dynamic.Message, stop chan bool) {
ring := channels.NewRingChannel(1)
defer ring.Close()
@ -233,7 +233,7 @@ func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish ch
case <-stop:
return
case nextConfig := <-ring.Out():
if config, ok := nextConfig.(config.Message); ok {
if config, ok := nextConfig.(dynamic.Message); ok {
publish <- config
time.Sleep(throttle)
}

View file

@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
th "github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
@ -37,7 +37,7 @@ func TestReuseService(t *testing.T) {
th.WithRouterMiddlewares("basicauth")),
),
th.WithMiddlewares(th.WithMiddleware("basicauth",
th.WithBasicAuth(&config.BasicAuth{Users: []string{"foo:bar"}}),
th.WithBasicAuth(&dynamic.BasicAuth{Users: []string{"foo:bar"}}),
)),
th.WithLoadBalancerServices(th.WithService("bar",
th.WithServers(th.WithServer(testServer.URL))),
@ -46,7 +46,7 @@ func TestReuseService(t *testing.T) {
srv := NewServer(staticConfig, nil, entryPoints, nil)
rtConf := config.NewRuntimeConfig(config.Configuration{HTTP: dynamicConfigs})
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{HTTP: dynamicConfigs})
entrypointsHandlers, _ := srv.createHTTPHandlers(context.Background(), rtConf, []string{"http"})
// Test that the /ok path returns a status 200.
@ -67,8 +67,8 @@ func TestReuseService(t *testing.T) {
func TestThrottleProviderConfigReload(t *testing.T) {
throttleDuration := 30 * time.Millisecond
publishConfig := make(chan config.Message)
providerConfig := make(chan config.Message)
publishConfig := make(chan dynamic.Message)
providerConfig := make(chan dynamic.Message)
stop := make(chan bool)
defer func() {
stop <- true
@ -96,7 +96,7 @@ func TestThrottleProviderConfigReload(t *testing.T) {
// publish 5 new configs, one new config each 10 milliseconds
for i := 0; i < 5; i++ {
providerConfig <- config.Message{}
providerConfig <- dynamic.Message{}
time.Sleep(10 * time.Millisecond)
}

View file

@ -7,7 +7,7 @@ import (
"testing"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/static"
th "github.com/containous/traefik/pkg/testhelpers"
"github.com/containous/traefik/pkg/types"
@ -29,7 +29,7 @@ func TestListenProvidersSkipsEmptyConfigs(t *testing.T) {
}
}()
server.configurationChan <- config.Message{ProviderName: "kubernetes"}
server.configurationChan <- dynamic.Message{ProviderName: "kubernetes"}
// give some time so that the configuration can be processed
time.Sleep(100 * time.Millisecond)
@ -49,7 +49,7 @@ func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
// set the current configuration
// this is usually done in the processing part of the published configuration
// so we have to emulate the behavior here
currentConfigurations := server.currentConfigurations.Get().(config.Configurations)
currentConfigurations := server.currentConfigurations.Get().(dynamic.Configurations)
currentConfigurations[conf.ProviderName] = conf.Configuration
server.currentConfigurations.Set(currentConfigurations)
@ -60,20 +60,20 @@ func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
}
}
}()
conf := &config.Configuration{}
conf := &dynamic.Configuration{}
conf.HTTP = th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo")),
th.WithLoadBalancerServices(th.WithService("bar")),
)
// provide a configuration
server.configurationChan <- config.Message{ProviderName: "kubernetes", Configuration: conf}
server.configurationChan <- dynamic.Message{ProviderName: "kubernetes", Configuration: conf}
// give some time so that the configuration can be processed
time.Sleep(20 * time.Millisecond)
// provide the same configuration a second time
server.configurationChan <- config.Message{ProviderName: "kubernetes", Configuration: conf}
server.configurationChan <- dynamic.Message{ProviderName: "kubernetes", Configuration: conf}
// give some time so that the configuration can be processed
time.Sleep(100 * time.Millisecond)
@ -102,13 +102,13 @@ func TestListenProvidersPublishesConfigForEachProvider(t *testing.T) {
}
}()
conf := &config.Configuration{}
conf := &dynamic.Configuration{}
conf.HTTP = th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo")),
th.WithLoadBalancerServices(th.WithService("bar")),
)
server.configurationChan <- config.Message{ProviderName: "kubernetes", Configuration: conf}
server.configurationChan <- config.Message{ProviderName: "marathon", Configuration: conf}
server.configurationChan <- dynamic.Message{ProviderName: "kubernetes", Configuration: conf}
server.configurationChan <- dynamic.Message{ProviderName: "marathon", Configuration: conf}
select {
case <-consumePublishedConfigsDone:
@ -148,12 +148,12 @@ func TestServerResponseEmptyBackend(t *testing.T) {
testCases := []struct {
desc string
config func(testServerURL string) *config.HTTPConfiguration
config func(testServerURL string) *dynamic.HTTPConfiguration
expectedStatusCode int
}{
{
desc: "Ok",
config: func(testServerURL string) *config.HTTPConfiguration {
config: func(testServerURL string) *dynamic.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
@ -169,14 +169,14 @@ func TestServerResponseEmptyBackend(t *testing.T) {
},
{
desc: "No Frontend",
config: func(testServerURL string) *config.HTTPConfiguration {
config: func(testServerURL string) *dynamic.HTTPConfiguration {
return th.BuildConfiguration()
},
expectedStatusCode: http.StatusNotFound,
},
{
desc: "Empty Backend LB",
config: func(testServerURL string) *config.HTTPConfiguration {
config: func(testServerURL string) *dynamic.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
@ -190,7 +190,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
},
{
desc: "Empty Backend LB Sticky",
config: func(testServerURL string) *config.HTTPConfiguration {
config: func(testServerURL string) *dynamic.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
@ -206,7 +206,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
},
{
desc: "Empty Backend LB",
config: func(testServerURL string) *config.HTTPConfiguration {
config: func(testServerURL string) *dynamic.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
@ -220,7 +220,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
},
{
desc: "Empty Backend LB Sticky",
config: func(testServerURL string) *config.HTTPConfiguration {
config: func(testServerURL string) *dynamic.HTTPConfiguration {
return th.BuildConfiguration(
th.WithRouters(th.WithRouter("foo",
th.WithEntryPoints("http"),
@ -253,7 +253,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
}
srv := NewServer(globalConfig, nil, entryPointsConfig, nil)
rtConf := config.NewRuntimeConfig(config.Configuration{HTTP: test.config(testServer.URL)})
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{HTTP: test.config(testServer.URL)})
entryPoints, _ := srv.createHTTPHandlers(context.Background(), rtConf, []string{"http"})
responseRecorder := &httptest.ResponseRecorder{}

View file

@ -10,7 +10,7 @@ import (
"net/url"
"time"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/types"
)
@ -21,7 +21,7 @@ const StatusClientClosedRequest = 499
// StatusClientClosedRequestText non-standard HTTP status for client disconnection
const StatusClientClosedRequestText = "Client Closed Request"
func buildProxy(passHostHeader bool, responseForwarding *config.ResponseForwarding, defaultRoundTripper http.RoundTripper, bufferPool httputil.BufferPool, responseModifier func(*http.Response) error) (http.Handler, error) {
func buildProxy(passHostHeader bool, responseForwarding *dynamic.ResponseForwarding, defaultRoundTripper http.RoundTripper, bufferPool httputil.BufferPool, responseModifier func(*http.Response) error) (http.Handler, error) {
var flushInterval types.Duration
if responseForwarding != nil {
err := flushInterval.Set(responseForwarding.FlushInterval)

View file

@ -9,7 +9,7 @@ import (
"time"
"github.com/containous/alice"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/healthcheck"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/middlewares/accesslog"
@ -26,7 +26,7 @@ const (
)
// NewManager creates a new Manager
func NewManager(configs map[string]*config.ServiceInfo, defaultRoundTripper http.RoundTripper) *Manager {
func NewManager(configs map[string]*dynamic.ServiceInfo, defaultRoundTripper http.RoundTripper) *Manager {
return &Manager{
bufferPool: newBufferPool(),
defaultRoundTripper: defaultRoundTripper,
@ -40,7 +40,7 @@ type Manager struct {
bufferPool httputil.BufferPool
defaultRoundTripper http.RoundTripper
balancers map[string][]healthcheck.BalancerHandler
configs map[string]*config.ServiceInfo
configs map[string]*dynamic.ServiceInfo
}
// BuildHTTP Creates a http.Handler for a service configuration.
@ -74,7 +74,7 @@ func (m *Manager) BuildHTTP(rootCtx context.Context, serviceName string, respons
func (m *Manager) getLoadBalancerServiceHandler(
ctx context.Context,
serviceName string,
service *config.LoadBalancerService,
service *dynamic.LoadBalancerService,
responseModifier func(*http.Response) error,
) (http.Handler, error) {
fwd, err := buildProxy(service.PassHostHeader, service.ResponseForwarding, m.defaultRoundTripper, m.bufferPool, responseModifier)
@ -134,7 +134,7 @@ func (m *Manager) LaunchHealthCheck() {
healthcheck.GetHealthCheck().SetBackendsConfiguration(context.TODO(), backendConfigs)
}
func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler, backend string, hc *config.HealthCheck) *healthcheck.Options {
func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler, backend string, hc *dynamic.HealthCheck) *healthcheck.Options {
if hc == nil || hc.Path == "" {
return nil
}
@ -183,7 +183,7 @@ func buildHealthCheckOptions(ctx context.Context, lb healthcheck.BalancerHandler
}
}
func (m *Manager) getLoadBalancer(ctx context.Context, serviceName string, service *config.LoadBalancerService, fwd http.Handler) (healthcheck.BalancerHandler, error) {
func (m *Manager) getLoadBalancer(ctx context.Context, serviceName string, service *dynamic.LoadBalancerService, fwd http.Handler) (healthcheck.BalancerHandler, error) {
logger := log.FromContext(ctx)
logger.Debug("Creating load-balancer")
@ -210,7 +210,7 @@ func (m *Manager) getLoadBalancer(ctx context.Context, serviceName string, servi
return lb, nil
}
func (m *Manager) upsertServers(ctx context.Context, lb healthcheck.BalancerHandler, servers []config.Server) error {
func (m *Manager) upsertServers(ctx context.Context, lb healthcheck.BalancerHandler, servers []dynamic.Server) error {
logger := log.FromContext(ctx)
for name, srv := range servers {

View file

@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/server/internal"
"github.com/containous/traefik/pkg/testhelpers"
"github.com/stretchr/testify/assert"
@ -26,15 +26,15 @@ func TestGetLoadBalancer(t *testing.T) {
testCases := []struct {
desc string
serviceName string
service *config.LoadBalancerService
service *dynamic.LoadBalancerService
fwd http.Handler
expectError bool
}{
{
desc: "Fails when provided an invalid URL",
serviceName: "test",
service: &config.LoadBalancerService{
Servers: []config.Server{
service: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: ":",
},
@ -46,15 +46,15 @@ func TestGetLoadBalancer(t *testing.T) {
{
desc: "Succeeds when there are no servers",
serviceName: "test",
service: &config.LoadBalancerService{},
service: &dynamic.LoadBalancerService{},
fwd: &MockForwarder{},
expectError: false,
},
{
desc: "Succeeds when stickiness is set",
serviceName: "test",
service: &config.LoadBalancerService{
Stickiness: &config.Stickiness{},
service: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{},
},
fwd: &MockForwarder{},
expectError: false,
@ -113,7 +113,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
testCases := []struct {
desc string
serviceName string
service *config.LoadBalancerService
service *dynamic.LoadBalancerService
responseModifier func(*http.Response) error
expected []ExpectedResult
@ -121,8 +121,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "Load balances between the two servers",
serviceName: "test",
service: &config.LoadBalancerService{
Servers: []config.Server{
service: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: server1.URL,
},
@ -145,8 +145,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "StatusBadGateway when the server is not reachable",
serviceName: "test",
service: &config.LoadBalancerService{
Servers: []config.Server{
service: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{
{
URL: "http://foo",
},
@ -161,8 +161,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "ServiceUnavailable when no servers are available",
serviceName: "test",
service: &config.LoadBalancerService{
Servers: []config.Server{},
service: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{},
},
expected: []ExpectedResult{
{
@ -173,9 +173,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "Always call the same server when stickiness is true",
serviceName: "test",
service: &config.LoadBalancerService{
Stickiness: &config.Stickiness{},
Servers: []config.Server{
service: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{},
Servers: []dynamic.Server{
{
URL: server1.URL,
},
@ -198,9 +198,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "Sticky Cookie's options set correctly",
serviceName: "test",
service: &config.LoadBalancerService{
Stickiness: &config.Stickiness{HTTPOnlyCookie: true, SecureCookie: true},
Servers: []config.Server{
service: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{HTTPOnlyCookie: true, SecureCookie: true},
Servers: []dynamic.Server{
{
URL: server1.URL,
},
@ -218,10 +218,10 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "PassHost passes the host instead of the IP",
serviceName: "test",
service: &config.LoadBalancerService{
Stickiness: &config.Stickiness{},
service: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{},
PassHostHeader: true,
Servers: []config.Server{
Servers: []dynamic.Server{
{
URL: serverPassHost.URL,
},
@ -237,9 +237,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
{
desc: "PassHost doesn't passe the host instead of the IP",
serviceName: "test",
service: &config.LoadBalancerService{
Stickiness: &config.Stickiness{},
Servers: []config.Server{
service: &dynamic.LoadBalancerService{
Stickiness: &dynamic.Stickiness{},
Servers: []dynamic.Server{
{
URL: serverPassHostFalse.URL,
},
@ -287,16 +287,16 @@ func TestManager_Build(t *testing.T) {
testCases := []struct {
desc string
serviceName string
configs map[string]*config.ServiceInfo
configs map[string]*dynamic.ServiceInfo
providerName string
}{
{
desc: "Simple service name",
serviceName: "serviceName",
configs: map[string]*config.ServiceInfo{
configs: map[string]*dynamic.ServiceInfo{
"serviceName": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{},
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{},
},
},
},
@ -304,10 +304,10 @@ func TestManager_Build(t *testing.T) {
{
desc: "Service name with provider",
serviceName: "serviceName@provider-1",
configs: map[string]*config.ServiceInfo{
configs: map[string]*dynamic.ServiceInfo{
"serviceName@provider-1": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{},
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{},
},
},
},
@ -315,10 +315,10 @@ func TestManager_Build(t *testing.T) {
{
desc: "Service name with provider in context",
serviceName: "serviceName",
configs: map[string]*config.ServiceInfo{
configs: map[string]*dynamic.ServiceInfo{
"serviceName@provider-1": {
Service: &config.Service{
LoadBalancer: &config.LoadBalancerService{},
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{},
},
},
},

View file

@ -5,7 +5,7 @@ import (
"fmt"
"net"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/server/internal"
"github.com/containous/traefik/pkg/tcp"
@ -13,11 +13,11 @@ import (
// Manager is the TCPHandlers factory
type Manager struct {
configs map[string]*config.TCPServiceInfo
configs map[string]*dynamic.TCPServiceInfo
}
// NewManager creates a new manager
func NewManager(conf *config.RuntimeConfiguration) *Manager {
func NewManager(conf *dynamic.RuntimeConfiguration) *Manager {
return &Manager{
configs: conf.TCPServices,
}

View file

@ -4,7 +4,7 @@ import (
"context"
"testing"
"github.com/containous/traefik/pkg/config"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/server/internal"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -14,7 +14,7 @@ func TestManager_BuildTCP(t *testing.T) {
testCases := []struct {
desc string
serviceName string
configs map[string]*config.TCPServiceInfo
configs map[string]*dynamic.TCPServiceInfo
providerName string
expectedError string
}{
@ -27,9 +27,9 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "missing lb configuration",
serviceName: "test",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"test": {
TCPService: &config.TCPService{},
TCPService: &dynamic.TCPService{},
},
},
expectedError: `the service "test" doesn't have any TCP load balancer`,
@ -37,11 +37,11 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "no such host, server is skipped, error is logged",
serviceName: "test",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"test": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{Address: "test:31"},
},
},
@ -52,11 +52,11 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "invalid IP address, server is skipped, error is logged",
serviceName: "test",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"test": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{Address: "foobar"},
},
},
@ -67,10 +67,10 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "Simple service name",
serviceName: "serviceName",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{},
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{},
},
},
},
@ -78,10 +78,10 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "Service name with provider",
serviceName: "serviceName@provider-1",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName@provider-1": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{},
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{},
},
},
},
@ -89,10 +89,10 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "Service name with provider in context",
serviceName: "serviceName",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName@provider-1": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{},
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{},
},
},
},
@ -101,11 +101,11 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "Server with correct host:port as address",
serviceName: "serviceName",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName@provider-1": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "foobar.com:80",
},
@ -119,11 +119,11 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "Server with correct ip:port as address",
serviceName: "serviceName",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName@provider-1": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "192.168.0.12:80",
},
@ -137,11 +137,11 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "missing port in address with hostname, server is skipped, error is logged",
serviceName: "serviceName",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName@provider-1": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "foobar.com",
},
@ -155,11 +155,11 @@ func TestManager_BuildTCP(t *testing.T) {
{
desc: "missing port in address with ip, server is skipped, error is logged",
serviceName: "serviceName",
configs: map[string]*config.TCPServiceInfo{
configs: map[string]*dynamic.TCPServiceInfo{
"serviceName@provider-1": {
TCPService: &config.TCPService{
LoadBalancer: &config.TCPLoadBalancerService{
Servers: []config.TCPServer{
TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{
Servers: []dynamic.TCPServer{
{
Address: "192.168.0.12",
},
@ -177,7 +177,7 @@ func TestManager_BuildTCP(t *testing.T) {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()
manager := NewManager(&config.RuntimeConfiguration{
manager := NewManager(&dynamic.RuntimeConfiguration{
TCPServices: test.configs,
})

Some files were not shown because too many files have changed in this diff Show more