diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index 0527ebfe9..d7f346593 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -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()) diff --git a/integration/https_test.go b/integration/https_test.go index a226c54ce..d589f216d 100644 --- a/integration/https_test.go +++ b/integration/https_test.go @@ -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"), diff --git a/integration/rest_test.go b/integration/rest_test.go index 86cad9d90..1cb330cf2 100644 --- a/integration/rest_test.go +++ b/integration/rest_test.go @@ -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", }, diff --git a/integration/simple_test.go b/integration/simple_test.go index 063f0dfcc..a6c8a3ea5 100644 --- a/integration/simple_test.go +++ b/integration/simple_test.go @@ -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"}, diff --git a/internal/gendoc.go b/internal/gendoc.go index 9b9efc01e..92405a4d3 100644 --- a/internal/gendoc.go +++ b/internal/gendoc.go @@ -48,8 +48,8 @@ func genStaticConfDoc(outputFile string, prefix string, encodeFn func(interface{ w.writeln(` -`) +-->`) + w.writeln() for i, flat := range flats { w.writeln("`" + prefix + strings.ReplaceAll(flat.Name, "[0]", "[n]") + "`: ") diff --git a/pkg/api/handler.go b/pkg/api/handler.go index 4520343d9..2fecfc9c2 100644 --- a/pkg/api/handler.go +++ b/pkg/api/handler.go @@ -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{ diff --git a/pkg/api/handler_test.go b/pkg/api/handler_test.go index ce10158a2..fa770b33a 100644 --- a/pkg/api/handler_test.go +++ b/pkg/api/handler_test.go @@ -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) + "`)", diff --git a/pkg/config/dynamic/config.go b/pkg/config/dynamic/config.go new file mode 100644 index 000000000..07845ca97 --- /dev/null +++ b/pkg/config/dynamic/config.go @@ -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"` +} diff --git a/pkg/config/dyn_config_test.go b/pkg/config/dynamic/config_test.go similarity index 98% rename from pkg/config/dyn_config_test.go rename to pkg/config/dynamic/config_test.go index ee0467141..4a04509c4 100644 --- a/pkg/config/dyn_config_test.go +++ b/pkg/config/dynamic/config_test.go @@ -1,4 +1,4 @@ -package config +package dynamic import ( "reflect" diff --git a/pkg/config/fixtures/sample.toml b/pkg/config/dynamic/fixtures/sample.toml similarity index 100% rename from pkg/config/fixtures/sample.toml rename to pkg/config/dynamic/fixtures/sample.toml diff --git a/pkg/config/dyn_config.go b/pkg/config/dynamic/http_config.go similarity index 57% rename from pkg/config/dyn_config.go rename to pkg/config/dynamic/http_config.go index 63e7c4daa..f58bd0753 100644 --- a/pkg/config/dyn_config.go +++ b/pkg/config/dynamic/http_config.go @@ -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" diff --git a/pkg/config/middlewares.go b/pkg/config/dynamic/middlewares.go similarity index 99% rename from pkg/config/middlewares.go rename to pkg/config/dynamic/middlewares.go index 8b8ee3599..2c7482e48 100644 --- a/pkg/config/middlewares.go +++ b/pkg/config/dynamic/middlewares.go @@ -1,4 +1,4 @@ -package config +package dynamic import ( "crypto/tls" diff --git a/pkg/config/runtime.go b/pkg/config/dynamic/runtime.go similarity index 99% rename from pkg/config/runtime.go rename to pkg/config/dynamic/runtime.go index d5a1c512a..94dfe2c94 100644 --- a/pkg/config/runtime.go +++ b/pkg/config/dynamic/runtime.go @@ -1,4 +1,4 @@ -package config +package dynamic import ( "context" diff --git a/pkg/config/runtime_test.go b/pkg/config/dynamic/runtime_test.go similarity index 68% rename from pkg/config/runtime_test.go rename to pkg/config/dynamic/runtime_test.go index 6bb7be89c..4cd1be4e1 100644 --- a/pkg/config/runtime_test.go +++ b/pkg/config/dynamic/runtime_test.go @@ -1,10 +1,10 @@ -package config_test +package dynamic_test 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" ) @@ -13,42 +13,42 @@ import ( func TestPopulateUsedby(t *testing.T) { testCases := []struct { desc string - conf *config.RuntimeConfiguration - expected config.RuntimeConfiguration + conf *dynamic.RuntimeConfiguration + expected dynamic.RuntimeConfiguration }{ { desc: "nil config", conf: nil, - expected: config.RuntimeConfiguration{}, + expected: dynamic.RuntimeConfiguration{}, }, { desc: "One service used by two routers", - conf: &config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + conf: &dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "foo@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`bar.foo`)", }, }, "bar@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar`)", }, }, }, - Services: map[string]*config.ServiceInfo{ + 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:8085"}, {URL: "http://127.0.0.1:8086"}, }, - HealthCheck: &config.HealthCheck{ + HealthCheck: &dynamic.HealthCheck{ Interval: "500ms", Path: "/health", }, @@ -57,12 +57,12 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "foo@myprovider": {}, "bar@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider", "foo@myprovider"}, }, @@ -71,28 +71,28 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "One service used by two routers, but one router with wrong rule", - 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"}, }, }, }, }, }, - Routers: map[string]*config.RouterInfo{ + Routers: map[string]*dynamic.RouterInfo{ "foo@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "WrongRule(`bar.foo`)", }, }, "bar@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar`)", @@ -100,12 +100,12 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "foo@myprovider": {}, "bar@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider", "foo@myprovider"}, }, @@ -114,17 +114,17 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "Broken Service used by one Router", - conf: &config.RuntimeConfiguration{ - Services: map[string]*config.ServiceInfo{ + conf: &dynamic.RuntimeConfiguration{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { - Service: &config.Service{ + Service: &dynamic.Service{ LoadBalancer: nil, }, }, }, - 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`)", @@ -132,11 +132,11 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "bar@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider"}, }, @@ -145,12 +145,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "2 different Services each used by a disctinct router.", - 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:8085", }, @@ -158,7 +158,7 @@ func TestPopulateUsedby(t *testing.T) { URL: "http://127.0.0.1:8086", }, }, - HealthCheck: &config.HealthCheck{ + HealthCheck: &dynamic.HealthCheck{ Interval: "500ms", Path: "/health", }, @@ -166,9 +166,9 @@ func TestPopulateUsedby(t *testing.T) { }, }, "bar-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:8087", }, @@ -176,7 +176,7 @@ func TestPopulateUsedby(t *testing.T) { URL: "http://127.0.0.1:8088", }, }, - HealthCheck: &config.HealthCheck{ + HealthCheck: &dynamic.HealthCheck{ Interval: "500ms", Path: "/health", }, @@ -184,16 +184,16 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - Routers: map[string]*config.RouterInfo{ + Routers: map[string]*dynamic.RouterInfo{ "foo@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`bar.foo`)", }, }, "bar@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "bar-service@myprovider", Rule: "Host(`foo.bar`)", @@ -201,12 +201,12 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "bar@myprovider": {}, "foo@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"foo@myprovider"}, }, @@ -218,12 +218,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "2 middlewares both used by 2 Routers", - 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", }, @@ -232,25 +232,25 @@ func TestPopulateUsedby(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: "/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`)", @@ -258,7 +258,7 @@ func TestPopulateUsedby(t *testing.T) { }, }, "test@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar.other`)", @@ -267,17 +267,17 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "bar@myprovider": {}, "test@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider", "test@myprovider"}, }, }, - Middlewares: map[string]*config.MiddlewareInfo{ + Middlewares: map[string]*dynamic.MiddlewareInfo{ "auth@myprovider": { UsedBy: []string{"bar@myprovider", "test@myprovider"}, }, @@ -289,12 +289,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "Unknown middleware is not used by the Router", - 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", }, @@ -303,18 +303,18 @@ func TestPopulateUsedby(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"}, }, }, }, }, - 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`)", @@ -323,8 +323,8 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Services: map[string]*config.ServiceInfo{ + expected: dynamic.RuntimeConfiguration{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider"}, }, @@ -333,12 +333,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "Broken middleware is used by Router", - 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", }, @@ -347,18 +347,18 @@ func TestPopulateUsedby(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{"badConf"}, }, }, }, }, - 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`)", @@ -367,16 +367,16 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "bar@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider"}, }, }, - Middlewares: map[string]*config.MiddlewareInfo{ + Middlewares: map[string]*dynamic.MiddlewareInfo{ "auth@myprovider": { UsedBy: []string{"bar@myprovider"}, }, @@ -385,12 +385,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "2 middlewares from 2 disctinct providers both used by 2 Routers", - 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", }, @@ -399,32 +399,32 @@ func TestPopulateUsedby(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`)", @@ -432,7 +432,7 @@ func TestPopulateUsedby(t *testing.T) { }, }, "test@myprovider": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar.other`)", @@ -441,17 +441,17 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - Routers: map[string]*config.RouterInfo{ + expected: dynamic.RuntimeConfiguration{ + Routers: map[string]*dynamic.RouterInfo{ "bar@myprovider": {}, "test@myprovider": {}, }, - Services: map[string]*config.ServiceInfo{ + Services: map[string]*dynamic.ServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider", "test@myprovider"}, }, }, - Middlewares: map[string]*config.MiddlewareInfo{ + Middlewares: map[string]*dynamic.MiddlewareInfo{ "auth@myprovider": { UsedBy: []string{"bar@myprovider", "test@myprovider"}, }, @@ -468,28 +468,28 @@ func TestPopulateUsedby(t *testing.T) { // TCP tests from hereon { desc: "TCP, One service used by two routers", - conf: &config.RuntimeConfiguration{ - TCPRouters: map[string]*config.TCPRouterInfo{ + conf: &dynamic.RuntimeConfiguration{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "foo@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`bar.foo`)", }, }, "bar@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar`)", }, }, }, - TCPServices: map[string]*config.TCPServiceInfo{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-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", Port: "8085", @@ -504,12 +504,12 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - TCPRouters: map[string]*config.TCPRouterInfo{ + expected: dynamic.RuntimeConfiguration{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "foo@myprovider": {}, "bar@myprovider": {}, }, - TCPServices: map[string]*config.TCPServiceInfo{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider", "foo@myprovider"}, }, @@ -518,12 +518,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "TCP, One service used by two routers, but one router with wrong rule", - conf: &config.RuntimeConfiguration{ - TCPServices: map[string]*config.TCPServiceInfo{ + conf: &dynamic.RuntimeConfiguration{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-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", }, @@ -532,16 +532,16 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - TCPRouters: map[string]*config.TCPRouterInfo{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "foo@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "WrongRule(`bar.foo`)", }, }, "bar@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar`)", @@ -549,12 +549,12 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - TCPRouters: map[string]*config.TCPRouterInfo{ + expected: dynamic.RuntimeConfiguration{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "foo@myprovider": {}, "bar@myprovider": {}, }, - TCPServices: map[string]*config.TCPServiceInfo{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider", "foo@myprovider"}, }, @@ -563,17 +563,17 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "TCP, Broken Service used by one Router", - conf: &config.RuntimeConfiguration{ - TCPServices: map[string]*config.TCPServiceInfo{ + conf: &dynamic.RuntimeConfiguration{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-service@myprovider": { - TCPService: &config.TCPService{ + TCPService: &dynamic.TCPService{ LoadBalancer: nil, }, }, }, - TCPRouters: map[string]*config.TCPRouterInfo{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "bar@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`foo.bar`)", @@ -581,11 +581,11 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - TCPRouters: map[string]*config.TCPRouterInfo{ + expected: dynamic.RuntimeConfiguration{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "bar@myprovider": {}, }, - TCPServices: map[string]*config.TCPServiceInfo{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"bar@myprovider"}, }, @@ -594,12 +594,12 @@ func TestPopulateUsedby(t *testing.T) { }, { desc: "TCP, 2 different Services each used by a disctinct router.", - conf: &config.RuntimeConfiguration{ - TCPServices: map[string]*config.TCPServiceInfo{ + conf: &dynamic.RuntimeConfiguration{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-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", Port: "8085", @@ -613,9 +613,9 @@ func TestPopulateUsedby(t *testing.T) { }, }, "bar-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", Port: "8087", @@ -629,16 +629,16 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - TCPRouters: map[string]*config.TCPRouterInfo{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "foo@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`bar.foo`)", }, }, "bar@myprovider": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "bar-service@myprovider", Rule: "Host(`foo.bar`)", @@ -646,12 +646,12 @@ func TestPopulateUsedby(t *testing.T) { }, }, }, - expected: config.RuntimeConfiguration{ - TCPRouters: map[string]*config.TCPRouterInfo{ + expected: dynamic.RuntimeConfiguration{ + TCPRouters: map[string]*dynamic.TCPRouterInfo{ "bar@myprovider": {}, "foo@myprovider": {}, }, - TCPServices: map[string]*config.TCPServiceInfo{ + TCPServices: map[string]*dynamic.TCPServiceInfo{ "foo-service@myprovider": { UsedBy: []string{"foo@myprovider"}, }, @@ -693,27 +693,27 @@ func TestPopulateUsedby(t *testing.T) { func TestGetTCPRoutersByEntrypoints(t *testing.T) { testCases := []struct { desc string - conf config.Configuration + conf dynamic.Configuration entryPoints []string - expected map[string]map[string]*config.TCPRouterInfo + expected map[string]map[string]*dynamic.TCPRouterInfo }{ { desc: "Empty Configuration without entrypoint", - conf: config.Configuration{}, + conf: dynamic.Configuration{}, entryPoints: []string{""}, - expected: map[string]map[string]*config.TCPRouterInfo{}, + expected: map[string]map[string]*dynamic.TCPRouterInfo{}, }, { desc: "Empty Configuration with unknown entrypoints", - conf: config.Configuration{}, + conf: dynamic.Configuration{}, entryPoints: []string{"foo"}, - expected: map[string]map[string]*config.TCPRouterInfo{}, + expected: map[string]map[string]*dynamic.TCPRouterInfo{}, }, { desc: "Valid configuration with an unknown entrypoint", - conf: config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + conf: dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -721,8 +721,8 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -732,13 +732,13 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, entryPoints: []string{"foo"}, - expected: map[string]map[string]*config.TCPRouterInfo{}, + expected: map[string]map[string]*dynamic.TCPRouterInfo{}, }, { desc: "Valid configuration with a known entrypoint", - conf: config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + conf: dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -756,8 +756,8 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -777,17 +777,17 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, entryPoints: []string{"web"}, - expected: map[string]map[string]*config.TCPRouterInfo{ + expected: map[string]map[string]*dynamic.TCPRouterInfo{ "web": { "foo": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "HostSNI(`bar.foo`)", }, }, "foobar": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web", "webs"}, Service: "foobar-service@myprovider", Rule: "HostSNI(`bar.foobar`)", @@ -798,9 +798,9 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, { desc: "Valid configuration with multiple known entrypoints", - conf: config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + conf: dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -818,8 +818,8 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -839,17 +839,17 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, entryPoints: []string{"web", "webs"}, - expected: map[string]map[string]*config.TCPRouterInfo{ + expected: map[string]map[string]*dynamic.TCPRouterInfo{ "web": { "foo": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "HostSNI(`bar.foo`)", }, }, "foobar": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web", "webs"}, Service: "foobar-service@myprovider", Rule: "HostSNI(`bar.foobar`)", @@ -858,7 +858,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, "webs": { "bar": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"webs"}, Service: "bar-service@myprovider", @@ -866,7 +866,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { }, }, "foobar": { - TCPRouter: &config.TCPRouter{ + TCPRouter: &dynamic.TCPRouter{ EntryPoints: []string{"web", "webs"}, Service: "foobar-service@myprovider", Rule: "HostSNI(`bar.foobar`)", @@ -881,7 +881,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { test := test t.Run(test.desc, func(t *testing.T) { t.Parallel() - runtimeConfig := config.NewRuntimeConfig(test.conf) + runtimeConfig := dynamic.NewRuntimeConfig(test.conf) actual := runtimeConfig.GetTCPRoutersByEntrypoints(context.Background(), test.entryPoints) assert.Equal(t, test.expected, actual) }) @@ -891,27 +891,27 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) { func TestGetRoutersByEntrypoints(t *testing.T) { testCases := []struct { desc string - conf config.Configuration + conf dynamic.Configuration entryPoints []string - expected map[string]map[string]*config.RouterInfo + expected map[string]map[string]*dynamic.RouterInfo }{ { desc: "Empty Configuration without entrypoint", - conf: config.Configuration{}, + conf: dynamic.Configuration{}, entryPoints: []string{""}, - expected: map[string]map[string]*config.RouterInfo{}, + expected: map[string]map[string]*dynamic.RouterInfo{}, }, { desc: "Empty Configuration with unknown entrypoints", - conf: config.Configuration{}, + conf: dynamic.Configuration{}, entryPoints: []string{"foo"}, - expected: map[string]map[string]*config.RouterInfo{}, + expected: map[string]map[string]*dynamic.RouterInfo{}, }, { desc: "Valid configuration with an unknown entrypoint", - conf: config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + conf: dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -919,8 +919,8 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -930,13 +930,13 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, entryPoints: []string{"foo"}, - expected: map[string]map[string]*config.RouterInfo{}, + expected: map[string]map[string]*dynamic.RouterInfo{}, }, { desc: "Valid configuration with a known entrypoint", - conf: config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + conf: dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -954,8 +954,8 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -975,17 +975,17 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, entryPoints: []string{"web"}, - expected: map[string]map[string]*config.RouterInfo{ + expected: map[string]map[string]*dynamic.RouterInfo{ "web": { "foo": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`bar.foo`)", }, }, "foobar": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web", "webs"}, Service: "foobar-service@myprovider", Rule: "Host(`bar.foobar`)", @@ -996,9 +996,9 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, { desc: "Valid configuration with multiple known entrypoints", - conf: config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + conf: dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -1016,8 +1016,8 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { EntryPoints: []string{"web"}, Service: "foo-service@myprovider", @@ -1037,17 +1037,17 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, entryPoints: []string{"web", "webs"}, - expected: map[string]map[string]*config.RouterInfo{ + expected: map[string]map[string]*dynamic.RouterInfo{ "web": { "foo": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web"}, Service: "foo-service@myprovider", Rule: "Host(`bar.foo`)", }, }, "foobar": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web", "webs"}, Service: "foobar-service@myprovider", Rule: "Host(`bar.foobar`)", @@ -1056,7 +1056,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, "webs": { "bar": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"webs"}, Service: "bar-service@myprovider", @@ -1064,7 +1064,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) { }, }, "foobar": { - Router: &config.Router{ + Router: &dynamic.Router{ EntryPoints: []string{"web", "webs"}, Service: "foobar-service@myprovider", Rule: "Host(`bar.foobar`)", @@ -1079,7 +1079,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) { test := test t.Run(test.desc, func(t *testing.T) { t.Parallel() - runtimeConfig := config.NewRuntimeConfig(test.conf) + runtimeConfig := dynamic.NewRuntimeConfig(test.conf) actual := runtimeConfig.GetRoutersByEntrypoints(context.Background(), test.entryPoints, false) assert.Equal(t, test.expected, actual) }) diff --git a/pkg/config/dynamic/tcp_config.go b/pkg/config/dynamic/tcp_config.go new file mode 100644 index 000000000..be2ca9b1b --- /dev/null +++ b/pkg/config/dynamic/tcp_config.go @@ -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:"-"` +} diff --git a/pkg/config/zz_generated.deepcopy.go b/pkg/config/dynamic/zz_generated.deepcopy.go similarity index 99% rename from pkg/config/zz_generated.deepcopy.go rename to pkg/config/dynamic/zz_generated.deepcopy.go index 2b037b221..9671e61db 100644 --- a/pkg/config/zz_generated.deepcopy.go +++ b/pkg/config/dynamic/zz_generated.deepcopy.go @@ -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" diff --git a/pkg/config/label/label.go b/pkg/config/label/label.go index 6b5478dee..09fdfac4e 100644 --- a/pkg/config/label/label.go +++ b/pkg/config/label/label.go @@ -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) } diff --git a/pkg/config/label/label_test.go b/pkg/config/label/label_test.go index 88672cdc5..76550ad08 100644 --- a/pkg/config/label/label_test.go +++ b/pkg/config/label/label_test.go @@ -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", }, }, diff --git a/pkg/healthcheck/healthcheck.go b/pkg/healthcheck/healthcheck.go index 11ccfab6f..f36a2b039 100644 --- a/pkg/healthcheck/healthcheck.go +++ b/pkg/healthcheck/healthcheck.go @@ -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, diff --git a/pkg/healthcheck/healthcheck_test.go b/pkg/healthcheck/healthcheck_test.go index e60126b8c..9dc9ef406 100644 --- a/pkg/healthcheck/healthcheck_test.go +++ b/pkg/healthcheck/healthcheck_test.go @@ -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) diff --git a/pkg/metrics/prometheus.go b/pkg/metrics/prometheus.go index fea31b8d1..e70b7d54e 100644 --- a/pkg/metrics/prometheus.go +++ b/pkg/metrics/prometheus.go @@ -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 diff --git a/pkg/metrics/prometheus_test.go b/pkg/metrics/prometheus_test.go index fc32fc7a8..73f9b427d 100644 --- a/pkg/metrics/prometheus_test.go +++ b/pkg/metrics/prometheus_test.go @@ -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", diff --git a/pkg/middlewares/addprefix/add_prefix.go b/pkg/middlewares/addprefix/add_prefix.go index a4883cc1b..c2d44c086 100644 --- a/pkg/middlewares/addprefix/add_prefix.go +++ b/pkg/middlewares/addprefix/add_prefix.go @@ -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 diff --git a/pkg/middlewares/addprefix/add_prefix_test.go b/pkg/middlewares/addprefix/add_prefix_test.go index 0f10e7cf1..01d1c16d1 100644 --- a/pkg/middlewares/addprefix/add_prefix_test.go +++ b/pkg/middlewares/addprefix/add_prefix_test.go @@ -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", diff --git a/pkg/middlewares/auth/basic_auth.go b/pkg/middlewares/auth/basic_auth.go index 79179bd15..62ec3773e 100644 --- a/pkg/middlewares/auth/basic_auth.go +++ b/pkg/middlewares/auth/basic_auth.go @@ -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 { diff --git a/pkg/middlewares/auth/basic_auth_test.go b/pkg/middlewares/auth/basic_auth_test.go index 587197a46..103fd7771 100644 --- a/pkg/middlewares/auth/basic_auth_test.go +++ b/pkg/middlewares/auth/basic_auth_test.go @@ -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, diff --git a/pkg/middlewares/auth/digest_auth.go b/pkg/middlewares/auth/digest_auth.go index beca09db6..3611b2cd5 100644 --- a/pkg/middlewares/auth/digest_auth.go +++ b/pkg/middlewares/auth/digest_auth.go @@ -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 { diff --git a/pkg/middlewares/auth/digest_auth_test.go b/pkg/middlewares/auth/digest_auth_test.go index 0210232ea..7fc16e1f1 100644 --- a/pkg/middlewares/auth/digest_auth_test.go +++ b/pkg/middlewares/auth/digest_auth_test.go @@ -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, diff --git a/pkg/middlewares/auth/forward.go b/pkg/middlewares/auth/forward.go index ce2fd5736..7e074b29f 100644 --- a/pkg/middlewares/auth/forward.go +++ b/pkg/middlewares/auth/forward.go @@ -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{ diff --git a/pkg/middlewares/auth/forward_test.go b/pkg/middlewares/auth/forward_test.go index cd3089eef..9b698186d 100644 --- a/pkg/middlewares/auth/forward_test.go +++ b/pkg/middlewares/auth/forward_test.go @@ -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") diff --git a/pkg/middlewares/buffering/buffering.go b/pkg/middlewares/buffering/buffering.go index 5c00d839c..d247b2de2 100644 --- a/pkg/middlewares/buffering/buffering.go +++ b/pkg/middlewares/buffering/buffering.go @@ -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'", diff --git a/pkg/middlewares/chain/chain.go b/pkg/middlewares/chain/chain.go index 1b25cd833..914766a9d 100644 --- a/pkg/middlewares/chain/chain.go +++ b/pkg/middlewares/chain/chain.go @@ -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) diff --git a/pkg/middlewares/circuitbreaker/circuit_breaker.go b/pkg/middlewares/circuitbreaker/circuit_breaker.go index 6dbafff94..cb57b8894 100644 --- a/pkg/middlewares/circuitbreaker/circuit_breaker.go +++ b/pkg/middlewares/circuitbreaker/circuit_breaker.go @@ -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) diff --git a/pkg/middlewares/customerrors/custom_errors.go b/pkg/middlewares/customerrors/custom_errors.go index c86ee3416..77a552c2f 100644 --- a/pkg/middlewares/customerrors/custom_errors.go +++ b/pkg/middlewares/customerrors/custom_errors.go @@ -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) diff --git a/pkg/middlewares/customerrors/custom_errors_test.go b/pkg/middlewares/customerrors/custom_errors_test.go index 27c33d98b..cf7d577b9 100644 --- a/pkg/middlewares/customerrors/custom_errors_test.go +++ b/pkg/middlewares/customerrors/custom_errors_test.go @@ -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" { diff --git a/pkg/middlewares/headers/headers.go b/pkg/middlewares/headers/headers.go index 547fb7ef8..526bc8b8e 100644 --- a/pkg/middlewares/headers/headers.go +++ b/pkg/middlewares/headers/headers.go @@ -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, diff --git a/pkg/middlewares/headers/headers_test.go b/pkg/middlewares/headers/headers_test.go index 5c50452ce..6f637a6c0 100644 --- a/pkg/middlewares/headers/headers_test.go +++ b/pkg/middlewares/headers/headers_test.go @@ -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": "", diff --git a/pkg/middlewares/ipwhitelist/ip_whitelist.go b/pkg/middlewares/ipwhitelist/ip_whitelist.go index c144e9ca7..659800c51 100644 --- a/pkg/middlewares/ipwhitelist/ip_whitelist.go +++ b/pkg/middlewares/ipwhitelist/ip_whitelist.go @@ -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") diff --git a/pkg/middlewares/ipwhitelist/ip_whitelist_test.go b/pkg/middlewares/ipwhitelist/ip_whitelist_test.go index 6b3cea987..5200dea54 100644 --- a/pkg/middlewares/ipwhitelist/ip_whitelist_test.go +++ b/pkg/middlewares/ipwhitelist/ip_whitelist_test.go @@ -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", diff --git a/pkg/middlewares/maxconnection/max_connection.go b/pkg/middlewares/maxconnection/max_connection.go index 352b6e696..e81c3089b 100644 --- a/pkg/middlewares/maxconnection/max_connection.go +++ b/pkg/middlewares/maxconnection/max_connection.go @@ -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) diff --git a/pkg/middlewares/passtlsclientcert/pass_tls_client_cert.go b/pkg/middlewares/passtlsclientcert/pass_tls_client_cert.go index e730440ab..9512854ef 100644 --- a/pkg/middlewares/passtlsclientcert/pass_tls_client_cert.go +++ b/pkg/middlewares/passtlsclientcert/pass_tls_client_cert.go @@ -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 } diff --git a/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go b/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go index 694362f99..a2c6cd967 100644 --- a/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go +++ b/pkg/middlewares/passtlsclientcert/pass_tls_client_cert_test.go @@ -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, diff --git a/pkg/middlewares/ratelimiter/rate_limiter.go b/pkg/middlewares/ratelimiter/rate_limiter.go index 76c4f3d51..4f9e53865 100644 --- a/pkg/middlewares/ratelimiter/rate_limiter.go +++ b/pkg/middlewares/ratelimiter/rate_limiter.go @@ -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) diff --git a/pkg/middlewares/redirect/redirect_regex.go b/pkg/middlewares/redirect/redirect_regex.go index 1b5d3033a..1028e2403 100644 --- a/pkg/middlewares/redirect/redirect_regex.go +++ b/pkg/middlewares/redirect/redirect_regex.go @@ -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) diff --git a/pkg/middlewares/redirect/redirect_regex_test.go b/pkg/middlewares/redirect/redirect_regex_test.go index 3e48e6ff2..774f31b6d 100644 --- a/pkg/middlewares/redirect/redirect_regex_test.go +++ b/pkg/middlewares/redirect/redirect_regex_test.go @@ -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, diff --git a/pkg/middlewares/redirect/redirect_scheme.go b/pkg/middlewares/redirect/redirect_scheme.go index 55e2553a6..f95679eab 100644 --- a/pkg/middlewares/redirect/redirect_scheme.go +++ b/pkg/middlewares/redirect/redirect_scheme.go @@ -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) diff --git a/pkg/middlewares/redirect/redirect_scheme_test.go b/pkg/middlewares/redirect/redirect_scheme_test.go index 99205ef40..3e5072aa3 100644 --- a/pkg/middlewares/redirect/redirect_scheme_test.go +++ b/pkg/middlewares/redirect/redirect_scheme_test.go @@ -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", diff --git a/pkg/middlewares/replacepath/replace_path.go b/pkg/middlewares/replacepath/replace_path.go index 4e46a7a76..9706c425c 100644 --- a/pkg/middlewares/replacepath/replace_path.go +++ b/pkg/middlewares/replacepath/replace_path.go @@ -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{ diff --git a/pkg/middlewares/replacepath/replace_path_test.go b/pkg/middlewares/replacepath/replace_path_test.go index 102d0aa81..16d07442b 100644 --- a/pkg/middlewares/replacepath/replace_path_test.go +++ b/pkg/middlewares/replacepath/replace_path_test.go @@ -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", } diff --git a/pkg/middlewares/replacepathregex/replace_path_regex.go b/pkg/middlewares/replacepathregex/replace_path_regex.go index a3ca0b519..0421cc06f 100644 --- a/pkg/middlewares/replacepathregex/replace_path_regex.go +++ b/pkg/middlewares/replacepathregex/replace_path_regex.go @@ -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)) diff --git a/pkg/middlewares/replacepathregex/replace_path_regex_test.go b/pkg/middlewares/replacepathregex/replace_path_regex_test.go index 67ab607e8..fe73c6199 100644 --- a/pkg/middlewares/replacepathregex/replace_path_regex_test.go +++ b/pkg/middlewares/replacepathregex/replace_path_regex_test.go @@ -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/([^/]+)$`, }, diff --git a/pkg/middlewares/retry/retry.go b/pkg/middlewares/retry/retry.go index da4c28e5a..3658e69f0 100644 --- a/pkg/middlewares/retry/retry.go +++ b/pkg/middlewares/retry/retry.go @@ -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") diff --git a/pkg/middlewares/retry/retry_test.go b/pkg/middlewares/retry/retry_test.go index 10eb3f725..9df97011b 100644 --- a/pkg/middlewares/retry/retry_test.go +++ b/pkg/middlewares/retry/retry_test.go @@ -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) diff --git a/pkg/middlewares/stripprefix/strip_prefix.go b/pkg/middlewares/stripprefix/strip_prefix.go index 504f20fa3..94c8de90e 100644 --- a/pkg/middlewares/stripprefix/strip_prefix.go +++ b/pkg/middlewares/stripprefix/strip_prefix.go @@ -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, diff --git a/pkg/middlewares/stripprefix/strip_prefix_test.go b/pkg/middlewares/stripprefix/strip_prefix_test.go index 73690ce40..e1aed92cb 100644 --- a/pkg/middlewares/stripprefix/strip_prefix_test.go +++ b/pkg/middlewares/stripprefix/strip_prefix_test.go @@ -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", diff --git a/pkg/middlewares/stripprefixregex/strip_prefix_regex.go b/pkg/middlewares/stripprefixregex/strip_prefix_regex.go index 574092141..6af3bb090 100644 --- a/pkg/middlewares/stripprefixregex/strip_prefix_regex.go +++ b/pkg/middlewares/stripprefixregex/strip_prefix_regex.go @@ -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{ diff --git a/pkg/middlewares/stripprefixregex/strip_prefix_regex_test.go b/pkg/middlewares/stripprefixregex/strip_prefix_regex_test.go index d8a5ca0aa..01ba9224e 100644 --- a/pkg/middlewares/stripprefixregex/strip_prefix_regex_test.go +++ b/pkg/middlewares/stripprefixregex/strip_prefix_regex_test.go @@ -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]+}/"}, } diff --git a/pkg/provider/acme/provider.go b/pkg/provider/acme/provider.go index 75b6ff03b..9d6130481 100644 --- a/pkg/provider/acme/provider.go +++ b/pkg/provider/acme/provider.go @@ -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{}, }, } diff --git a/pkg/provider/aggregator/aggregator.go b/pkg/provider/aggregator/aggregator.go index d7053cd5d..403dc1416 100644 --- a/pkg/provider/aggregator/aggregator.go +++ b/pkg/provider/aggregator/aggregator.go @@ -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) diff --git a/pkg/provider/configuration.go b/pkg/provider/configuration.go index b80781aca..882a58255 100644 --- a/pkg/provider/configuration.go +++ b/pkg/provider/configuration.go @@ -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{} } } diff --git a/pkg/provider/docker/config.go b/pkg/provider/docker/config.go index ac179b096..d8474e60d 100644 --- a/pkg/provider/docker/config.go +++ b/pkg/provider/docker/config.go @@ -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 } diff --git a/pkg/provider/docker/config_test.go b/pkg/provider/docker/config_test.go index f7b8d94fb..107e9c4c6 100644 --- a/pkg/provider/docker/config_test.go +++ b/pkg/provider/docker/config_test.go @@ -5,7 +5,7 @@ import ( "strconv" "testing" - "github.com/containous/traefik/pkg/config" + "github.com/containous/traefik/pkg/config/dynamic" docker "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/go-connections/nat" @@ -18,7 +18,7 @@ func TestDefaultRule(t *testing.T) { desc string containers []dockerData defaultRule string - expected *config.Configuration + expected *dynamic.Configuration }{ { desc: "default rule with no variable", @@ -41,23 +41,23 @@ func TestDefaultRule(t *testing.T) { }, }, defaultRule: "Host(`foo.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{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "Test": { Service: "Test", Rule: "Host(`foo.bar`)", }, }, - 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", }, @@ -90,23 +90,23 @@ func TestDefaultRule(t *testing.T) { }, }, defaultRule: "Host(`{{ .Name }}.foo.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{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "Test": { Service: "Test", Rule: "Host(`Test.foo.bar`)", }, }, - 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", }, @@ -141,23 +141,23 @@ func TestDefaultRule(t *testing.T) { }, }, defaultRule: `Host("{{ .Name }}.{{ index .Labels "traefik.domain" }}")`, - 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.foo.bar")`, }, }, - 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", }, @@ -190,18 +190,18 @@ func TestDefaultRule(t *testing.T) { }, }, defaultRule: `Host("{{ .Toto }}")`, - 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{ "Test": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -234,18 +234,18 @@ func TestDefaultRule(t *testing.T) { }, }, defaultRule: ``, - 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{ "Test": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -278,23 +278,23 @@ func TestDefaultRule(t *testing.T) { }, }, defaultRule: DefaultTemplateRule, - 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`)", }, }, - 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", }, @@ -339,7 +339,7 @@ func Test_buildConfiguration(t *testing.T) { desc string containers []dockerData constraints string - expected *config.Configuration + expected *dynamic.Configuration }{ { desc: "one container no label", @@ -361,23 +361,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -425,13 +425,13 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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`)", @@ -441,11 +441,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{ "Test": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -454,8 +454,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", }, @@ -505,23 +505,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -558,23 +558,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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: "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", }, @@ -610,23 +610,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -660,17 +660,17 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + HTTP: &dynamic.HTTPConfiguration{ + 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", }, @@ -679,7 +679,7 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - Routers: map[string]*config.Router{ + Routers: map[string]*dynamic.Router{ "Router1": { Service: "Test", Rule: "Host(`foo.com`)", @@ -711,23 +711,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -763,18 +763,18 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ "Service1": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -783,8 +783,8 @@ func Test_buildConfiguration(t *testing.T) { }, }, "Service2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -838,20 +838,20 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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: "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{}, }, }, }, @@ -916,20 +916,20 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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: "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{}, }, }, }, @@ -975,23 +975,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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: "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", }, @@ -1028,22 +1028,22 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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`)", }, }, - 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", }, @@ -1052,9 +1052,9 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - Middlewares: map[string]*config.Middleware{ + Middlewares: map[string]*dynamic.Middleware{ "Middleware1": { - MaxConn: &config.MaxConn{ + MaxConn: &dynamic.MaxConn{ Amount: 42, ExtractorFunc: "request.host", }, @@ -1105,30 +1105,30 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ + Middlewares: map[string]*dynamic.Middleware{ "Middleware1": { - MaxConn: &config.MaxConn{ + MaxConn: &dynamic.MaxConn{ Amount: 42, ExtractorFunc: "request.host", }, }, }, - 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", }, @@ -1185,23 +1185,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -1277,23 +1277,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -1353,18 +1353,18 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ "Test": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -1440,18 +1440,18 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ "Test": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -1511,23 +1511,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -1582,18 +1582,18 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ "Test": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -1602,8 +1602,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", }, @@ -1637,23 +1637,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -1688,23 +1688,23 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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: "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: "h2c://127.0.0.1:8080", }, @@ -1739,18 +1739,18 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ "Service1": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:80", }, @@ -1759,8 +1759,8 @@ func Test_buildConfiguration(t *testing.T) { }, }, "Service2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://127.0.0.1:8080", }, @@ -1790,15 +1790,15 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{}, }, }, }, @@ -1822,15 +1822,15 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{}, }, }, }, @@ -1856,15 +1856,15 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{}, }, }, }, @@ -1889,15 +1889,15 @@ func Test_buildConfiguration(t *testing.T) { Health: "not_healthy", }, }, - 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{}, }, }, }, @@ -1924,15 +1924,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{}, }, }, }, @@ -1959,23 +1959,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", }, @@ -2010,22 +2010,22 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", @@ -2033,10 +2033,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", }, @@ -2071,19 +2071,19 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -2092,10 +2092,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{}, }, }, }, @@ -2121,13 +2121,13 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -2136,10 +2136,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{}, }, }, }, @@ -2167,21 +2167,21 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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{ Options: "foo", }, }, }, - 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", }, @@ -2190,10 +2190,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{}, }, }, }, @@ -2244,19 +2244,19 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -2268,18 +2268,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", }, @@ -2316,13 +2316,13 @@ func Test_buildConfiguration(t *testing.T) { }, }, }, - 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", }, @@ -2331,10 +2331,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{}, }, }, }, diff --git a/pkg/provider/docker/docker.go b/pkg/provider/docker/docker.go index 7eaa48818..dc7dff779 100644 --- a/pkg/provider/docker/docker.go +++ b/pkg/provider/docker/docker.go @@ -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, } diff --git a/pkg/provider/file/file.go b/pkg/provider/file/file.go index b7a485342..c89bc0be0 100644 --- a/pkg/provider/file/file.go +++ b/pkg/provider/file/file.go @@ -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), }, diff --git a/pkg/provider/file/file_test.go b/pkg/provider/file/file_test.go index 019e74036..3907b6e9e 100644 --- a/pkg/provider/file/file_test.go +++ b/pkg/provider/file/file_test.go @@ -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())) diff --git a/pkg/provider/kubernetes/crd/kubernetes.go b/pkg/provider/kubernetes/crd/kubernetes.go index 94144a8b8..9de6cdf9c 100644 --- a/pkg/provider/kubernetes/crd/kubernetes.go +++ b/pkg/provider/kubernetes/crd/kubernetes.go @@ -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), }, diff --git a/pkg/provider/kubernetes/crd/kubernetes_test.go b/pkg/provider/kubernetes/crd/kubernetes_test.go index c88ffcb0d..9ece08d30 100644 --- a/pkg/provider/kubernetes/crd/kubernetes_test.go +++ b/pkg/provider/kubernetes/crd/kubernetes_test.go @@ -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/provider" "github.com/containous/traefik/pkg/tls" "github.com/stretchr/testify/assert" @@ -17,44 +17,44 @@ func TestLoadIngressRouteTCPs(t *testing.T) { desc string ingressClass string paths []string - expected *config.Configuration + expected *dynamic.Configuration }{ { desc: "Empty", - 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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "Simple Ingress Route, with foo entrypoint", paths: []string{"tcp/services.yml", "tcp/simple.yml"}, - expected: &config.Configuration{ - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{}, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{}, + expected: &dynamic.Configuration{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{}, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{}, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -68,15 +68,15 @@ func TestLoadIngressRouteTCPs(t *testing.T) { }, }, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "One ingress Route with two different rules", paths: []string{"tcp/services.yml", "tcp/with_two_rules.yml"}, - expected: &config.Configuration{ - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", @@ -88,10 +88,10 @@ func TestLoadIngressRouteTCPs(t *testing.T) { Rule: "HostSNI(`bar.com`)", }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -104,8 +104,8 @@ func TestLoadIngressRouteTCPs(t *testing.T) { }, }, "default/test.route-f44ce589164e656d231c": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -119,30 +119,30 @@ func TestLoadIngressRouteTCPs(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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "One ingress Route with two different services, their servers will merge", paths: []string{"tcp/services.yml", "tcp/with_two_services.yml"}, - expected: &config.Configuration{ - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -163,68 +163,68 @@ func TestLoadIngressRouteTCPs(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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "Ingress class does not match", paths: []string{"tcp/services.yml", "tcp/simple.yml"}, ingressClass: "tchouk", - 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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "Route with empty rule value is ignored", paths: []string{"tcp/services.yml", "tcp/with_no_rule_value.yml"}, - 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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "check rule quoting validity", paths: []string{"tcp/services.yml", "tcp/with_bad_host_rule.yml"}, - 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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "TLS", paths: []string{"tcp/services.yml", "tcp/with_tls.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Certificates: []*tls.CertAndStores{ { Certificate: tls.Certificate{ @@ -234,19 +234,19 @@ func TestLoadIngressRouteTCPs(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{}, + TLS: &dynamic.RouterTCPTLSConfig{}, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -260,32 +260,32 @@ func TestLoadIngressRouteTCPs(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{}, }, }, }, { desc: "TLS with passthrough", paths: []string{"tcp/services.yml", "tcp/with_tls_passthrough.yml"}, - expected: &config.Configuration{ - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{ + TLS: &dynamic.RouterTCPTLSConfig{ Passthrough: true, }, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -299,19 +299,19 @@ func TestLoadIngressRouteTCPs(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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "TLS with tls options", paths: []string{"tcp/services.yml", "tcp/with_tls_options.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", @@ -330,21 +330,21 @@ func TestLoadIngressRouteTCPs(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{ + TLS: &dynamic.RouterTCPTLSConfig{ Options: "default/foo", }, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -358,18 +358,18 @@ func TestLoadIngressRouteTCPs(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{}, }, }, }, { desc: "TLS with tls options and specific namespace", paths: []string{"tcp/services.yml", "tcp/with_tls_options_and_specific_namespace.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "myns/foo": { MinVersion: "VersionTLS12", @@ -388,21 +388,21 @@ func TestLoadIngressRouteTCPs(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{ + TLS: &dynamic.RouterTCPTLSConfig{ Options: "myns/foo", }, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -416,18 +416,18 @@ func TestLoadIngressRouteTCPs(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{}, }, }, }, { desc: "TLS with bad tls options", paths: []string{"tcp/services.yml", "tcp/with_bad_tls_options.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", @@ -445,21 +445,21 @@ func TestLoadIngressRouteTCPs(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{ + TLS: &dynamic.RouterTCPTLSConfig{ Options: "default/foo", }, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -473,39 +473,39 @@ func TestLoadIngressRouteTCPs(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{}, }, }, }, { desc: "TLS with unknown tls options", paths: []string{"tcp/services.yml", "tcp/with_unknown_tls_options.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{ + TLS: &dynamic.RouterTCPTLSConfig{ Options: "default/unknown", }, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -519,39 +519,39 @@ func TestLoadIngressRouteTCPs(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{}, }, }, }, { desc: "TLS with unknown tls options namespace", paths: []string{"tcp/services.yml", "tcp/with_unknown_tls_options_namespace.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{ + TLS: &dynamic.RouterTCPTLSConfig{ Options: "unknown/foo", }, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -565,30 +565,30 @@ func TestLoadIngressRouteTCPs(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{}, }, }, }, { desc: "TLS with ACME", paths: []string{"tcp/services.yml", "tcp/with_tls_acme.yml"}, - expected: &config.Configuration{ - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "default/test.route-fdd3e9338e47a45efefc": { EntryPoints: []string{"foo"}, Service: "default/test.route-fdd3e9338e47a45efefc", Rule: "HostSNI(`foo.com`)", - TLS: &config.RouterTCPTLSConfig{}, + TLS: &dynamic.RouterTCPTLSConfig{}, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "default/test.route-fdd3e9338e47a45efefc": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "10.10.0.1:8000", Port: "", @@ -602,12 +602,12 @@ func TestLoadIngressRouteTCPs(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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, } @@ -634,33 +634,33 @@ func TestLoadIngressRoutes(t *testing.T) { desc string ingressClass string paths []string - expected *config.Configuration + expected *dynamic.Configuration }{ { desc: "Empty", - 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{}, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "Simple Ingress Route, with foo entrypoint", paths: []string{"services.yml", "simple.yml"}, - 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"foo"}, Service: "default/test.route-6b204d94623b3df4370c", @@ -668,11 +668,11 @@ func TestLoadIngressRoutes(t *testing.T) { Priority: 12, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -685,19 +685,19 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "Simple Ingress Route with middleware", paths: []string{"services.yml", "with_middleware.yml"}, - 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{ "default/test2.route-23c7f4c450289ee29016": { EntryPoints: []string{"web"}, Service: "default/test2.route-23c7f4c450289ee29016", @@ -706,22 +706,22 @@ func TestLoadIngressRoutes(t *testing.T) { Middlewares: []string{"default/stripprefix", "foo/addprefix"}, }, }, - Middlewares: map[string]*config.Middleware{ + Middlewares: map[string]*dynamic.Middleware{ "default/stripprefix": { - StripPrefix: &config.StripPrefix{ + StripPrefix: &dynamic.StripPrefix{ Prefixes: []string{"/tobestripped"}, }, }, "foo/addprefix": { - AddPrefix: &config.AddPrefix{ + AddPrefix: &dynamic.AddPrefix{ Prefix: "/tobeadded", }, }, }, - Services: map[string]*config.Service{ + Services: map[string]*dynamic.Service{ "default/test2.route-23c7f4c450289ee29016": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -734,20 +734,20 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "Simple Ingress Route with middleware crossprovider", paths: []string{"services.yml", "with_middleware_crossprovider.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{ "default/test2.route-23c7f4c450289ee29016": { EntryPoints: []string{"web"}, Service: "default/test2.route-23c7f4c450289ee29016", @@ -756,22 +756,22 @@ func TestLoadIngressRoutes(t *testing.T) { Middlewares: []string{"default/stripprefix", "foo/addprefix", "basicauth@file", "redirect@file"}, }, }, - Middlewares: map[string]*config.Middleware{ + Middlewares: map[string]*dynamic.Middleware{ "default/stripprefix": { - StripPrefix: &config.StripPrefix{ + StripPrefix: &dynamic.StripPrefix{ Prefixes: []string{"/tobestripped"}, }, }, "foo/addprefix": { - AddPrefix: &config.AddPrefix{ + AddPrefix: &dynamic.AddPrefix{ Prefix: "/tobeadded", }, }, }, - Services: map[string]*config.Service{ + Services: map[string]*dynamic.Service{ "default/test2.route-23c7f4c450289ee29016": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -789,13 +789,13 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "One ingress Route with two different rules", paths: []string{"services.yml", "with_two_rules.yml"}, - 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", @@ -809,11 +809,11 @@ func TestLoadIngressRoutes(t *testing.T) { Priority: 12, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -825,8 +825,8 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, "default/test.route-77c62dfe9517144aeeaa": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -839,20 +839,20 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TLS: &config.TLSConfiguration{}, + TLS: &dynamic.TLSConfiguration{}, }, }, { desc: "One ingress Route with two different services, their servers will merge", paths: []string{"services.yml", "with_two_services.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{ "default/test.route-77c62dfe9517144aeeaa": { EntryPoints: []string{"web"}, Service: "default/test.route-77c62dfe9517144aeeaa", @@ -860,11 +860,11 @@ func TestLoadIngressRoutes(t *testing.T) { Priority: 12, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-77c62dfe9517144aeeaa": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -889,72 +889,72 @@ func TestLoadIngressRoutes(t *testing.T) { desc: "Ingress class", paths: []string{"services.yml", "simple.yml"}, ingressClass: "tchouk", - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{}, }, }, }, { desc: "Route with empty rule value is ignored", paths: []string{"services.yml", "with_no_rule_value.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{}, }, }, }, { desc: "Route with kind not of a rule type (empty kind) is ignored", paths: []string{"services.yml", "with_wrong_rule_kind.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{}, }, }, }, { desc: "check rule quoting validity", paths: []string{"services.yml", "with_bad_host_rule.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{}, }, }, }, { desc: "TLS", paths: []string{"services.yml", "with_tls.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Certificates: []*tls.CertAndStores{ { Certificate: tls.Certificate{ @@ -964,25 +964,25 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{}, + TLS: &dynamic.RouterTLSConfig{}, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1000,8 +1000,8 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "TLS with tls options", paths: []string{"services.yml", "with_tls_options.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", @@ -1020,27 +1020,27 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{ + TLS: &dynamic.RouterTLSConfig{ Options: "default/foo", }, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1058,8 +1058,8 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "TLS with tls options and specific namespace", paths: []string{"services.yml", "with_tls_options_and_specific_namespace.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "myns/foo": { MinVersion: "VersionTLS12", @@ -1078,27 +1078,27 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{ + TLS: &dynamic.RouterTLSConfig{ Options: "myns/foo", }, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1116,8 +1116,8 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "TLS with bad tls options", paths: []string{"services.yml", "with_bad_tls_options.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", @@ -1135,27 +1135,27 @@ func TestLoadIngressRoutes(t *testing.T) { }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{ + TLS: &dynamic.RouterTLSConfig{ Options: "default/foo", }, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1173,35 +1173,35 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "TLS with unknown tls options", paths: []string{"services.yml", "with_unknown_tls_options.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{ + TLS: &dynamic.RouterTLSConfig{ Options: "default/unknown", }, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1219,35 +1219,35 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "TLS with unknown tls options namespace", paths: []string{"services.yml", "with_unknown_tls_options_namespace.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{ + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{ Options: map[string]tls.Options{ "default/foo": { MinVersion: "VersionTLS12", }, }, }, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{ + TLS: &dynamic.RouterTLSConfig{ Options: "unknown/foo", }, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1265,27 +1265,27 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "TLS with ACME", paths: []string{"services.yml", "with_tls_acme.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"web"}, Service: "default/test.route-6b204d94623b3df4370c", Rule: "Host(`foo.com`) && PathPrefix(`/bar`)", Priority: 12, - TLS: &config.RouterTLSConfig{}, + TLS: &dynamic.RouterTLSConfig{}, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://10.10.0.1:80", }, @@ -1303,14 +1303,14 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "Simple Ingress Route, defaulting to https for servers", paths: []string{"services.yml", "with_https_default.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"foo"}, Service: "default/test.route-6b204d94623b3df4370c", @@ -1318,11 +1318,11 @@ func TestLoadIngressRoutes(t *testing.T) { Priority: 12, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "https://10.10.0.5:443", }, @@ -1340,14 +1340,14 @@ func TestLoadIngressRoutes(t *testing.T) { { desc: "Simple Ingress Route, explicit https scheme", paths: []string{"services.yml", "with_https_scheme.yml"}, - expected: &config.Configuration{ - TLS: &config.TLSConfiguration{}, - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{}, - Services: map[string]*config.TCPService{}, + expected: &dynamic.Configuration{ + TLS: &dynamic.TLSConfiguration{}, + 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{ "default/test.route-6b204d94623b3df4370c": { EntryPoints: []string{"foo"}, Service: "default/test.route-6b204d94623b3df4370c", @@ -1355,11 +1355,11 @@ func TestLoadIngressRoutes(t *testing.T) { Priority: 12, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "default/test.route-6b204d94623b3df4370c": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "https://10.10.0.7:8443", }, diff --git a/pkg/provider/kubernetes/crd/traefik/v1alpha1/middleware.go b/pkg/provider/kubernetes/crd/traefik/v1alpha1/middleware.go index 5cb9c8eb6..eeb4b9d06 100644 --- a/pkg/provider/kubernetes/crd/traefik/v1alpha1/middleware.go +++ b/pkg/provider/kubernetes/crd/traefik/v1alpha1/middleware.go @@ -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 diff --git a/pkg/provider/kubernetes/ingress/kubernetes.go b/pkg/provider/kubernetes/ingress/kubernetes.go index 16bfc30d1..6be714a28 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes.go +++ b/pkg/provider/kubernetes/ingress/kubernetes.go @@ -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, } } diff --git a/pkg/provider/kubernetes/ingress/kubernetes_test.go b/pkg/provider/kubernetes/ingress/kubernetes_test.go index ffb0e273f..c9d434e2c 100644 --- a/pkg/provider/kubernetes/ingress/kubernetes_test.go +++ b/pkg/provider/kubernetes/ingress/kubernetes_test.go @@ -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{}, }, }, }, diff --git a/pkg/provider/marathon/config.go b/pkg/provider/marathon/config.go index 1624390af..43ce3016d 100644 --- a/pkg/provider/marathon/config.go +++ b/pkg/provider/marathon/config.go @@ -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)), } diff --git a/pkg/provider/marathon/config_test.go b/pkg/provider/marathon/config_test.go index 34adeaf4c..83ce1e89a 100644 --- a/pkg/provider/marathon/config_test.go +++ b/pkg/provider/marathon/config_test.go @@ -5,7 +5,7 @@ import ( "math" "testing" - "github.com/containous/traefik/pkg/config" + "github.com/containous/traefik/pkg/config/dynamic" "github.com/gambol99/go-marathon" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -32,7 +32,7 @@ func TestBuildConfiguration(t *testing.T) { applications *marathon.Applications constraints string defaultRule string - expected *config.Configuration + expected *dynamic.Configuration }{ { desc: "simple application", @@ -42,22 +42,22 @@ func TestBuildConfiguration(t *testing.T) { appPorts(80), withTasks(localhostTask(taskPorts(80))), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ - "app": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "app": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -76,15 +76,15 @@ func TestBuildConfiguration(t *testing.T) { appPorts(80), withTasks(localhostTask(taskPorts(80), taskState(taskStateStaging))), )), - 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{}, }, }, }, @@ -96,22 +96,22 @@ func TestBuildConfiguration(t *testing.T) { appPorts(80, 81), withTasks(localhostTask(taskPorts(80, 81))), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ - "app": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "app": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -132,22 +132,22 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.routers.app.middlewares", "Middleware1"), withTasks(localhostTask(taskPorts(80))), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", 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", @@ -155,9 +155,9 @@ func TestBuildConfiguration(t *testing.T) { }, }, }, - Services: map[string]*config.Service{ - "app": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Services: map[string]*dynamic.Service{ + "app": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -186,22 +186,22 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.routers.Router1.rule", "Host(`app.marathon.localhost`)"), ), ), - 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(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ - "Service1": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "Service1": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:8080", }, @@ -235,22 +235,22 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.routers.Router1.rule", "Host(`app.marathon.localhost`)"), ), ), - 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(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ - "Service1": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "Service1": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:8080", }, @@ -282,13 +282,13 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(8081))), ), ), - 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{ "foo": { Service: "foo", Rule: "Host(`foo.marathon.localhost`)", @@ -298,18 +298,18 @@ func TestBuildConfiguration(t *testing.T) { Rule: "Host(`bar.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ - "foo": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "foo": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:8080", }, }, PassHostHeader: true, }}, - "bar": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + "bar": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:8081", }, @@ -328,23 +328,23 @@ func TestBuildConfiguration(t *testing.T) { appPorts(80), withTasks(localhostTask(taskPorts(80)), localhostTask(taskPorts(81))), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -368,22 +368,22 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80))), withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"), )), - 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{ "app": { Service: "Service1", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ - "Service1": {LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ + "Service1": {LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -405,23 +405,23 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"), withLabel("traefik.http.routers.Router1.service", "Service1"), )), - 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://localhost:80", }, @@ -442,17 +442,17 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"), )), - 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{ - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + HTTP: &dynamic.HTTPConfiguration{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -461,7 +461,7 @@ func TestBuildConfiguration(t *testing.T) { }, }, }, - Routers: map[string]*config.Router{ + Routers: map[string]*dynamic.Router{ "Router1": { Service: "app", Rule: "Host(`foo.com`)", @@ -480,23 +480,23 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"), withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"), )), - 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://localhost:80", }, @@ -519,18 +519,18 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"), withLabel("traefik.http.services.Service2.loadbalancer.passhostheader", "true"), )), - 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{ "Service1": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -539,8 +539,8 @@ func TestBuildConfiguration(t *testing.T) { }, }, "Service2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -567,13 +567,13 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.http.services.Service1.loadbalancer.passhostheader", "true"), )), - 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{ "app": { Service: "Service1", Rule: "Host(`app.marathon.localhost`)", @@ -583,8 +583,8 @@ func TestBuildConfiguration(t *testing.T) { Rule: "Host(`app2.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{}, + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{}, }, }, }, @@ -603,13 +603,13 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.http.middlewares.Middleware1.maxconn.amount", "42"), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", @@ -619,18 +619,18 @@ func TestBuildConfiguration(t *testing.T) { Rule: "Host(`app2.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{ + Middlewares: map[string]*dynamic.Middleware{ "Middleware1": { - MaxConn: &config.MaxConn{ + MaxConn: &dynamic.MaxConn{ Amount: 42, ExtractorFunc: "request.host", }, }, }, - Services: map[string]*config.Service{ + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -639,8 +639,8 @@ func TestBuildConfiguration(t *testing.T) { }, }, "app2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -667,13 +667,13 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.http.middlewares.Middleware1.maxconn.amount", "41"), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", @@ -683,11 +683,11 @@ func TestBuildConfiguration(t *testing.T) { Rule: "Host(`app2.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -696,8 +696,8 @@ func TestBuildConfiguration(t *testing.T) { }, }, "app2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -724,18 +724,18 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.http.routers.Router1.rule", "Host(`bar.com`)"), )), - 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{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -744,8 +744,8 @@ func TestBuildConfiguration(t *testing.T) { }, }, "app2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -774,23 +774,23 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"), withLabel("traefik.http.services.Service1.LoadBalancer.passhostheader", "true"), )), - 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://localhost:80", }, @@ -820,18 +820,18 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.http.routers.Router1.rule", "Host(`foo.com`)"), )), - 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{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -840,8 +840,8 @@ func TestBuildConfiguration(t *testing.T) { }, }, "app2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -862,23 +862,23 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.wrong.label", "tchouk"), )), - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -900,23 +900,23 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.services.Service1.LoadBalancer.server.scheme", "h2c"), withLabel("traefik.http.services.Service1.LoadBalancer.server.port", "90"), )), - 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{ "app": { Service: "Service1", Rule: "Host(`app.marathon.localhost`)", }, }, - 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: "h2c://localhost:90", }, @@ -938,18 +938,18 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.http.services.Service1.LoadBalancer.server.port", ""), withLabel("traefik.http.services.Service2.LoadBalancer.server.port", "8080"), )), - 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{ "Service1": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -958,8 +958,8 @@ func TestBuildConfiguration(t *testing.T) { }, }, "Service2": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:8080", }, @@ -979,15 +979,15 @@ func TestBuildConfiguration(t *testing.T) { appPorts(80, 81), withTasks(localhostTask()), )), - 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{}, }, }, }, @@ -1000,15 +1000,15 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask()), withLabel("traefik.http.middlewares.Middleware1.basicauth.users", "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0"), )), - 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{}, }, }, }, @@ -1021,15 +1021,15 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask()), withLabel("traefik.enable", "false"), )), - 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{}, }, }, }, @@ -1042,15 +1042,15 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask()), withLabel("traefik.enable", "false"), )), - 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{}, }, }, }, @@ -1064,15 +1064,15 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.tags", "foo"), )), 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{}, }, }, }, @@ -1086,15 +1086,15 @@ func TestBuildConfiguration(t *testing.T) { constraint("rack_id:CLUSTER:rack-1"), )), constraints: `MarathonConstraint("rack_id:CLUSTER:rack-2")`, - 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{}, }, }, }, @@ -1108,23 +1108,23 @@ func TestBuildConfiguration(t *testing.T) { constraint("rack_id:CLUSTER:rack-1"), )), constraints: `MarathonConstraint("rack_id:CLUSTER:rack-1")`, - 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{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -1146,23 +1146,23 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.tags", "bar"), )), 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{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "app": { Service: "app", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -1183,23 +1183,23 @@ func TestBuildConfiguration(t *testing.T) { appPorts(80, 81), withTasks(localhostTask(taskPorts(80, 81))), )), - 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{ "a_b_app": { Service: "a_b_app", Rule: `Host("app.b.a.marathon.localhost")`, }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "a_b_app": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -1221,19 +1221,19 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.tcp.routers.foo.rule", "HostSNI(`foo.bar`)"), withLabel("traefik.tcp.routers.foo.tls", "true"), )), - expected: &config.Configuration{ - TCP: &config.TCPConfiguration{ - Routers: map[string]*config.TCPRouter{ + expected: &dynamic.Configuration{ + TCP: &dynamic.TCPConfiguration{ + Routers: map[string]*dynamic.TCPRouter{ "foo": { Service: "app", Rule: "HostSNI(`foo.bar`)", - TLS: &config.RouterTCPTLSConfig{}, + TLS: &dynamic.RouterTCPTLSConfig{}, }, }, - Services: map[string]*config.TCPService{ + Services: map[string]*dynamic.TCPService{ "app": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "localhost:80", }, @@ -1242,10 +1242,10 @@ func TestBuildConfiguration(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{}, }, }, }, @@ -1258,13 +1258,13 @@ func TestBuildConfiguration(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), withLabel("traefik.tcp.routers.foo.tls", "true"), )), - 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{ "app": { - LoadBalancer: &config.TCPLoadBalancerService{ - Servers: []config.TCPServer{ + LoadBalancer: &dynamic.TCPLoadBalancerService{ + Servers: []dynamic.TCPServer{ { Address: "localhost:80", }, @@ -1273,10 +1273,10 @@ func TestBuildConfiguration(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{}, }, }, }, @@ -1291,19 +1291,19 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.tcp.routers.foo.tls", "true"), withLabel("traefik.tcp.services.foo.loadbalancer.server.port", "8080"), )), - 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: "localhost:8080", }, @@ -1312,10 +1312,10 @@ func TestBuildConfiguration(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{}, }, }, }, @@ -1331,19 +1331,19 @@ func TestBuildConfiguration(t *testing.T) { withLabel("traefik.tcp.services.foo.loadbalancer.server.port", "8080"), withLabel("traefik.http.services.bar.loadbalancer.passhostheader", "true"), )), - 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: "localhost:8080", }, @@ -1352,18 +1352,18 @@ func TestBuildConfiguration(t *testing.T) { }, }, }, - HTTP: &config.HTTPConfiguration{ - Routers: map[string]*config.Router{ + HTTP: &dynamic.HTTPConfiguration{ + Routers: map[string]*dynamic.Router{ "app": { Service: "bar", Rule: "Host(`app.marathon.localhost`)", }, }, - Middlewares: map[string]*config.Middleware{}, - Services: map[string]*config.Service{ + Middlewares: map[string]*dynamic.Middleware{}, + Services: map[string]*dynamic.Service{ "bar": { - LoadBalancer: &config.LoadBalancerService{ - Servers: []config.Server{ + LoadBalancer: &dynamic.LoadBalancerService{ + Servers: []dynamic.Server{ { URL: "http://localhost:80", }, @@ -1452,7 +1452,7 @@ func TestApplicationFilterEnabled(t *testing.T) { func TestGetServer(t *testing.T) { type expected struct { - server config.Server + server dynamic.Server error string } @@ -1461,7 +1461,7 @@ func TestGetServer(t *testing.T) { provider Provider app marathon.Application extraConf configuration - defaultServer config.Server + defaultServer dynamic.Server expected expected }{ { @@ -1469,7 +1469,7 @@ func TestGetServer(t *testing.T) { provider: Provider{}, app: application(), extraConf: configuration{}, - defaultServer: config.Server{}, + defaultServer: dynamic.Server{}, expected: expected{ error: `host is undefined for task "taskID" app ""`, }, @@ -1483,11 +1483,11 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://localhost:80", }, }, @@ -1501,7 +1501,7 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask()), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ @@ -1517,12 +1517,12 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", Port: "88", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://localhost:88", }, }, @@ -1536,7 +1536,7 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", Port: "aaaa", }, @@ -1553,7 +1553,7 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", Port: "-6", }, @@ -1570,12 +1570,12 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", Port: "index:1", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://localhost:81", }, }, @@ -1589,7 +1589,7 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", Port: "index:2", }, @@ -1606,7 +1606,7 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", Port: "index:aaa", }, @@ -1624,11 +1624,11 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask()), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://localhost:80", }, }, @@ -1643,11 +1643,11 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask()), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://127.0.0.1:88", }, }, @@ -1662,11 +1662,11 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://127.0.0.1:80", }, }, @@ -1681,11 +1681,11 @@ func TestGetServer(t *testing.T) { withTasks(localhostTask(taskPorts(80, 81))), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://localhost:80", }, }, @@ -1710,11 +1710,11 @@ func TestGetServer(t *testing.T) { IPAddressIdx: 0, }, }, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ - server: config.Server{ + server: dynamic.Server{ URL: "http://127.0.0.1:88", }, }, @@ -1738,7 +1738,7 @@ func TestGetServer(t *testing.T) { IPAddressIdx: math.MinInt32, }, }, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ @@ -1764,7 +1764,7 @@ func TestGetServer(t *testing.T) { IPAddressIdx: 3, }, }, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ @@ -1785,7 +1785,7 @@ func TestGetServer(t *testing.T) { )), ), extraConf: configuration{}, - defaultServer: config.Server{ + defaultServer: dynamic.Server{ Scheme: "http", }, expected: expected{ diff --git a/pkg/provider/marathon/marathon.go b/pkg/provider/marathon/marathon.go index b08d7f425..379d61d57 100644 --- a/pkg/provider/marathon/marathon.go +++ b/pkg/provider/marathon/marathon.go @@ -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) diff --git a/pkg/provider/provider.go b/pkg/provider/provider.go index d64b69914..e9c1b64ed 100644 --- a/pkg/provider/provider.go +++ b/pkg/provider/provider.go @@ -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 } diff --git a/pkg/provider/rancher/config.go b/pkg/provider/rancher/config.go index 3eb15ee69..08c48406a 100644 --- a/pkg/provider/rancher/config.go +++ b/pkg/provider/rancher/config.go @@ -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 } diff --git a/pkg/provider/rancher/config_test.go b/pkg/provider/rancher/config_test.go index 3cdf36f6e..7a180260c 100644 --- a/pkg/provider/rancher/config_test.go +++ b/pkg/provider/rancher/config_test.go @@ -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{}, }, }, }, diff --git a/pkg/provider/rancher/rancher.go b/pkg/provider/rancher/rancher.go index 9d12ac6bc..8d1c118a5 100644 --- a/pkg/provider/rancher/rancher.go +++ b/pkg/provider/rancher/rancher.go @@ -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, } diff --git a/pkg/provider/rest/rest.go b/pkg/provider/rest/rest.go index b7cc8e065..45cf025bf 100644 --- a/pkg/provider/rest/rest.go +++ b/pkg/provider/rest/rest.go @@ -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 } diff --git a/pkg/responsemodifiers/headers.go b/pkg/responsemodifiers/headers.go index 4796b9be4..5c104729a 100644 --- a/pkg/responsemodifiers/headers.go +++ b/pkg/responsemodifiers/headers.go @@ -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, diff --git a/pkg/responsemodifiers/response_modifier.go b/pkg/responsemodifiers/response_modifier.go index bd3199a18..cf30f42cf 100644 --- a/pkg/responsemodifiers/response_modifier.go +++ b/pkg/responsemodifiers/response_modifier.go @@ -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. diff --git a/pkg/responsemodifiers/response_modifier_test.go b/pkg/responsemodifiers/response_modifier_test.go index f409d80ce..f407c124c 100644 --- a/pkg/responsemodifiers/response_modifier_test.go +++ b/pkg/responsemodifiers/response_modifier_test.go @@ -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, }, }) diff --git a/pkg/server/aggregator.go b/pkg/server/aggregator.go index 5d2c25cc9..c00255ec3 100644 --- a/pkg/server/aggregator.go +++ b/pkg/server/aggregator.go @@ -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), }, diff --git a/pkg/server/aggregator_test.go b/pkg/server/aggregator_test.go index 92733f3e0..98e92166f 100644 --- a/pkg/server/aggregator_test.go +++ b/pkg/server/aggregator_test.go @@ -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", diff --git a/pkg/server/middleware/middlewares.go b/pkg/server/middleware/middlewares.go index 10cb83d46..7d2609623 100644 --- a/pkg/server/middleware/middlewares.go +++ b/pkg/server/middleware/middlewares.go @@ -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} } diff --git a/pkg/server/middleware/middlewares_test.go b/pkg/server/middleware/middlewares_test.go index 0de9b0ef5..ead213a69 100644 --- a/pkg/server/middleware/middlewares_test.go +++ b/pkg/server/middleware/middlewares_test.go @@ -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, }, }) diff --git a/pkg/server/router/route_appender_aggregator.go b/pkg/server/router/route_appender_aggregator.go index fcea9aec7..5f1423546 100644 --- a/pkg/server/router/route_appender_aggregator.go +++ b/pkg/server/router/route_appender_aggregator.go @@ -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 { diff --git a/pkg/server/router/route_appender_factory.go b/pkg/server/router/route_appender_factory.go index eec0b36b5..ea44a4e21 100644 --- a/pkg/server/router/route_appender_factory.go +++ b/pkg/server/router/route_appender_factory.go @@ -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 { diff --git a/pkg/server/router/router.go b/pkg/server/router/router.go index 51f6aae14..104e9b42f 100644 --- a/pkg/server/router/router.go +++ b/pkg/server/router/router.go @@ -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) diff --git a/pkg/server/router/router_test.go b/pkg/server/router/router_test.go index 6c17df155..8e110008f 100644 --- a/pkg/server/router/router_test.go +++ b/pkg/server/router/router_test.go @@ -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, }, }) diff --git a/pkg/server/router/tcp/router.go b/pkg/server/router/tcp/router.go index 26ed3d096..fba89d2c6 100644 --- a/pkg/server/router/tcp/router.go +++ b/pkg/server/router/tcp/router.go @@ -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" diff --git a/pkg/server/router/tcp/router_test.go b/pkg/server/router/tcp/router_test.go index e65e549e2..b2320f9e0 100644 --- a/pkg/server/router/tcp/router_test.go +++ b/pkg/server/router/tcp/router_test.go @@ -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, } diff --git a/pkg/server/server.go b/pkg/server/server.go index c84f1c84a..0feadb30f 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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) } diff --git a/pkg/server/server_configuration.go b/pkg/server/server_configuration.go index eb78e4023..c0aa203ac 100644 --- a/pkg/server/server_configuration.go +++ b/pkg/server/server_configuration.go @@ -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) } diff --git a/pkg/server/server_configuration_test.go b/pkg/server/server_configuration_test.go index a5d8b1fdc..6bdcc706d 100644 --- a/pkg/server/server_configuration_test.go +++ b/pkg/server/server_configuration_test.go @@ -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) } diff --git a/pkg/server/server_test.go b/pkg/server/server_test.go index 255b8aa5a..e2b2219f9 100644 --- a/pkg/server/server_test.go +++ b/pkg/server/server_test.go @@ -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{} diff --git a/pkg/server/service/proxy.go b/pkg/server/service/proxy.go index b4f970748..2c59c6475 100644 --- a/pkg/server/service/proxy.go +++ b/pkg/server/service/proxy.go @@ -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) diff --git a/pkg/server/service/service.go b/pkg/server/service/service.go index a92047bdd..03ec8e138 100644 --- a/pkg/server/service/service.go +++ b/pkg/server/service/service.go @@ -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 { diff --git a/pkg/server/service/service_test.go b/pkg/server/service/service_test.go index f2892a61f..963d67b25 100644 --- a/pkg/server/service/service_test.go +++ b/pkg/server/service/service_test.go @@ -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{}, }, }, }, diff --git a/pkg/server/service/tcp/service.go b/pkg/server/service/tcp/service.go index 9116f4648..704ba9fc2 100644 --- a/pkg/server/service/tcp/service.go +++ b/pkg/server/service/tcp/service.go @@ -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, } diff --git a/pkg/server/service/tcp/service_test.go b/pkg/server/service/tcp/service_test.go index 13b27ed6d..15550eb63 100644 --- a/pkg/server/service/tcp/service_test.go +++ b/pkg/server/service/tcp/service_test.go @@ -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, }) diff --git a/pkg/testhelpers/config.go b/pkg/testhelpers/config.go index ba2ebfebd..6cfcbbb43 100644 --- a/pkg/testhelpers/config.go +++ b/pkg/testhelpers/config.go @@ -1,12 +1,12 @@ package testhelpers import ( - "github.com/containous/traefik/pkg/config" + "github.com/containous/traefik/pkg/config/dynamic" ) // BuildConfiguration is a helper to create a configuration. -func BuildConfiguration(dynamicConfigBuilders ...func(*config.HTTPConfiguration)) *config.HTTPConfiguration { - conf := &config.HTTPConfiguration{} +func BuildConfiguration(dynamicConfigBuilders ...func(*dynamic.HTTPConfiguration)) *dynamic.HTTPConfiguration { + conf := &dynamic.HTTPConfiguration{} for _, build := range dynamicConfigBuilders { build(conf) } @@ -14,11 +14,11 @@ func BuildConfiguration(dynamicConfigBuilders ...func(*config.HTTPConfiguration) } // WithRouters is a helper to create a configuration. -func WithRouters(opts ...func(*config.Router) string) func(*config.HTTPConfiguration) { - return func(c *config.HTTPConfiguration) { - c.Routers = make(map[string]*config.Router) +func WithRouters(opts ...func(*dynamic.Router) string) func(*dynamic.HTTPConfiguration) { + return func(c *dynamic.HTTPConfiguration) { + c.Routers = make(map[string]*dynamic.Router) for _, opt := range opts { - b := &config.Router{} + b := &dynamic.Router{} name := opt(b) c.Routers[name] = b } @@ -26,8 +26,8 @@ func WithRouters(opts ...func(*config.Router) string) func(*config.HTTPConfigura } // WithRouter is a helper to create a configuration. -func WithRouter(routerName string, opts ...func(*config.Router)) func(*config.Router) string { - return func(r *config.Router) string { +func WithRouter(routerName string, opts ...func(*dynamic.Router)) func(*dynamic.Router) string { + return func(r *dynamic.Router) string { for _, opt := range opts { opt(r) } @@ -36,27 +36,27 @@ func WithRouter(routerName string, opts ...func(*config.Router)) func(*config.Ro } // WithRouterMiddlewares is a helper to create a configuration. -func WithRouterMiddlewares(middlewaresName ...string) func(*config.Router) { - return func(r *config.Router) { +func WithRouterMiddlewares(middlewaresName ...string) func(*dynamic.Router) { + return func(r *dynamic.Router) { r.Middlewares = middlewaresName } } // WithServiceName is a helper to create a configuration. -func WithServiceName(serviceName string) func(*config.Router) { - return func(r *config.Router) { +func WithServiceName(serviceName string) func(*dynamic.Router) { + return func(r *dynamic.Router) { r.Service = serviceName } } // WithLoadBalancerServices is a helper to create a configuration. -func WithLoadBalancerServices(opts ...func(service *config.LoadBalancerService) string) func(*config.HTTPConfiguration) { - return func(c *config.HTTPConfiguration) { - c.Services = make(map[string]*config.Service) +func WithLoadBalancerServices(opts ...func(service *dynamic.LoadBalancerService) string) func(*dynamic.HTTPConfiguration) { + return func(c *dynamic.HTTPConfiguration) { + c.Services = make(map[string]*dynamic.Service) for _, opt := range opts { - b := &config.LoadBalancerService{} + b := &dynamic.LoadBalancerService{} name := opt(b) - c.Services[name] = &config.Service{ + c.Services[name] = &dynamic.Service{ LoadBalancer: b, } } @@ -64,8 +64,8 @@ func WithLoadBalancerServices(opts ...func(service *config.LoadBalancerService) } // WithService is a helper to create a configuration. -func WithService(name string, opts ...func(*config.LoadBalancerService)) func(*config.LoadBalancerService) string { - return func(r *config.LoadBalancerService) string { +func WithService(name string, opts ...func(*dynamic.LoadBalancerService)) func(*dynamic.LoadBalancerService) string { + return func(r *dynamic.LoadBalancerService) string { for _, opt := range opts { opt(r) } @@ -74,11 +74,11 @@ func WithService(name string, opts ...func(*config.LoadBalancerService)) func(*c } // WithMiddlewares is a helper to create a configuration. -func WithMiddlewares(opts ...func(*config.Middleware) string) func(*config.HTTPConfiguration) { - return func(c *config.HTTPConfiguration) { - c.Middlewares = make(map[string]*config.Middleware) +func WithMiddlewares(opts ...func(*dynamic.Middleware) string) func(*dynamic.HTTPConfiguration) { + return func(c *dynamic.HTTPConfiguration) { + c.Middlewares = make(map[string]*dynamic.Middleware) for _, opt := range opts { - b := &config.Middleware{} + b := &dynamic.Middleware{} name := opt(b) c.Middlewares[name] = b } @@ -86,8 +86,8 @@ func WithMiddlewares(opts ...func(*config.Middleware) string) func(*config.HTTPC } // WithMiddleware is a helper to create a configuration. -func WithMiddleware(name string, opts ...func(*config.Middleware)) func(*config.Middleware) string { - return func(r *config.Middleware) string { +func WithMiddleware(name string, opts ...func(*dynamic.Middleware)) func(*dynamic.Middleware) string { + return func(r *dynamic.Middleware) string { for _, opt := range opts { opt(r) } @@ -96,31 +96,31 @@ func WithMiddleware(name string, opts ...func(*config.Middleware)) func(*config. } // WithBasicAuth is a helper to create a configuration. -func WithBasicAuth(auth *config.BasicAuth) func(*config.Middleware) { - return func(r *config.Middleware) { +func WithBasicAuth(auth *dynamic.BasicAuth) func(*dynamic.Middleware) { + return func(r *dynamic.Middleware) { r.BasicAuth = auth } } // WithEntryPoints is a helper to create a configuration. -func WithEntryPoints(eps ...string) func(*config.Router) { - return func(f *config.Router) { +func WithEntryPoints(eps ...string) func(*dynamic.Router) { + return func(f *dynamic.Router) { f.EntryPoints = eps } } // WithRule is a helper to create a configuration. -func WithRule(rule string) func(*config.Router) { - return func(f *config.Router) { +func WithRule(rule string) func(*dynamic.Router) { + return func(f *dynamic.Router) { f.Rule = rule } } // WithServers is a helper to create a configuration. -func WithServers(opts ...func(*config.Server)) func(*config.LoadBalancerService) { - return func(b *config.LoadBalancerService) { +func WithServers(opts ...func(*dynamic.Server)) func(*dynamic.LoadBalancerService) { + return func(b *dynamic.LoadBalancerService) { for _, opt := range opts { - server := config.Server{} + server := dynamic.Server{} opt(&server) b.Servers = append(b.Servers, server) } @@ -128,8 +128,8 @@ func WithServers(opts ...func(*config.Server)) func(*config.LoadBalancerService) } // WithServer is a helper to create a configuration. -func WithServer(url string, opts ...func(*config.Server)) func(*config.Server) { - return func(s *config.Server) { +func WithServer(url string, opts ...func(*dynamic.Server)) func(*dynamic.Server) { + return func(s *dynamic.Server) { for _, opt := range opts { opt(s) } @@ -138,9 +138,9 @@ func WithServer(url string, opts ...func(*config.Server)) func(*config.Server) { } // WithStickiness is a helper to create a configuration. -func WithStickiness(cookieName string) func(*config.LoadBalancerService) { - return func(b *config.LoadBalancerService) { - b.Stickiness = &config.Stickiness{ +func WithStickiness(cookieName string) func(*dynamic.LoadBalancerService) { + return func(b *dynamic.LoadBalancerService) { + b.Stickiness = &dynamic.Stickiness{ CookieName: cookieName, } } diff --git a/script/update-generated-crd-code.sh b/script/update-generated-crd-code.sh index bbc02afdc..b7f7a5e4b 100755 --- a/script/update-generated-crd-code.sh +++ b/script/update-generated-crd-code.sh @@ -11,4 +11,4 @@ REPO_ROOT=${HACK_DIR}/.. --go-header-file "${HACK_DIR}"/boilerplate.go.tmpl \ "$@" -deepcopy-gen --input-dirs github.com/containous/traefik/pkg/config --input-dirs github.com/containous/traefik/pkg/tls -O zz_generated.deepcopy --go-header-file "${HACK_DIR}"/boilerplate.go.tmpl +deepcopy-gen --input-dirs github.com/containous/traefik/pkg/config/dynamic --input-dirs github.com/containous/traefik/pkg/tls -O zz_generated.deepcopy --go-header-file "${HACK_DIR}"/boilerplate.go.tmpl