Move dynamic config into a dedicated package.
This commit is contained in:
parent
09cc1161c9
commit
c8bf8e896a
102 changed files with 3170 additions and 3166 deletions
|
@ -17,7 +17,7 @@ import (
|
||||||
cmdVersion "github.com/containous/traefik/cmd/version"
|
cmdVersion "github.com/containous/traefik/cmd/version"
|
||||||
"github.com/containous/traefik/pkg/cli"
|
"github.com/containous/traefik/pkg/cli"
|
||||||
"github.com/containous/traefik/pkg/collector"
|
"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/config/static"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider/aggregator"
|
"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)
|
svr := server.NewServer(*staticConfiguration, providerAggregator, serverEntryPointsTCP, tlsManager)
|
||||||
|
|
||||||
if acmeProvider != nil && acmeProvider.OnHostRule {
|
if acmeProvider != nil && acmeProvider.OnHostRule {
|
||||||
acmeProvider.SetConfigListenerChan(make(chan config.Configuration))
|
acmeProvider.SetConfigListenerChan(make(chan dynamic.Configuration))
|
||||||
svr.AddListener(acmeProvider.ListenConfiguration)
|
svr.AddListener(acmeProvider.ListenConfiguration)
|
||||||
}
|
}
|
||||||
ctx := cmd.ContextWithSignal(context.Background())
|
ctx := cmd.ContextWithSignal(context.Background())
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/containous/traefik/integration/try"
|
"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"
|
traefiktls "github.com/containous/traefik/pkg/tls"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
checker "github.com/vdemeester/shakers"
|
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 certificate file is not provided, just truncate the configuration file
|
||||||
if len(certFileName) > 0 {
|
if len(certFileName) > 0 {
|
||||||
tlsConf := config.Configuration{
|
tlsConf := dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Certificates: []*traefiktls.CertAndStores{{
|
Certificates: []*traefiktls.CertAndStores{{
|
||||||
Certificate: traefiktls.Certificate{
|
Certificate: traefiktls.Certificate{
|
||||||
CertFile: traefiktls.FileOrContent("fixtures/https/" + certFileName + ".cert"),
|
CertFile: traefiktls.FileOrContent("fixtures/https/" + certFileName + ".cert"),
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/traefik/integration/try"
|
"github.com/containous/traefik/integration/try"
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
checker "github.com/vdemeester/shakers"
|
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))
|
err = try.GetRequest("http://127.0.0.1:8000/", 1000*time.Millisecond, try.StatusCodeIs(http.StatusNotFound))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
config := config.HTTPConfiguration{
|
config := dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router1": {
|
"router1": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Middlewares: []string{},
|
Middlewares: []string{},
|
||||||
|
@ -41,10 +41,10 @@ func (s *RestSuite) TestSimpleConfiguration(c *check.C) {
|
||||||
Rule: "PathPrefix(`/`)",
|
Rule: "PathPrefix(`/`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"service1": {
|
"service1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80",
|
URL: "http://" + s.composeProject.Container(c, "whoami1").NetworkSettings.IPAddress + ":80",
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/traefik/integration/try"
|
"github.com/containous/traefik/integration/try"
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
checker "github.com/vdemeester/shakers"
|
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"))
|
err = try.GetRequest("http://127.0.0.1:8080/api/rawdata", 1000*time.Millisecond, try.BodyContains("service"))
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
config := config.HTTPConfiguration{
|
config := dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router1": {
|
"router1": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Middlewares: []string{"customheader@file"},
|
Middlewares: []string{"customheader@file"},
|
||||||
|
|
|
@ -48,8 +48,8 @@ func genStaticConfDoc(outputFile string, prefix string, encodeFn func(interface{
|
||||||
w.writeln(`<!--
|
w.writeln(`<!--
|
||||||
CODE GENERATED AUTOMATICALLY
|
CODE GENERATED AUTOMATICALLY
|
||||||
THIS FILE MUST NOT BE EDITED BY HAND
|
THIS FILE MUST NOT BE EDITED BY HAND
|
||||||
-->
|
-->`)
|
||||||
`)
|
w.writeln()
|
||||||
|
|
||||||
for i, flat := range flats {
|
for i, flat := range flats {
|
||||||
w.writeln("`" + prefix + strings.ReplaceAll(flat.Name, "[0]", "[n]") + "`: ")
|
w.writeln("`" + prefix + strings.ReplaceAll(flat.Name, "[0]", "[n]") + "`: ")
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containous/mux"
|
"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/config/static"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"github.com/containous/traefik/pkg/types"
|
||||||
|
@ -25,46 +25,46 @@ const (
|
||||||
const nextPageHeader = "X-Next-Page"
|
const nextPageHeader = "X-Next-Page"
|
||||||
|
|
||||||
type serviceInfoRepresentation struct {
|
type serviceInfoRepresentation struct {
|
||||||
*config.ServiceInfo
|
*dynamic.ServiceInfo
|
||||||
ServerStatus map[string]string `json:"serverStatus,omitempty"`
|
ServerStatus map[string]string `json:"serverStatus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunTimeRepresentation is the configuration information exposed by the API handler.
|
// RunTimeRepresentation is the configuration information exposed by the API handler.
|
||||||
type RunTimeRepresentation struct {
|
type RunTimeRepresentation struct {
|
||||||
Routers map[string]*config.RouterInfo `json:"routers,omitempty"`
|
Routers map[string]*dynamic.RouterInfo `json:"routers,omitempty"`
|
||||||
Middlewares map[string]*config.MiddlewareInfo `json:"middlewares,omitempty"`
|
Middlewares map[string]*dynamic.MiddlewareInfo `json:"middlewares,omitempty"`
|
||||||
Services map[string]*serviceInfoRepresentation `json:"services,omitempty"`
|
Services map[string]*serviceInfoRepresentation `json:"services,omitempty"`
|
||||||
TCPRouters map[string]*config.TCPRouterInfo `json:"tcpRouters,omitempty"`
|
TCPRouters map[string]*dynamic.TCPRouterInfo `json:"tcpRouters,omitempty"`
|
||||||
TCPServices map[string]*config.TCPServiceInfo `json:"tcpServices,omitempty"`
|
TCPServices map[string]*dynamic.TCPServiceInfo `json:"tcpServices,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type routerRepresentation struct {
|
type routerRepresentation struct {
|
||||||
*config.RouterInfo
|
*dynamic.RouterInfo
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type serviceRepresentation struct {
|
type serviceRepresentation struct {
|
||||||
*config.ServiceInfo
|
*dynamic.ServiceInfo
|
||||||
ServerStatus map[string]string `json:"serverStatus,omitempty"`
|
ServerStatus map[string]string `json:"serverStatus,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type middlewareRepresentation struct {
|
type middlewareRepresentation struct {
|
||||||
*config.MiddlewareInfo
|
*dynamic.MiddlewareInfo
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpRouterRepresentation struct {
|
type tcpRouterRepresentation struct {
|
||||||
*config.TCPRouterInfo
|
*dynamic.TCPRouterInfo
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tcpServiceRepresentation struct {
|
type tcpServiceRepresentation struct {
|
||||||
*config.TCPServiceInfo
|
*dynamic.TCPServiceInfo
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Provider string `json:"provider,omitempty"`
|
Provider string `json:"provider,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ type Handler struct {
|
||||||
dashboard bool
|
dashboard bool
|
||||||
debug bool
|
debug bool
|
||||||
// runtimeConfiguration is the data set used to create all the data representations exposed by the API.
|
// 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
|
statistics *types.Statistics
|
||||||
// stats *thoasstats.Stats // FIXME stats
|
// stats *thoasstats.Stats // FIXME stats
|
||||||
// StatsRecorder *middlewares.StatsRecorder // 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.
|
// New returns a Handler defined by staticConfig, and if provided, by runtimeConfig.
|
||||||
// It finishes populating the information provided in the 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
|
rConfig := runtimeConfig
|
||||||
if rConfig == nil {
|
if rConfig == nil {
|
||||||
rConfig = &config.RuntimeConfiguration{}
|
rConfig = &dynamic.RuntimeConfiguration{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Handler{
|
return &Handler{
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containous/mux"
|
"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/config/static"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -29,13 +29,13 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
path string
|
path string
|
||||||
conf config.RuntimeConfiguration
|
conf dynamic.RuntimeConfiguration
|
||||||
expected expected
|
expected expected
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "all TCP routers, but no config",
|
desc: "all TCP routers, but no config",
|
||||||
path: "/api/tcp/routers",
|
path: "/api/tcp/routers",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusOK,
|
statusCode: http.StatusOK,
|
||||||
nextPage: "1",
|
nextPage: "1",
|
||||||
|
@ -45,20 +45,20 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all TCP routers",
|
desc: "all TCP routers",
|
||||||
path: "/api/tcp/routers",
|
path: "/api/tcp/routers",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPRouters: map[string]*config.TCPRouterInfo{
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
||||||
"test@myprovider": {
|
"test@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar.other`)",
|
Rule: "Host(`foo.bar.other`)",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
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",
|
desc: "all TCP routers, pagination, 1 res per page, want page 2",
|
||||||
path: "/api/tcp/routers?page=2&per_page=1",
|
path: "/api/tcp/routers?page=2&per_page=1",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPRouters: map[string]*config.TCPRouterInfo{
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"baz@myprovider": {
|
"baz@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`toto.bar`)",
|
Rule: "Host(`toto.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test@myprovider": {
|
"test@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar.other`)",
|
Rule: "Host(`foo.bar.other`)",
|
||||||
|
@ -109,10 +109,10 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one TCP router by id",
|
desc: "one TCP router by id",
|
||||||
path: "/api/tcp/routers/bar@myprovider",
|
path: "/api/tcp/routers/bar@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPRouters: map[string]*config.TCPRouterInfo{
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
|
@ -128,10 +128,10 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one TCP router by id, that does not exist",
|
desc: "one TCP router by id, that does not exist",
|
||||||
path: "/api/tcp/routers/foo@myprovider",
|
path: "/api/tcp/routers/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPRouters: map[string]*config.TCPRouterInfo{
|
TCPRouters: map[string]*dynamic.TCPRouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
|
@ -146,7 +146,7 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one TCP router by id, but no config",
|
desc: "one TCP router by id, but no config",
|
||||||
path: "/api/tcp/routers/bar@myprovider",
|
path: "/api/tcp/routers/bar@myprovider",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusNotFound,
|
statusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
|
@ -154,7 +154,7 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all tcp services, but no config",
|
desc: "all tcp services, but no config",
|
||||||
path: "/api/tcp/services",
|
path: "/api/tcp/services",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusOK,
|
statusCode: http.StatusOK,
|
||||||
nextPage: "1",
|
nextPage: "1",
|
||||||
|
@ -164,12 +164,12 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all tcp services",
|
desc: "all tcp services",
|
||||||
path: "/api/tcp/services",
|
path: "/api/tcp/services",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPServices: map[string]*config.TCPServiceInfo{
|
TCPServices: map[string]*dynamic.TCPServiceInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:2345",
|
Address: "127.0.0.1:2345",
|
||||||
},
|
},
|
||||||
|
@ -179,9 +179,9 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
UsedBy: []string{"foo@myprovider", "test@myprovider"},
|
UsedBy: []string{"foo@myprovider", "test@myprovider"},
|
||||||
},
|
},
|
||||||
"baz@myprovider": {
|
"baz@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.2:2345",
|
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",
|
desc: "all tcp services, 1 res per page, want page 2",
|
||||||
path: "/api/tcp/services?page=2&per_page=1",
|
path: "/api/tcp/services?page=2&per_page=1",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPServices: map[string]*config.TCPServiceInfo{
|
TCPServices: map[string]*dynamic.TCPServiceInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:2345",
|
Address: "127.0.0.1:2345",
|
||||||
},
|
},
|
||||||
|
@ -216,9 +216,9 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
UsedBy: []string{"foo@myprovider", "test@myprovider"},
|
UsedBy: []string{"foo@myprovider", "test@myprovider"},
|
||||||
},
|
},
|
||||||
"baz@myprovider": {
|
"baz@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.2:2345",
|
Address: "127.0.0.2:2345",
|
||||||
},
|
},
|
||||||
|
@ -228,9 +228,9 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
UsedBy: []string{"foo@myprovider"},
|
UsedBy: []string{"foo@myprovider"},
|
||||||
},
|
},
|
||||||
"test@myprovider": {
|
"test@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.3:2345",
|
Address: "127.0.0.3:2345",
|
||||||
},
|
},
|
||||||
|
@ -249,12 +249,12 @@ func TestHandlerTCP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one tcp service by id",
|
desc: "one tcp service by id",
|
||||||
path: "/api/tcp/services/bar@myprovider",
|
path: "/api/tcp/services/bar@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPServices: map[string]*config.TCPServiceInfo{
|
TCPServices: map[string]*dynamic.TCPServiceInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:2345",
|
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",
|
desc: "one tcp service by id, that does not exist",
|
||||||
path: "/api/tcp/services/nono@myprovider",
|
path: "/api/tcp/services/nono@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
TCPServices: map[string]*config.TCPServiceInfo{
|
TCPServices: map[string]*dynamic.TCPServiceInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:2345",
|
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",
|
desc: "one tcp service by id, but no config",
|
||||||
path: "/api/tcp/services/foo@myprovider",
|
path: "/api/tcp/services/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusNotFound,
|
statusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
|
@ -363,13 +363,13 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
path string
|
path string
|
||||||
conf config.RuntimeConfiguration
|
conf dynamic.RuntimeConfiguration
|
||||||
expected expected
|
expected expected
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "all routers, but no config",
|
desc: "all routers, but no config",
|
||||||
path: "/api/http/routers",
|
path: "/api/http/routers",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusOK,
|
statusCode: http.StatusOK,
|
||||||
nextPage: "1",
|
nextPage: "1",
|
||||||
|
@ -379,10 +379,10 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all routers",
|
desc: "all routers",
|
||||||
path: "/api/http/routers",
|
path: "/api/http/routers",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: map[string]*config.RouterInfo{
|
Routers: map[string]*dynamic.RouterInfo{
|
||||||
"test@myprovider": {
|
"test@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar.other`)",
|
Rule: "Host(`foo.bar.other`)",
|
||||||
|
@ -390,7 +390,7 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
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",
|
desc: "all routers, pagination, 1 res per page, want page 2",
|
||||||
path: "/api/http/routers?page=2&per_page=1",
|
path: "/api/http/routers?page=2&per_page=1",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: map[string]*config.RouterInfo{
|
Routers: map[string]*dynamic.RouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
|
@ -419,14 +419,14 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"baz@myprovider": {
|
"baz@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`toto.bar`)",
|
Rule: "Host(`toto.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test@myprovider": {
|
"test@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar.other`)",
|
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",
|
desc: "all routers, pagination, 19 results overall, 7 res per page, want page 3",
|
||||||
path: "/api/http/routers?page=3&per_page=7",
|
path: "/api/http/routers?page=3&per_page=7",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: generateHTTPRouters(19),
|
Routers: generateHTTPRouters(19),
|
||||||
},
|
},
|
||||||
expected: expected{
|
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",
|
desc: "all routers, pagination, 5 results overall, 10 res per page, want page 2",
|
||||||
path: "/api/http/routers?page=2&per_page=10",
|
path: "/api/http/routers?page=2&per_page=10",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: generateHTTPRouters(5),
|
Routers: generateHTTPRouters(5),
|
||||||
},
|
},
|
||||||
expected: expected{
|
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",
|
desc: "all routers, pagination, 10 results overall, 10 res per page, want page 2",
|
||||||
path: "/api/http/routers?page=2&per_page=10",
|
path: "/api/http/routers?page=2&per_page=10",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: generateHTTPRouters(10),
|
Routers: generateHTTPRouters(10),
|
||||||
},
|
},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
|
@ -476,10 +476,10 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one router by id",
|
desc: "one router by id",
|
||||||
path: "/api/http/routers/bar@myprovider",
|
path: "/api/http/routers/bar@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: map[string]*config.RouterInfo{
|
Routers: map[string]*dynamic.RouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
|
@ -496,10 +496,10 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one router by id, that does not exist",
|
desc: "one router by id, that does not exist",
|
||||||
path: "/api/http/routers/foo@myprovider",
|
path: "/api/http/routers/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Routers: map[string]*config.RouterInfo{
|
Routers: map[string]*dynamic.RouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
|
@ -515,7 +515,7 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one router by id, but no config",
|
desc: "one router by id, but no config",
|
||||||
path: "/api/http/routers/foo@myprovider",
|
path: "/api/http/routers/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusNotFound,
|
statusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
|
@ -523,7 +523,7 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all services, but no config",
|
desc: "all services, but no config",
|
||||||
path: "/api/http/services",
|
path: "/api/http/services",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusOK,
|
statusCode: http.StatusOK,
|
||||||
nextPage: "1",
|
nextPage: "1",
|
||||||
|
@ -533,13 +533,13 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all services",
|
desc: "all services",
|
||||||
path: "/api/http/services",
|
path: "/api/http/services",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Services: map[string]*config.ServiceInfo{
|
Services: map[string]*dynamic.ServiceInfo{
|
||||||
"bar@myprovider": func() *config.ServiceInfo {
|
"bar@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
URL: "http://127.0.0.1",
|
||||||
},
|
},
|
||||||
|
@ -551,11 +551,11 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
si.UpdateStatus("http://127.0.0.1", "UP")
|
si.UpdateStatus("http://127.0.0.1", "UP")
|
||||||
return si
|
return si
|
||||||
}(),
|
}(),
|
||||||
"baz@myprovider": func() *config.ServiceInfo {
|
"baz@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.2",
|
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",
|
desc: "all services, 1 res per page, want page 2",
|
||||||
path: "/api/http/services?page=2&per_page=1",
|
path: "/api/http/services?page=2&per_page=1",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Services: map[string]*config.ServiceInfo{
|
Services: map[string]*dynamic.ServiceInfo{
|
||||||
"bar@myprovider": func() *config.ServiceInfo {
|
"bar@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
URL: "http://127.0.0.1",
|
||||||
},
|
},
|
||||||
|
@ -596,11 +596,11 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
si.UpdateStatus("http://127.0.0.1", "UP")
|
si.UpdateStatus("http://127.0.0.1", "UP")
|
||||||
return si
|
return si
|
||||||
}(),
|
}(),
|
||||||
"baz@myprovider": func() *config.ServiceInfo {
|
"baz@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.2",
|
URL: "http://127.0.0.2",
|
||||||
},
|
},
|
||||||
|
@ -612,11 +612,11 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
si.UpdateStatus("http://127.0.0.2", "UP")
|
si.UpdateStatus("http://127.0.0.2", "UP")
|
||||||
return si
|
return si
|
||||||
}(),
|
}(),
|
||||||
"test@myprovider": func() *config.ServiceInfo {
|
"test@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.3",
|
URL: "http://127.0.0.3",
|
||||||
},
|
},
|
||||||
|
@ -639,13 +639,13 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one service by id",
|
desc: "one service by id",
|
||||||
path: "/api/http/services/bar@myprovider",
|
path: "/api/http/services/bar@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Services: map[string]*config.ServiceInfo{
|
Services: map[string]*dynamic.ServiceInfo{
|
||||||
"bar@myprovider": func() *config.ServiceInfo {
|
"bar@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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",
|
desc: "one service by id, that does not exist",
|
||||||
path: "/api/http/services/nono@myprovider",
|
path: "/api/http/services/nono@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Services: map[string]*config.ServiceInfo{
|
Services: map[string]*dynamic.ServiceInfo{
|
||||||
"bar@myprovider": func() *config.ServiceInfo {
|
"bar@myprovider": func() *dynamic.ServiceInfo {
|
||||||
si := &config.ServiceInfo{
|
si := &dynamic.ServiceInfo{
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
URL: "http://127.0.0.1",
|
||||||
},
|
},
|
||||||
|
@ -694,7 +694,7 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one service by id, but no config",
|
desc: "one service by id, but no config",
|
||||||
path: "/api/http/services/foo@myprovider",
|
path: "/api/http/services/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusNotFound,
|
statusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
|
@ -702,7 +702,7 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all middlewares, but no config",
|
desc: "all middlewares, but no config",
|
||||||
path: "/api/http/middlewares",
|
path: "/api/http/middlewares",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusOK,
|
statusCode: http.StatusOK,
|
||||||
nextPage: "1",
|
nextPage: "1",
|
||||||
|
@ -712,27 +712,27 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all middlewares",
|
desc: "all middlewares",
|
||||||
path: "/api/http/middlewares",
|
path: "/api/http/middlewares",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Middlewares: map[string]*config.MiddlewareInfo{
|
Middlewares: map[string]*dynamic.MiddlewareInfo{
|
||||||
"auth@myprovider": {
|
"auth@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
||||||
},
|
},
|
||||||
"addPrefixTest@myprovider": {
|
"addPrefixTest@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/titi",
|
Prefix: "/titi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UsedBy: []string{"test@myprovider"},
|
UsedBy: []string{"test@myprovider"},
|
||||||
},
|
},
|
||||||
"addPrefixTest@anotherprovider": {
|
"addPrefixTest@anotherprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/toto",
|
Prefix: "/toto",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -749,27 +749,27 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "all middlewares, 1 res per page, want page 2",
|
desc: "all middlewares, 1 res per page, want page 2",
|
||||||
path: "/api/http/middlewares?page=2&per_page=1",
|
path: "/api/http/middlewares?page=2&per_page=1",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Middlewares: map[string]*config.MiddlewareInfo{
|
Middlewares: map[string]*dynamic.MiddlewareInfo{
|
||||||
"auth@myprovider": {
|
"auth@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
||||||
},
|
},
|
||||||
"addPrefixTest@myprovider": {
|
"addPrefixTest@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/titi",
|
Prefix: "/titi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UsedBy: []string{"test@myprovider"},
|
UsedBy: []string{"test@myprovider"},
|
||||||
},
|
},
|
||||||
"addPrefixTest@anotherprovider": {
|
"addPrefixTest@anotherprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/toto",
|
Prefix: "/toto",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -786,27 +786,27 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one middleware by id",
|
desc: "one middleware by id",
|
||||||
path: "/api/http/middlewares/auth@myprovider",
|
path: "/api/http/middlewares/auth@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Middlewares: map[string]*config.MiddlewareInfo{
|
Middlewares: map[string]*dynamic.MiddlewareInfo{
|
||||||
"auth@myprovider": {
|
"auth@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
UsedBy: []string{"bar@myprovider", "test@myprovider"},
|
||||||
},
|
},
|
||||||
"addPrefixTest@myprovider": {
|
"addPrefixTest@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/titi",
|
Prefix: "/titi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
UsedBy: []string{"test@myprovider"},
|
UsedBy: []string{"test@myprovider"},
|
||||||
},
|
},
|
||||||
"addPrefixTest@anotherprovider": {
|
"addPrefixTest@anotherprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/toto",
|
Prefix: "/toto",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -822,11 +822,11 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one middleware by id, that does not exist",
|
desc: "one middleware by id, that does not exist",
|
||||||
path: "/api/http/middlewares/foo@myprovider",
|
path: "/api/http/middlewares/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Middlewares: map[string]*config.MiddlewareInfo{
|
Middlewares: map[string]*dynamic.MiddlewareInfo{
|
||||||
"auth@myprovider": {
|
"auth@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -841,7 +841,7 @@ func TestHandlerHTTP_API(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "one middleware by id, but no config",
|
desc: "one middleware by id, but no config",
|
||||||
path: "/api/http/middlewares/foo@myprovider",
|
path: "/api/http/middlewares/foo@myprovider",
|
||||||
conf: config.RuntimeConfiguration{},
|
conf: dynamic.RuntimeConfiguration{},
|
||||||
expected: expected{
|
expected: expected{
|
||||||
statusCode: http.StatusNotFound,
|
statusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
|
@ -906,18 +906,18 @@ func TestHandler_Configuration(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
path string
|
path string
|
||||||
conf config.RuntimeConfiguration
|
conf dynamic.RuntimeConfiguration
|
||||||
expected expected
|
expected expected
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Get rawdata",
|
desc: "Get rawdata",
|
||||||
path: "/api/rawdata",
|
path: "/api/rawdata",
|
||||||
conf: config.RuntimeConfiguration{
|
conf: dynamic.RuntimeConfiguration{
|
||||||
Services: map[string]*config.ServiceInfo{
|
Services: map[string]*dynamic.ServiceInfo{
|
||||||
"foo-service@myprovider": {
|
"foo-service@myprovider": {
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"auth@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"addPrefixTest@myprovider": {
|
"addPrefixTest@myprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/titi",
|
Prefix: "/titi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"addPrefixTest@anotherprovider": {
|
"addPrefixTest@anotherprovider": {
|
||||||
Middleware: &config.Middleware{
|
Middleware: &dynamic.Middleware{
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/toto",
|
Prefix: "/toto",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Routers: map[string]*config.RouterInfo{
|
Routers: map[string]*dynamic.RouterInfo{
|
||||||
"bar@myprovider": {
|
"bar@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
|
@ -959,7 +959,7 @@ func TestHandler_Configuration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"test@myprovider": {
|
"test@myprovider": {
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar.other`)",
|
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": {
|
"tcpfoo-service@myprovider": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1",
|
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": {
|
"tcpbar@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "tcpfoo-service@myprovider",
|
Service: "tcpfoo-service@myprovider",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"tcptest@myprovider": {
|
"tcptest@myprovider": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "tcpfoo-service@myprovider",
|
Service: "tcpfoo-service@myprovider",
|
||||||
Rule: "HostSNI(`foo.bar.other`)",
|
Rule: "HostSNI(`foo.bar.other`)",
|
||||||
|
@ -1054,11 +1054,11 @@ func TestHandler_Configuration(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateHTTPRouters(nbRouters int) map[string]*config.RouterInfo {
|
func generateHTTPRouters(nbRouters int) map[string]*dynamic.RouterInfo {
|
||||||
routers := make(map[string]*config.RouterInfo, nbRouters)
|
routers := make(map[string]*dynamic.RouterInfo, nbRouters)
|
||||||
for i := 0; i < nbRouters; i++ {
|
for i := 0; i < nbRouters; i++ {
|
||||||
routers[fmt.Sprintf("bar%2d@myprovider", i)] = &config.RouterInfo{
|
routers[fmt.Sprintf("bar%2d@myprovider", i)] = &dynamic.RouterInfo{
|
||||||
Router: &config.Router{
|
Router: &dynamic.Router{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@myprovider",
|
Service: "foo-service@myprovider",
|
||||||
Rule: "Host(`foo.bar" + strconv.Itoa(i) + "`)",
|
Rule: "Host(`foo.bar" + strconv.Itoa(i) + "`)",
|
||||||
|
|
36
pkg/config/dynamic/config.go
Normal file
36
pkg/config/dynamic/config.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package dynamic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containous/traefik/pkg/tls"
|
||||||
|
)
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// Message holds configuration information exchanged between parts of traefik.
|
||||||
|
type Message struct {
|
||||||
|
ProviderName string
|
||||||
|
Configuration *Configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// Configurations is for currentConfigurations Map.
|
||||||
|
type Configurations map[string]*Configuration
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// Configuration is the root of the dynamic configuration
|
||||||
|
type Configuration struct {
|
||||||
|
HTTP *HTTPConfiguration `json:"http,omitempty" toml:"http,omitempty" yaml:"http,omitempty"`
|
||||||
|
TCP *TCPConfiguration `json:"tcp,omitempty" toml:"tcp,omitempty" yaml:"tcp,omitempty"`
|
||||||
|
TLS *TLSConfiguration `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// TLSConfiguration contains all the configuration parameters of a TLS connection.
|
||||||
|
type TLSConfiguration struct {
|
||||||
|
Certificates []*tls.CertAndStores `json:"-" toml:"certificates,omitempty" yaml:"certificates,omitempty" label:"-"`
|
||||||
|
Options map[string]tls.Options `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"`
|
||||||
|
Stores map[string]tls.Store `json:"stores,omitempty" toml:"stores,omitempty" yaml:"stores,omitempty"`
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package config
|
package dynamic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
|
@ -1,41 +1,6 @@
|
||||||
package config
|
package dynamic
|
||||||
|
|
||||||
import (
|
import "reflect"
|
||||||
"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"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// +k8s:deepcopy-gen=true
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
@ -48,14 +13,6 @@ type HTTPConfiguration struct {
|
||||||
|
|
||||||
// +k8s:deepcopy-gen=true
|
// +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).
|
// Service holds a service configuration (can only be of one type at the same time).
|
||||||
type Service struct {
|
type Service struct {
|
||||||
LoadBalancer *LoadBalancerService `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"`
|
LoadBalancer *LoadBalancerService `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"`
|
||||||
|
@ -63,13 +20,6 @@ type Service struct {
|
||||||
|
|
||||||
// +k8s:deepcopy-gen=true
|
// +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.
|
// Router holds the router configuration.
|
||||||
type Router struct {
|
type Router struct {
|
||||||
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty"`
|
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty"`
|
||||||
|
@ -89,24 +39,6 @@ type RouterTLSConfig struct {
|
||||||
|
|
||||||
// +k8s:deepcopy-gen=true
|
// +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.
|
// LoadBalancerService holds the LoadBalancerService configuration.
|
||||||
type LoadBalancerService struct {
|
type LoadBalancerService struct {
|
||||||
Stickiness *Stickiness `json:"stickiness,omitempty" toml:"stickiness,omitempty" yaml:"stickiness,omitempty" label:"allowEmpty"`
|
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"`
|
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.
|
// Mergeable tells if the given service is mergeable.
|
||||||
func (l *LoadBalancerService) Mergeable(loadBalancer *LoadBalancerService) bool {
|
func (l *LoadBalancerService) Mergeable(loadBalancer *LoadBalancerService) bool {
|
||||||
savedServers := l.Servers
|
savedServers := l.Servers
|
||||||
|
@ -187,14 +95,6 @@ type Server struct {
|
||||||
Port string `toml:"-" json:"-" yaml:"-"`
|
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.
|
// SetDefaults Default values for a Server.
|
||||||
func (s *Server) SetDefaults() {
|
func (s *Server) SetDefaults() {
|
||||||
s.Scheme = "http"
|
s.Scheme = "http"
|
|
@ -1,4 +1,4 @@
|
||||||
package config
|
package dynamic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
|
@ -1,4 +1,4 @@
|
||||||
package config
|
package dynamic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
File diff suppressed because it is too large
Load diff
68
pkg/config/dynamic/tcp_config.go
Normal file
68
pkg/config/dynamic/tcp_config.go
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
package dynamic
|
||||||
|
|
||||||
|
import "reflect"
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// TCPConfiguration contains all the TCP configuration parameters.
|
||||||
|
type TCPConfiguration struct {
|
||||||
|
Routers map[string]*TCPRouter `json:"routers,omitempty" toml:"routers,omitempty" yaml:"routers,omitempty"`
|
||||||
|
Services map[string]*TCPService `json:"services,omitempty" toml:"services,omitempty" yaml:"services,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// TCPService holds a tcp service configuration (can only be of one type at the same time).
|
||||||
|
type TCPService struct {
|
||||||
|
LoadBalancer *TCPLoadBalancerService `json:"loadBalancer,omitempty" toml:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// TCPRouter holds the router configuration.
|
||||||
|
type TCPRouter struct {
|
||||||
|
EntryPoints []string `json:"entryPoints,omitempty" toml:"entryPoints,omitempty" yaml:"entryPoints,omitempty"`
|
||||||
|
Service string `json:"service,omitempty" toml:"service,omitempty" yaml:"service,omitempty"`
|
||||||
|
Rule string `json:"rule,omitempty" toml:"rule,omitempty" yaml:"rule,omitempty"`
|
||||||
|
TLS *RouterTCPTLSConfig `json:"tls,omitempty" toml:"tls,omitempty" yaml:"tls,omitempty" label:"allowEmpty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// RouterTCPTLSConfig holds the TLS configuration for a router
|
||||||
|
type RouterTCPTLSConfig struct {
|
||||||
|
Passthrough bool `json:"passthrough" toml:"passthrough" yaml:"passthrough"`
|
||||||
|
Options string `json:"options,omitempty" toml:"options,omitempty" yaml:"options,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// TCPLoadBalancerService holds the LoadBalancerService configuration.
|
||||||
|
type TCPLoadBalancerService struct {
|
||||||
|
Servers []TCPServer `json:"servers,omitempty" toml:"servers,omitempty" yaml:"servers,omitempty" label-slice-as-struct:"server" label-slice-as-struct:"server"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mergeable tells if the given service is mergeable.
|
||||||
|
func (l *TCPLoadBalancerService) Mergeable(loadBalancer *TCPLoadBalancerService) bool {
|
||||||
|
savedServers := l.Servers
|
||||||
|
defer func() {
|
||||||
|
l.Servers = savedServers
|
||||||
|
}()
|
||||||
|
l.Servers = nil
|
||||||
|
|
||||||
|
savedServersLB := loadBalancer.Servers
|
||||||
|
defer func() {
|
||||||
|
loadBalancer.Servers = savedServersLB
|
||||||
|
}()
|
||||||
|
loadBalancer.Servers = nil
|
||||||
|
|
||||||
|
return reflect.DeepEqual(l, loadBalancer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// +k8s:deepcopy-gen=true
|
||||||
|
|
||||||
|
// TCPServer holds a TCP Server configuration
|
||||||
|
type TCPServer struct {
|
||||||
|
Address string `json:"address,omitempty" toml:"address,omitempty" yaml:"address,omitempty" label:"-"`
|
||||||
|
Port string `toml:"-" json:"-" yaml:"-"`
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
// Code generated by deepcopy-gen. DO NOT EDIT.
|
// Code generated by deepcopy-gen. DO NOT EDIT.
|
||||||
|
|
||||||
package config
|
package dynamic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
tls "github.com/containous/traefik/pkg/tls"
|
tls "github.com/containous/traefik/pkg/tls"
|
|
@ -2,15 +2,15 @@
|
||||||
package label
|
package label
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/config/parser"
|
"github.com/containous/traefik/pkg/config/parser"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DecodeConfiguration converts the labels to a configuration.
|
// DecodeConfiguration converts the labels to a configuration.
|
||||||
func DecodeConfiguration(labels map[string]string) (*config.Configuration, error) {
|
func DecodeConfiguration(labels map[string]string) (*dynamic.Configuration, error) {
|
||||||
conf := &config.Configuration{
|
conf := &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{},
|
HTTP: &dynamic.HTTPConfiguration{},
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := parser.Decode(labels, conf, parser.DefaultRootName, "traefik.http", "traefik.tcp")
|
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.
|
// 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)
|
return parser.Encode(conf, parser.DefaultRootName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"github.com/containous/traefik/pkg/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -175,9 +175,9 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
configuration, err := DecodeConfiguration(labels)
|
configuration, err := DecodeConfiguration(labels)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := &config.Configuration{
|
expected := &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{
|
Routers: map[string]*dynamic.TCPRouter{
|
||||||
"Router0": {
|
"Router0": {
|
||||||
EntryPoints: []string{
|
EntryPoints: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
|
@ -185,7 +185,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
Service: "foobar",
|
Service: "foobar",
|
||||||
Rule: "foobar",
|
Rule: "foobar",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
Options: "foo",
|
Options: "foo",
|
||||||
},
|
},
|
||||||
|
@ -197,16 +197,16 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
Service: "foobar",
|
Service: "foobar",
|
||||||
Rule: "foobar",
|
Rule: "foobar",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
Options: "foo",
|
Options: "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"Service0": {
|
"Service0": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Port: "42",
|
Port: "42",
|
||||||
},
|
},
|
||||||
|
@ -214,8 +214,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Service1": {
|
"Service1": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Port: "42",
|
Port: "42",
|
||||||
},
|
},
|
||||||
|
@ -224,8 +224,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Router0": {
|
"Router0": {
|
||||||
EntryPoints: []string{
|
EntryPoints: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
|
@ -238,7 +238,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
Service: "foobar",
|
Service: "foobar",
|
||||||
Rule: "foobar",
|
Rule: "foobar",
|
||||||
Priority: 42,
|
Priority: 42,
|
||||||
TLS: &config.RouterTLSConfig{},
|
TLS: &dynamic.RouterTLSConfig{},
|
||||||
},
|
},
|
||||||
"Router1": {
|
"Router1": {
|
||||||
EntryPoints: []string{
|
EntryPoints: []string{
|
||||||
|
@ -254,14 +254,14 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
Priority: 42,
|
Priority: 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"Middleware0": {
|
"Middleware0": {
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "foobar",
|
Prefix: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware1": {
|
"Middleware1": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{
|
Users: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -273,18 +273,18 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware10": {
|
"Middleware10": {
|
||||||
MaxConn: &config.MaxConn{
|
MaxConn: &dynamic.MaxConn{
|
||||||
Amount: 42,
|
Amount: 42,
|
||||||
ExtractorFunc: "foobar",
|
ExtractorFunc: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware11": {
|
"Middleware11": {
|
||||||
PassTLSClientCert: &config.PassTLSClientCert{
|
PassTLSClientCert: &dynamic.PassTLSClientCert{
|
||||||
PEM: true,
|
PEM: true,
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
NotAfter: true,
|
NotAfter: true,
|
||||||
NotBefore: true,
|
NotBefore: true,
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -293,7 +293,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
SerialNumber: true,
|
SerialNumber: true,
|
||||||
DomainComponent: true,
|
DomainComponent: true,
|
||||||
},
|
},
|
||||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -307,8 +307,8 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware12": {
|
"Middleware12": {
|
||||||
RateLimit: &config.RateLimit{
|
RateLimit: &dynamic.RateLimit{
|
||||||
RateSet: map[string]*config.Rate{
|
RateSet: map[string]*dynamic.Rate{
|
||||||
"Rate0": {
|
"Rate0": {
|
||||||
Period: types.Duration(42 * time.Second),
|
Period: types.Duration(42 * time.Second),
|
||||||
Average: 42,
|
Average: 42,
|
||||||
|
@ -324,37 +324,37 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware13": {
|
"Middleware13": {
|
||||||
RedirectRegex: &config.RedirectRegex{
|
RedirectRegex: &dynamic.RedirectRegex{
|
||||||
Regex: "foobar",
|
Regex: "foobar",
|
||||||
Replacement: "foobar",
|
Replacement: "foobar",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware13b": {
|
"Middleware13b": {
|
||||||
RedirectScheme: &config.RedirectScheme{
|
RedirectScheme: &dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Port: "80",
|
Port: "80",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware14": {
|
"Middleware14": {
|
||||||
ReplacePath: &config.ReplacePath{
|
ReplacePath: &dynamic.ReplacePath{
|
||||||
Path: "foobar",
|
Path: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware15": {
|
"Middleware15": {
|
||||||
ReplacePathRegex: &config.ReplacePathRegex{
|
ReplacePathRegex: &dynamic.ReplacePathRegex{
|
||||||
Regex: "foobar",
|
Regex: "foobar",
|
||||||
Replacement: "foobar",
|
Replacement: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware16": {
|
"Middleware16": {
|
||||||
Retry: &config.Retry{
|
Retry: &dynamic.Retry{
|
||||||
Attempts: 42,
|
Attempts: 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware17": {
|
"Middleware17": {
|
||||||
StripPrefix: &config.StripPrefix{
|
StripPrefix: &dynamic.StripPrefix{
|
||||||
Prefixes: []string{
|
Prefixes: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -362,7 +362,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware18": {
|
"Middleware18": {
|
||||||
StripPrefixRegex: &config.StripPrefixRegex{
|
StripPrefixRegex: &dynamic.StripPrefixRegex{
|
||||||
Regex: []string{
|
Regex: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -370,10 +370,10 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware19": {
|
"Middleware19": {
|
||||||
Compress: &config.Compress{},
|
Compress: &dynamic.Compress{},
|
||||||
},
|
},
|
||||||
"Middleware2": {
|
"Middleware2": {
|
||||||
Buffering: &config.Buffering{
|
Buffering: &dynamic.Buffering{
|
||||||
MaxRequestBodyBytes: 42,
|
MaxRequestBodyBytes: 42,
|
||||||
MemRequestBodyBytes: 42,
|
MemRequestBodyBytes: 42,
|
||||||
MaxResponseBodyBytes: 42,
|
MaxResponseBodyBytes: 42,
|
||||||
|
@ -382,7 +382,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware3": {
|
"Middleware3": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{
|
Middlewares: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -390,12 +390,12 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware4": {
|
"Middleware4": {
|
||||||
CircuitBreaker: &config.CircuitBreaker{
|
CircuitBreaker: &dynamic.CircuitBreaker{
|
||||||
Expression: "foobar",
|
Expression: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware5": {
|
"Middleware5": {
|
||||||
DigestAuth: &config.DigestAuth{
|
DigestAuth: &dynamic.DigestAuth{
|
||||||
Users: []string{
|
Users: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -407,7 +407,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware6": {
|
"Middleware6": {
|
||||||
Errors: &config.ErrorPage{
|
Errors: &dynamic.ErrorPage{
|
||||||
Status: []string{
|
Status: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -417,9 +417,9 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware7": {
|
"Middleware7": {
|
||||||
ForwardAuth: &config.ForwardAuth{
|
ForwardAuth: &dynamic.ForwardAuth{
|
||||||
Address: "foobar",
|
Address: "foobar",
|
||||||
TLS: &config.ClientTLS{
|
TLS: &dynamic.ClientTLS{
|
||||||
CA: "foobar",
|
CA: "foobar",
|
||||||
CAOptional: true,
|
CAOptional: true,
|
||||||
Cert: "foobar",
|
Cert: "foobar",
|
||||||
|
@ -434,7 +434,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware8": {
|
"Middleware8": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{
|
CustomRequestHeaders: map[string]string{
|
||||||
"name0": "foobar",
|
"name0": "foobar",
|
||||||
"name1": "foobar",
|
"name1": "foobar",
|
||||||
|
@ -491,12 +491,12 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware9": {
|
"Middleware9": {
|
||||||
IPWhiteList: &config.IPWhiteList{
|
IPWhiteList: &dynamic.IPWhiteList{
|
||||||
SourceRange: []string{
|
SourceRange: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
},
|
},
|
||||||
IPStrategy: &config.IPStrategy{
|
IPStrategy: &dynamic.IPStrategy{
|
||||||
Depth: 42,
|
Depth: 42,
|
||||||
ExcludedIPs: []string{
|
ExcludedIPs: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
|
@ -506,21 +506,21 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Service0": {
|
"Service0": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{
|
Stickiness: &dynamic.Stickiness{
|
||||||
CookieName: "foobar",
|
CookieName: "foobar",
|
||||||
SecureCookie: true,
|
SecureCookie: true,
|
||||||
HTTPOnlyCookie: false,
|
HTTPOnlyCookie: false,
|
||||||
},
|
},
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Port: "8080",
|
Port: "8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HealthCheck: &config.HealthCheck{
|
HealthCheck: &dynamic.HealthCheck{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Path: "foobar",
|
Path: "foobar",
|
||||||
Port: 42,
|
Port: 42,
|
||||||
|
@ -533,20 +533,20 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
ResponseForwarding: &config.ResponseForwarding{
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||||
FlushInterval: "foobar",
|
FlushInterval: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Service1": {
|
"Service1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Port: "8080",
|
Port: "8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HealthCheck: &config.HealthCheck{
|
HealthCheck: &dynamic.HealthCheck{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Path: "foobar",
|
Path: "foobar",
|
||||||
Port: 42,
|
Port: 42,
|
||||||
|
@ -559,7 +559,7 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
ResponseForwarding: &config.ResponseForwarding{
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||||
FlushInterval: "foobar",
|
FlushInterval: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -572,9 +572,9 @@ func TestDecodeConfiguration(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEncodeConfiguration(t *testing.T) {
|
func TestEncodeConfiguration(t *testing.T) {
|
||||||
configuration := &config.Configuration{
|
configuration := &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{
|
Routers: map[string]*dynamic.TCPRouter{
|
||||||
"Router0": {
|
"Router0": {
|
||||||
EntryPoints: []string{
|
EntryPoints: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
|
@ -582,7 +582,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
Service: "foobar",
|
Service: "foobar",
|
||||||
Rule: "foobar",
|
Rule: "foobar",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
Options: "foo",
|
Options: "foo",
|
||||||
},
|
},
|
||||||
|
@ -594,16 +594,16 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
Service: "foobar",
|
Service: "foobar",
|
||||||
Rule: "foobar",
|
Rule: "foobar",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
Options: "foo",
|
Options: "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"Service0": {
|
"Service0": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Port: "42",
|
Port: "42",
|
||||||
},
|
},
|
||||||
|
@ -611,8 +611,8 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Service1": {
|
"Service1": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Port: "42",
|
Port: "42",
|
||||||
},
|
},
|
||||||
|
@ -621,8 +621,8 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Router0": {
|
"Router0": {
|
||||||
EntryPoints: []string{
|
EntryPoints: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
|
@ -635,7 +635,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
Service: "foobar",
|
Service: "foobar",
|
||||||
Rule: "foobar",
|
Rule: "foobar",
|
||||||
Priority: 42,
|
Priority: 42,
|
||||||
TLS: &config.RouterTLSConfig{},
|
TLS: &dynamic.RouterTLSConfig{},
|
||||||
},
|
},
|
||||||
"Router1": {
|
"Router1": {
|
||||||
EntryPoints: []string{
|
EntryPoints: []string{
|
||||||
|
@ -651,14 +651,14 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
Priority: 42,
|
Priority: 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"Middleware0": {
|
"Middleware0": {
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "foobar",
|
Prefix: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware1": {
|
"Middleware1": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{
|
Users: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -670,18 +670,18 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware10": {
|
"Middleware10": {
|
||||||
MaxConn: &config.MaxConn{
|
MaxConn: &dynamic.MaxConn{
|
||||||
Amount: 42,
|
Amount: 42,
|
||||||
ExtractorFunc: "foobar",
|
ExtractorFunc: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware11": {
|
"Middleware11": {
|
||||||
PassTLSClientCert: &config.PassTLSClientCert{
|
PassTLSClientCert: &dynamic.PassTLSClientCert{
|
||||||
PEM: true,
|
PEM: true,
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
NotAfter: true,
|
NotAfter: true,
|
||||||
NotBefore: true,
|
NotBefore: true,
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -690,7 +690,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
SerialNumber: true,
|
SerialNumber: true,
|
||||||
DomainComponent: true,
|
DomainComponent: true,
|
||||||
},
|
},
|
||||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -703,8 +703,8 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware12": {
|
"Middleware12": {
|
||||||
RateLimit: &config.RateLimit{
|
RateLimit: &dynamic.RateLimit{
|
||||||
RateSet: map[string]*config.Rate{
|
RateSet: map[string]*dynamic.Rate{
|
||||||
"Rate0": {
|
"Rate0": {
|
||||||
Period: types.Duration(42 * time.Nanosecond),
|
Period: types.Duration(42 * time.Nanosecond),
|
||||||
Average: 42,
|
Average: 42,
|
||||||
|
@ -720,37 +720,37 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware13": {
|
"Middleware13": {
|
||||||
RedirectRegex: &config.RedirectRegex{
|
RedirectRegex: &dynamic.RedirectRegex{
|
||||||
Regex: "foobar",
|
Regex: "foobar",
|
||||||
Replacement: "foobar",
|
Replacement: "foobar",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware13b": {
|
"Middleware13b": {
|
||||||
RedirectScheme: &config.RedirectScheme{
|
RedirectScheme: &dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Port: "80",
|
Port: "80",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware14": {
|
"Middleware14": {
|
||||||
ReplacePath: &config.ReplacePath{
|
ReplacePath: &dynamic.ReplacePath{
|
||||||
Path: "foobar",
|
Path: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware15": {
|
"Middleware15": {
|
||||||
ReplacePathRegex: &config.ReplacePathRegex{
|
ReplacePathRegex: &dynamic.ReplacePathRegex{
|
||||||
Regex: "foobar",
|
Regex: "foobar",
|
||||||
Replacement: "foobar",
|
Replacement: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware16": {
|
"Middleware16": {
|
||||||
Retry: &config.Retry{
|
Retry: &dynamic.Retry{
|
||||||
Attempts: 42,
|
Attempts: 42,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware17": {
|
"Middleware17": {
|
||||||
StripPrefix: &config.StripPrefix{
|
StripPrefix: &dynamic.StripPrefix{
|
||||||
Prefixes: []string{
|
Prefixes: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -758,7 +758,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware18": {
|
"Middleware18": {
|
||||||
StripPrefixRegex: &config.StripPrefixRegex{
|
StripPrefixRegex: &dynamic.StripPrefixRegex{
|
||||||
Regex: []string{
|
Regex: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -766,10 +766,10 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware19": {
|
"Middleware19": {
|
||||||
Compress: &config.Compress{},
|
Compress: &dynamic.Compress{},
|
||||||
},
|
},
|
||||||
"Middleware2": {
|
"Middleware2": {
|
||||||
Buffering: &config.Buffering{
|
Buffering: &dynamic.Buffering{
|
||||||
MaxRequestBodyBytes: 42,
|
MaxRequestBodyBytes: 42,
|
||||||
MemRequestBodyBytes: 42,
|
MemRequestBodyBytes: 42,
|
||||||
MaxResponseBodyBytes: 42,
|
MaxResponseBodyBytes: 42,
|
||||||
|
@ -778,7 +778,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware3": {
|
"Middleware3": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{
|
Middlewares: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -786,12 +786,12 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware4": {
|
"Middleware4": {
|
||||||
CircuitBreaker: &config.CircuitBreaker{
|
CircuitBreaker: &dynamic.CircuitBreaker{
|
||||||
Expression: "foobar",
|
Expression: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware5": {
|
"Middleware5": {
|
||||||
DigestAuth: &config.DigestAuth{
|
DigestAuth: &dynamic.DigestAuth{
|
||||||
Users: []string{
|
Users: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -803,7 +803,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware6": {
|
"Middleware6": {
|
||||||
Errors: &config.ErrorPage{
|
Errors: &dynamic.ErrorPage{
|
||||||
Status: []string{
|
Status: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
|
@ -813,9 +813,9 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware7": {
|
"Middleware7": {
|
||||||
ForwardAuth: &config.ForwardAuth{
|
ForwardAuth: &dynamic.ForwardAuth{
|
||||||
Address: "foobar",
|
Address: "foobar",
|
||||||
TLS: &config.ClientTLS{
|
TLS: &dynamic.ClientTLS{
|
||||||
CA: "foobar",
|
CA: "foobar",
|
||||||
CAOptional: true,
|
CAOptional: true,
|
||||||
Cert: "foobar",
|
Cert: "foobar",
|
||||||
|
@ -830,7 +830,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware8": {
|
"Middleware8": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{
|
CustomRequestHeaders: map[string]string{
|
||||||
"name0": "foobar",
|
"name0": "foobar",
|
||||||
"name1": "foobar",
|
"name1": "foobar",
|
||||||
|
@ -887,12 +887,12 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Middleware9": {
|
"Middleware9": {
|
||||||
IPWhiteList: &config.IPWhiteList{
|
IPWhiteList: &dynamic.IPWhiteList{
|
||||||
SourceRange: []string{
|
SourceRange: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
"fiibar",
|
"fiibar",
|
||||||
},
|
},
|
||||||
IPStrategy: &config.IPStrategy{
|
IPStrategy: &dynamic.IPStrategy{
|
||||||
Depth: 42,
|
Depth: 42,
|
||||||
ExcludedIPs: []string{
|
ExcludedIPs: []string{
|
||||||
"foobar",
|
"foobar",
|
||||||
|
@ -902,20 +902,20 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Service0": {
|
"Service0": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{
|
Stickiness: &dynamic.Stickiness{
|
||||||
CookieName: "foobar",
|
CookieName: "foobar",
|
||||||
HTTPOnlyCookie: true,
|
HTTPOnlyCookie: true,
|
||||||
},
|
},
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Port: "8080",
|
Port: "8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HealthCheck: &config.HealthCheck{
|
HealthCheck: &dynamic.HealthCheck{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Path: "foobar",
|
Path: "foobar",
|
||||||
Port: 42,
|
Port: 42,
|
||||||
|
@ -928,20 +928,20 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
ResponseForwarding: &config.ResponseForwarding{
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||||
FlushInterval: "foobar",
|
FlushInterval: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Service1": {
|
"Service1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Port: "8080",
|
Port: "8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HealthCheck: &config.HealthCheck{
|
HealthCheck: &dynamic.HealthCheck{
|
||||||
Scheme: "foobar",
|
Scheme: "foobar",
|
||||||
Path: "foobar",
|
Path: "foobar",
|
||||||
Port: 42,
|
Port: 42,
|
||||||
|
@ -954,7 +954,7 @@ func TestEncodeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
ResponseForwarding: &config.ResponseForwarding{
|
ResponseForwarding: &dynamic.ResponseForwarding{
|
||||||
FlushInterval: "foobar",
|
FlushInterval: "foobar",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"github.com/containous/traefik/pkg/safe"
|
||||||
"github.com/go-kit/kit/metrics"
|
"github.com/go-kit/kit/metrics"
|
||||||
|
@ -229,7 +229,7 @@ func checkHealth(serverURL *url.URL, backend *BackendConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLBStatusUpdater returns a new LbStatusUpdater
|
// NewLBStatusUpdater returns a new LbStatusUpdater
|
||||||
func NewLBStatusUpdater(bh BalancerHandler, svinfo *config.ServiceInfo) *LbStatusUpdater {
|
func NewLBStatusUpdater(bh BalancerHandler, svinfo *dynamic.ServiceInfo) *LbStatusUpdater {
|
||||||
return &LbStatusUpdater{
|
return &LbStatusUpdater{
|
||||||
BalancerHandler: bh,
|
BalancerHandler: bh,
|
||||||
serviceInfo: svinfo,
|
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.
|
// so it can keep track of the status of a server in the ServiceInfo.
|
||||||
type LbStatusUpdater struct {
|
type LbStatusUpdater struct {
|
||||||
BalancerHandler
|
BalancerHandler
|
||||||
serviceInfo *config.ServiceInfo // can be nil
|
serviceInfo *dynamic.ServiceInfo // can be nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveServer removes the given server from the BalancerHandler,
|
// RemoveServer removes the given server from the BalancerHandler,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/testhelpers"
|
"github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -443,7 +443,7 @@ func (th *testHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func TestLBStatusUpdater(t *testing.T) {
|
func TestLBStatusUpdater(t *testing.T) {
|
||||||
lb := &testLoadBalancer{RWMutex: &sync.RWMutex{}}
|
lb := &testLoadBalancer{RWMutex: &sync.RWMutex{}}
|
||||||
svInfo := &config.ServiceInfo{}
|
svInfo := &dynamic.ServiceInfo{}
|
||||||
lbsu := NewLBStatusUpdater(lb, svInfo)
|
lbsu := NewLBStatusUpdater(lb, svInfo)
|
||||||
newServer, err := url.Parse("http://foo.com")
|
newServer, err := url.Parse("http://foo.com")
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/containous/mux"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"github.com/containous/traefik/pkg/safe"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"github.com/containous/traefik/pkg/types"
|
||||||
|
@ -189,7 +189,7 @@ func registerPromState(ctx context.Context) bool {
|
||||||
// OnConfigurationUpdate receives the current configuration from Traefik.
|
// OnConfigurationUpdate receives the current configuration from Traefik.
|
||||||
// It then converts the configuration to the optimized package internal format
|
// It then converts the configuration to the optimized package internal format
|
||||||
// and sets it to the promState.
|
// and sets it to the promState.
|
||||||
func OnConfigurationUpdate(configurations config.Configurations) {
|
func OnConfigurationUpdate(configurations dynamic.Configurations) {
|
||||||
dynamicConfig := newDynamicConfig()
|
dynamicConfig := newDynamicConfig()
|
||||||
|
|
||||||
// FIXME metrics
|
// FIXME metrics
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
th "github.com/containous/traefik/pkg/testhelpers"
|
th "github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"github.com/containous/traefik/pkg/types"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -276,8 +276,8 @@ func TestPrometheusMetricRemoval(t *testing.T) {
|
||||||
prometheusRegistry := RegisterPrometheus(context.Background(), &types.Prometheus{})
|
prometheusRegistry := RegisterPrometheus(context.Background(), &types.Prometheus{})
|
||||||
defer prometheus.Unregister(promState)
|
defer prometheus.Unregister(promState)
|
||||||
|
|
||||||
configurations := make(config.Configurations)
|
configurations := make(dynamic.Configurations)
|
||||||
configurations["providerName"] = &config.Configuration{
|
configurations["providerName"] = &dynamic.Configuration{
|
||||||
HTTP: th.BuildConfiguration(
|
HTTP: th.BuildConfiguration(
|
||||||
th.WithRouters(
|
th.WithRouters(
|
||||||
th.WithRouter("foo",
|
th.WithRouter("foo",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -23,7 +23,7 @@ type addPrefix struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new handler.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
var result *addPrefix
|
var result *addPrefix
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -15,16 +15,16 @@ import (
|
||||||
func TestNewAddPrefix(t *testing.T) {
|
func TestNewAddPrefix(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
prefix config.AddPrefix
|
prefix dynamic.AddPrefix
|
||||||
expectsError bool
|
expectsError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Works with a non empty prefix",
|
desc: "Works with a non empty prefix",
|
||||||
prefix: config.AddPrefix{Prefix: "/a"},
|
prefix: dynamic.AddPrefix{Prefix: "/a"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Fails if prefix is empty",
|
desc: "Fails if prefix is empty",
|
||||||
prefix: config.AddPrefix{Prefix: ""},
|
prefix: dynamic.AddPrefix{Prefix: ""},
|
||||||
expectsError: true,
|
expectsError: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -50,20 +50,20 @@ func TestAddPrefix(t *testing.T) {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
prefix config.AddPrefix
|
prefix dynamic.AddPrefix
|
||||||
path string
|
path string
|
||||||
expectedPath string
|
expectedPath string
|
||||||
expectedRawPath string
|
expectedRawPath string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Works with a regular path",
|
desc: "Works with a regular path",
|
||||||
prefix: config.AddPrefix{Prefix: "/a"},
|
prefix: dynamic.AddPrefix{Prefix: "/a"},
|
||||||
path: "/b",
|
path: "/b",
|
||||||
expectedPath: "/a/b",
|
expectedPath: "/a/b",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Works with a raw path",
|
desc: "Works with a raw path",
|
||||||
prefix: config.AddPrefix{Prefix: "/a"},
|
prefix: dynamic.AddPrefix{Prefix: "/a"},
|
||||||
path: "/b%2Fc",
|
path: "/b%2Fc",
|
||||||
expectedPath: "/a/b/c",
|
expectedPath: "/a/b/c",
|
||||||
expectedRawPath: "/a/b%2Fc",
|
expectedRawPath: "/a/b%2Fc",
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
goauth "github.com/abbot/go-http-auth"
|
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"
|
||||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
|
@ -29,7 +29,7 @@ type basicAuth struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBasic creates a basicAuth middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, basicTypeName).Debug("Creating middleware")
|
||||||
users, err := getUsers(authConfig.UsersFile, authConfig.Users, basicUserParser)
|
users, err := getUsers(authConfig.UsersFile, authConfig.Users, basicUserParser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -20,13 +20,13 @@ func TestBasicAuthFail(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.BasicAuth{
|
auth := dynamic.BasicAuth{
|
||||||
Users: []string{"test"},
|
Users: []string{"test"},
|
||||||
}
|
}
|
||||||
_, err := NewBasic(context.Background(), next, auth, "authName")
|
_, err := NewBasic(context.Background(), next, auth, "authName")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
auth2 := config.BasicAuth{
|
auth2 := dynamic.BasicAuth{
|
||||||
Users: []string{"test:test"},
|
Users: []string{"test:test"},
|
||||||
}
|
}
|
||||||
authMiddleware, err := NewBasic(context.Background(), next, auth2, "authTest")
|
authMiddleware, err := NewBasic(context.Background(), next, auth2, "authTest")
|
||||||
|
@ -49,7 +49,7 @@ func TestBasicAuthSuccess(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.BasicAuth{
|
auth := dynamic.BasicAuth{
|
||||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||||
}
|
}
|
||||||
authMiddleware, err := NewBasic(context.Background(), next, auth, "authName")
|
authMiddleware, err := NewBasic(context.Background(), next, auth, "authName")
|
||||||
|
@ -79,7 +79,7 @@ func TestBasicAuthUserHeader(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.BasicAuth{
|
auth := dynamic.BasicAuth{
|
||||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||||
HeaderField: "X-Webauth-User",
|
HeaderField: "X-Webauth-User",
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ func TestBasicAuthHeaderRemoved(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.BasicAuth{
|
auth := dynamic.BasicAuth{
|
||||||
RemoveHeader: true,
|
RemoveHeader: true,
|
||||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func TestBasicAuthHeaderPresent(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.BasicAuth{
|
auth := dynamic.BasicAuth{
|
||||||
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
Users: []string{"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/"},
|
||||||
}
|
}
|
||||||
middleware, err := NewBasic(context.Background(), next, auth, "authName")
|
middleware, err := NewBasic(context.Background(), next, auth, "authName")
|
||||||
|
@ -226,7 +226,7 @@ func TestBasicAuthUsersFromFile(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Creates the configuration for our Authenticator
|
// Creates the configuration for our Authenticator
|
||||||
authenticatorConfiguration := config.BasicAuth{
|
authenticatorConfiguration := dynamic.BasicAuth{
|
||||||
Users: test.givenUsers,
|
Users: test.givenUsers,
|
||||||
UsersFile: usersFile.Name(),
|
UsersFile: usersFile.Name(),
|
||||||
Realm: test.realm,
|
Realm: test.realm,
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
goauth "github.com/abbot/go-http-auth"
|
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"
|
||||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
|
@ -29,7 +29,7 @@ type digestAuth struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDigest creates a digest auth middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, digestTypeName).Debug("Creating middleware")
|
||||||
users, err := getUsers(authConfig.UsersFile, authConfig.Users, digestUserParser)
|
users, err := getUsers(authConfig.UsersFile, authConfig.Users, digestUserParser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -20,7 +20,7 @@ func TestDigestAuthError(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.DigestAuth{
|
auth := dynamic.DigestAuth{
|
||||||
Users: []string{"test"},
|
Users: []string{"test"},
|
||||||
}
|
}
|
||||||
_, err := NewDigest(context.Background(), next, auth, "authName")
|
_, err := NewDigest(context.Background(), next, auth, "authName")
|
||||||
|
@ -32,7 +32,7 @@ func TestDigestAuthFail(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.DigestAuth{
|
auth := dynamic.DigestAuth{
|
||||||
Users: []string{"test:traefik:a2688e031edb4be6a3797f3882655c05"},
|
Users: []string{"test:traefik:a2688e031edb4be6a3797f3882655c05"},
|
||||||
}
|
}
|
||||||
authMiddleware, err := NewDigest(context.Background(), next, auth, "authName")
|
authMiddleware, err := NewDigest(context.Background(), next, auth, "authName")
|
||||||
|
@ -101,7 +101,7 @@ func TestDigestAuthUsersFromFile(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
// Creates the configuration for our Authenticator
|
// Creates the configuration for our Authenticator
|
||||||
authenticatorConfiguration := config.DigestAuth{
|
authenticatorConfiguration := dynamic.DigestAuth{
|
||||||
Users: test.givenUsers,
|
Users: test.givenUsers,
|
||||||
UsersFile: usersFile.Name(),
|
UsersFile: usersFile.Name(),
|
||||||
Realm: test.realm,
|
Realm: test.realm,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -33,7 +33,7 @@ type forwardAuth struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewForward creates a forward auth middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, forwardedTypeName).Debug("Creating middleware")
|
||||||
|
|
||||||
fa := &forwardAuth{
|
fa := &forwardAuth{
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -25,7 +25,7 @@ func TestForwardAuthFail(t *testing.T) {
|
||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
middleware, err := NewForward(context.Background(), next, config.ForwardAuth{
|
middleware, err := NewForward(context.Background(), next, dynamic.ForwardAuth{
|
||||||
Address: server.URL,
|
Address: server.URL,
|
||||||
}, "authTest")
|
}, "authTest")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -63,7 +63,7 @@ func TestForwardAuthSuccess(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.ForwardAuth{
|
auth := dynamic.ForwardAuth{
|
||||||
Address: server.URL,
|
Address: server.URL,
|
||||||
AuthResponseHeaders: []string{"X-Auth-User", "X-Auth-Group"},
|
AuthResponseHeaders: []string{"X-Auth-User", "X-Auth-Group"},
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ func TestForwardAuthRedirect(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.ForwardAuth{
|
auth := dynamic.ForwardAuth{
|
||||||
Address: authTs.URL,
|
Address: authTs.URL,
|
||||||
}
|
}
|
||||||
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
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) {
|
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
auth := config.ForwardAuth{
|
auth := dynamic.ForwardAuth{
|
||||||
Address: authTs.URL,
|
Address: authTs.URL,
|
||||||
}
|
}
|
||||||
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
||||||
|
@ -193,7 +193,7 @@ func TestForwardAuthFailResponseHeaders(t *testing.T) {
|
||||||
fmt.Fprintln(w, "traefik")
|
fmt.Fprintln(w, "traefik")
|
||||||
})
|
})
|
||||||
|
|
||||||
auth := config.ForwardAuth{
|
auth := dynamic.ForwardAuth{
|
||||||
Address: authTs.URL,
|
Address: authTs.URL,
|
||||||
}
|
}
|
||||||
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
authMiddleware, err := NewForward(context.Background(), next, auth, "authTest")
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -21,7 +21,7 @@ type buffer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a buffering middleware.
|
// 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 := middlewares.GetLogger(ctx, name, typeName)
|
||||||
logger.Debug("Creating middleware")
|
logger.Debug("Creating middleware")
|
||||||
logger.Debug("Setting up buffering: request limits: %d (mem), %d (max), response limits: %d (mem), %d (max) with retry: '%s'",
|
logger.Debug("Setting up buffering: request limits: %d (mem), %d (max), response limits: %d (mem), %d (max) with retry: '%s'",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containous/alice"
|
"github.com/containous/alice"
|
||||||
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ type chainBuilder interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a chain middleware
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
middlewareChain := builder.BuildChain(ctx, config.Middlewares)
|
middlewareChain := builder.BuildChain(ctx, config.Middlewares)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/middlewares"
|
"github.com/containous/traefik/pkg/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
|
@ -22,7 +22,7 @@ type circuitBreaker struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new circuit breaker middleware.
|
// 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
|
expression := confCircuitBreaker.Expression
|
||||||
|
|
||||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"github.com/containous/traefik/pkg/types"
|
||||||
|
@ -42,7 +42,7 @@ type customErrors struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new custom error pages middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
httpCodeRanges, err := types.NewHTTPCodeRanges(config.Status)
|
httpCodeRanges, err := types.NewHTTPCodeRanges(config.Status)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/testhelpers"
|
"github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -17,14 +17,14 @@ import (
|
||||||
func TestHandler(t *testing.T) {
|
func TestHandler(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
errorPage *config.ErrorPage
|
errorPage *dynamic.ErrorPage
|
||||||
backendCode int
|
backendCode int
|
||||||
backendErrorHandler http.HandlerFunc
|
backendErrorHandler http.HandlerFunc
|
||||||
validate func(t *testing.T, recorder *httptest.ResponseRecorder)
|
validate func(t *testing.T, recorder *httptest.ResponseRecorder)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "no error",
|
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,
|
backendCode: http.StatusOK,
|
||||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "My error page.")
|
fmt.Fprintln(w, "My error page.")
|
||||||
|
@ -36,7 +36,7 @@ func TestHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "in the range",
|
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,
|
backendCode: http.StatusInternalServerError,
|
||||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "My error page.")
|
fmt.Fprintln(w, "My error page.")
|
||||||
|
@ -49,7 +49,7 @@ func TestHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "not in the range",
|
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,
|
backendCode: http.StatusBadGateway,
|
||||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "My error page.")
|
fmt.Fprintln(w, "My error page.")
|
||||||
|
@ -62,7 +62,7 @@ func TestHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "query replacement",
|
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,
|
backendCode: http.StatusServiceUnavailable,
|
||||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.RequestURI == "/503" {
|
if r.RequestURI == "/503" {
|
||||||
|
@ -79,7 +79,7 @@ func TestHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Single code",
|
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,
|
backendCode: http.StatusServiceUnavailable,
|
||||||
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
backendErrorHandler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.RequestURI == "/503" {
|
if r.RequestURI == "/503" {
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -26,7 +26,7 @@ type headers struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a Headers middleware.
|
// 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
|
// HeaderMiddleware -> SecureMiddleWare -> next
|
||||||
logger := middlewares.GetLogger(ctx, name, typeName)
|
logger := middlewares.GetLogger(ctx, name, typeName)
|
||||||
logger.Debug("Creating middleware")
|
logger.Debug("Creating middleware")
|
||||||
|
@ -73,7 +73,7 @@ type secureHeader struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newSecure constructs a new secure instance with supplied options.
|
// 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{
|
opt := secure.Options{
|
||||||
BrowserXssFilter: headers.BrowserXSSFilter,
|
BrowserXssFilter: headers.BrowserXSSFilter,
|
||||||
ContentTypeNosniff: headers.ContentTypeNosniff,
|
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.
|
// provided to configure which features should be enabled, and the ability to override a few of the default values.
|
||||||
type Header struct {
|
type Header struct {
|
||||||
next http.Handler
|
next http.Handler
|
||||||
headers *config.Headers
|
headers *dynamic.Headers
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewHeader constructs a new header instance from supplied frontend header struct.
|
// 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{
|
return &Header{
|
||||||
next: next,
|
next: next,
|
||||||
headers: &headers,
|
headers: &headers,
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -18,7 +18,7 @@ import (
|
||||||
func TestCustomRequestHeader(t *testing.T) {
|
func TestCustomRequestHeader(t *testing.T) {
|
||||||
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||||
|
|
||||||
header := NewHeader(emptyHandler, config.Headers{
|
header := NewHeader(emptyHandler, dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{
|
CustomRequestHeaders: map[string]string{
|
||||||
"X-Custom-Request-Header": "test_request",
|
"X-Custom-Request-Header": "test_request",
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@ func TestCustomRequestHeader(t *testing.T) {
|
||||||
func TestCustomRequestHeaderEmptyValue(t *testing.T) {
|
func TestCustomRequestHeaderEmptyValue(t *testing.T) {
|
||||||
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
||||||
|
|
||||||
header := NewHeader(emptyHandler, config.Headers{
|
header := NewHeader(emptyHandler, dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{
|
CustomRequestHeaders: map[string]string{
|
||||||
"X-Custom-Request-Header": "test_request",
|
"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, http.StatusOK, res.Code)
|
||||||
assert.Equal(t, "test_request", req.Header.Get("X-Custom-Request-Header"))
|
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{
|
CustomRequestHeaders: map[string]string{
|
||||||
"X-Custom-Request-Header": "",
|
"X-Custom-Request-Header": "",
|
||||||
},
|
},
|
||||||
|
@ -86,7 +86,7 @@ func TestSecureHeader(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
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"},
|
AllowedHosts: []string{"foo.com", "bar.com"},
|
||||||
}, "foo")
|
}, "foo")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -119,7 +119,7 @@ func TestSSLForceHost(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "http should return a 301",
|
desc: "http should return a 301",
|
||||||
host: "http://powpow.example.com",
|
host: "http://powpow.example.com",
|
||||||
secureMiddleware: newSecure(next, config.Headers{
|
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||||
SSLRedirect: true,
|
SSLRedirect: true,
|
||||||
SSLForceHost: true,
|
SSLForceHost: true,
|
||||||
SSLHost: "powpow.example.com",
|
SSLHost: "powpow.example.com",
|
||||||
|
@ -129,7 +129,7 @@ func TestSSLForceHost(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "http sub domain should return a 301",
|
desc: "http sub domain should return a 301",
|
||||||
host: "http://www.powpow.example.com",
|
host: "http://www.powpow.example.com",
|
||||||
secureMiddleware: newSecure(next, config.Headers{
|
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||||
SSLRedirect: true,
|
SSLRedirect: true,
|
||||||
SSLForceHost: true,
|
SSLForceHost: true,
|
||||||
SSLHost: "powpow.example.com",
|
SSLHost: "powpow.example.com",
|
||||||
|
@ -139,7 +139,7 @@ func TestSSLForceHost(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "https should return a 200",
|
desc: "https should return a 200",
|
||||||
host: "https://powpow.example.com",
|
host: "https://powpow.example.com",
|
||||||
secureMiddleware: newSecure(next, config.Headers{
|
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||||
SSLRedirect: true,
|
SSLRedirect: true,
|
||||||
SSLForceHost: true,
|
SSLForceHost: true,
|
||||||
SSLHost: "powpow.example.com",
|
SSLHost: "powpow.example.com",
|
||||||
|
@ -149,7 +149,7 @@ func TestSSLForceHost(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "https sub domain should return a 301",
|
desc: "https sub domain should return a 301",
|
||||||
host: "https://www.powpow.example.com",
|
host: "https://www.powpow.example.com",
|
||||||
secureMiddleware: newSecure(next, config.Headers{
|
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||||
SSLRedirect: true,
|
SSLRedirect: true,
|
||||||
SSLForceHost: true,
|
SSLForceHost: true,
|
||||||
SSLHost: "powpow.example.com",
|
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",
|
desc: "http without force host and sub domain should return a 301",
|
||||||
host: "http://www.powpow.example.com",
|
host: "http://www.powpow.example.com",
|
||||||
secureMiddleware: newSecure(next, config.Headers{
|
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||||
SSLRedirect: true,
|
SSLRedirect: true,
|
||||||
SSLForceHost: false,
|
SSLForceHost: false,
|
||||||
SSLHost: "powpow.example.com",
|
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",
|
desc: "https without force host and sub domain should return a 301",
|
||||||
host: "https://www.powpow.example.com",
|
host: "https://www.powpow.example.com",
|
||||||
secureMiddleware: newSecure(next, config.Headers{
|
secureMiddleware: newSecure(next, dynamic.Headers{
|
||||||
SSLRedirect: true,
|
SSLRedirect: true,
|
||||||
SSLForceHost: false,
|
SSLForceHost: false,
|
||||||
SSLHost: "powpow.example.com",
|
SSLHost: "powpow.example.com",
|
||||||
|
@ -201,7 +201,7 @@ func TestCORSPreflights(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Test Simple Preflight",
|
desc: "Test Simple Preflight",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||||
AccessControlAllowOrigin: "origin-list-or-null",
|
AccessControlAllowOrigin: "origin-list-or-null",
|
||||||
AccessControlMaxAge: 600,
|
AccessControlMaxAge: 600,
|
||||||
|
@ -219,7 +219,7 @@ func TestCORSPreflights(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Wildcard origin Preflight",
|
desc: "Wildcard origin Preflight",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||||
AccessControlAllowOrigin: "*",
|
AccessControlAllowOrigin: "*",
|
||||||
AccessControlMaxAge: 600,
|
AccessControlMaxAge: 600,
|
||||||
|
@ -237,7 +237,7 @@ func TestCORSPreflights(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Allow Credentials Preflight",
|
desc: "Allow Credentials Preflight",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||||
AccessControlAllowOrigin: "*",
|
AccessControlAllowOrigin: "*",
|
||||||
AccessControlAllowCredentials: true,
|
AccessControlAllowCredentials: true,
|
||||||
|
@ -257,7 +257,7 @@ func TestCORSPreflights(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Allow Headers Preflight",
|
desc: "Allow Headers Preflight",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
AccessControlAllowMethods: []string{"GET", "OPTIONS", "PUT"},
|
||||||
AccessControlAllowOrigin: "*",
|
AccessControlAllowOrigin: "*",
|
||||||
AccessControlAllowHeaders: []string{"origin", "X-Forwarded-For"},
|
AccessControlAllowHeaders: []string{"origin", "X-Forwarded-For"},
|
||||||
|
@ -293,14 +293,14 @@ func TestCORSPreflights(t *testing.T) {
|
||||||
func TestEmptyHeaderObject(t *testing.T) {
|
func TestEmptyHeaderObject(t *testing.T) {
|
||||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
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")
|
require.Errorf(t, err, "headers configuration not valid")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCustomHeaderHandler(t *testing.T) {
|
func TestCustomHeaderHandler(t *testing.T) {
|
||||||
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
|
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{
|
CustomRequestHeaders: map[string]string{
|
||||||
"X-Custom-Request-Header": "test_request",
|
"X-Custom-Request-Header": "test_request",
|
||||||
},
|
},
|
||||||
|
@ -342,7 +342,7 @@ func TestCORSResponses(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Test Simple Request",
|
desc: "Test Simple Request",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowOrigin: "origin-list-or-null",
|
AccessControlAllowOrigin: "origin-list-or-null",
|
||||||
}),
|
}),
|
||||||
requestHeaders: map[string][]string{
|
requestHeaders: map[string][]string{
|
||||||
|
@ -354,7 +354,7 @@ func TestCORSResponses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Wildcard origin Request",
|
desc: "Wildcard origin Request",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowOrigin: "*",
|
AccessControlAllowOrigin: "*",
|
||||||
}),
|
}),
|
||||||
requestHeaders: map[string][]string{
|
requestHeaders: map[string][]string{
|
||||||
|
@ -366,7 +366,7 @@ func TestCORSResponses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Empty origin Request",
|
desc: "Empty origin Request",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowOrigin: "origin-list-or-null",
|
AccessControlAllowOrigin: "origin-list-or-null",
|
||||||
}),
|
}),
|
||||||
requestHeaders: map[string][]string{},
|
requestHeaders: map[string][]string{},
|
||||||
|
@ -376,13 +376,13 @@ func TestCORSResponses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Not Defined origin Request",
|
desc: "Not Defined origin Request",
|
||||||
header: NewHeader(emptyHandler, config.Headers{}),
|
header: NewHeader(emptyHandler, dynamic.Headers{}),
|
||||||
requestHeaders: map[string][]string{},
|
requestHeaders: map[string][]string{},
|
||||||
expected: map[string][]string{},
|
expected: map[string][]string{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Allow Credentials Request",
|
desc: "Allow Credentials Request",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowOrigin: "*",
|
AccessControlAllowOrigin: "*",
|
||||||
AccessControlAllowCredentials: true,
|
AccessControlAllowCredentials: true,
|
||||||
}),
|
}),
|
||||||
|
@ -396,7 +396,7 @@ func TestCORSResponses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Expose Headers Request",
|
desc: "Expose Headers Request",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowOrigin: "*",
|
AccessControlAllowOrigin: "*",
|
||||||
AccessControlExposeHeaders: []string{"origin", "X-Forwarded-For"},
|
AccessControlExposeHeaders: []string{"origin", "X-Forwarded-For"},
|
||||||
}),
|
}),
|
||||||
|
@ -410,7 +410,7 @@ func TestCORSResponses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Test Simple Request with Vary Headers",
|
desc: "Test Simple Request with Vary Headers",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
AccessControlAllowOrigin: "origin-list-or-null",
|
AccessControlAllowOrigin: "origin-list-or-null",
|
||||||
AddVaryHeader: true,
|
AddVaryHeader: true,
|
||||||
}),
|
}),
|
||||||
|
@ -424,7 +424,7 @@ func TestCORSResponses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Test Simple Request with Vary Headers and non-empty response",
|
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",
|
AccessControlAllowOrigin: "origin-list-or-null",
|
||||||
AddVaryHeader: true,
|
AddVaryHeader: true,
|
||||||
}),
|
}),
|
||||||
|
@ -462,7 +462,7 @@ func TestCustomResponseHeaders(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Test Simple Response",
|
desc: "Test Simple Response",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{
|
CustomResponseHeaders: map[string]string{
|
||||||
"Testing": "foo",
|
"Testing": "foo",
|
||||||
"Testing2": "bar",
|
"Testing2": "bar",
|
||||||
|
@ -475,7 +475,7 @@ func TestCustomResponseHeaders(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Deleting Custom Header",
|
desc: "Deleting Custom Header",
|
||||||
header: NewHeader(emptyHandler, config.Headers{
|
header: NewHeader(emptyHandler, dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{
|
CustomResponseHeaders: map[string]string{
|
||||||
"Testing": "foo",
|
"Testing": "foo",
|
||||||
"Testing2": "",
|
"Testing2": "",
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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/ip"
|
||||||
"github.com/containous/traefik/pkg/middlewares"
|
"github.com/containous/traefik/pkg/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"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
|
// 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 := middlewares.GetLogger(ctx, name, typeName)
|
||||||
logger.Debug("Creating middleware")
|
logger.Debug("Creating middleware")
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -14,19 +14,19 @@ import (
|
||||||
func TestNewIPWhiteLister(t *testing.T) {
|
func TestNewIPWhiteLister(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
whiteList config.IPWhiteList
|
whiteList dynamic.IPWhiteList
|
||||||
expectedError bool
|
expectedError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "invalid IP",
|
desc: "invalid IP",
|
||||||
whiteList: config.IPWhiteList{
|
whiteList: dynamic.IPWhiteList{
|
||||||
SourceRange: []string{"foo"},
|
SourceRange: []string{"foo"},
|
||||||
},
|
},
|
||||||
expectedError: true,
|
expectedError: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "valid IP",
|
desc: "valid IP",
|
||||||
whiteList: config.IPWhiteList{
|
whiteList: dynamic.IPWhiteList{
|
||||||
SourceRange: []string{"10.10.10.10"},
|
SourceRange: []string{"10.10.10.10"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -53,13 +53,13 @@ func TestNewIPWhiteLister(t *testing.T) {
|
||||||
func TestIPWhiteLister_ServeHTTP(t *testing.T) {
|
func TestIPWhiteLister_ServeHTTP(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
whiteList config.IPWhiteList
|
whiteList dynamic.IPWhiteList
|
||||||
remoteAddr string
|
remoteAddr string
|
||||||
expected int
|
expected int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "authorized with remote address",
|
desc: "authorized with remote address",
|
||||||
whiteList: config.IPWhiteList{
|
whiteList: dynamic.IPWhiteList{
|
||||||
SourceRange: []string{"20.20.20.20"},
|
SourceRange: []string{"20.20.20.20"},
|
||||||
},
|
},
|
||||||
remoteAddr: "20.20.20.20:1234",
|
remoteAddr: "20.20.20.20:1234",
|
||||||
|
@ -67,7 +67,7 @@ func TestIPWhiteLister_ServeHTTP(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "non authorized with remote address",
|
desc: "non authorized with remote address",
|
||||||
whiteList: config.IPWhiteList{
|
whiteList: dynamic.IPWhiteList{
|
||||||
SourceRange: []string{"20.20.20.20"},
|
SourceRange: []string{"20.20.20.20"},
|
||||||
},
|
},
|
||||||
remoteAddr: "20.20.20.21:1234",
|
remoteAddr: "20.20.20.21:1234",
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -23,7 +23,7 @@ type maxConnection struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a max connection middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
extractFunc, err := utils.NewExtractor(maxConns.ExtractorFunc)
|
extractFunc, err := utils.NewExtractor(maxConns.ExtractorFunc)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/middlewares"
|
"github.com/containous/traefik/pkg/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
|
@ -40,7 +40,7 @@ type DistinguishedNameOptions struct {
|
||||||
StateOrProvinceName bool
|
StateOrProvinceName bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDistinguishedNameOptions(info *config.TLSCLientCertificateDNInfo) *DistinguishedNameOptions {
|
func newDistinguishedNameOptions(info *dynamic.TLSCLientCertificateDNInfo) *DistinguishedNameOptions {
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ type passTLSClientCert struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New constructs a new PassTLSClientCert instance from supplied frontend header 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
return &passTLSClientCert{
|
return &passTLSClientCert{
|
||||||
|
@ -85,7 +85,7 @@ type tlsClientCertificateInfo struct {
|
||||||
issuer *DistinguishedNameOptions
|
issuer *DistinguishedNameOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTLSClientInfo(info *config.TLSClientCertificateInfo) *tlsClientCertificateInfo {
|
func newTLSClientInfo(info *dynamic.TLSClientCertificateInfo) *tlsClientCertificateInfo {
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -367,7 +367,7 @@ func TestTLSClientHeadersWithPEM(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
certContents []string // set the request TLS attribute if defined
|
certContents []string // set the request TLS attribute if defined
|
||||||
config config.PassTLSClientCert
|
config dynamic.PassTLSClientCert
|
||||||
expectedHeader string
|
expectedHeader string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -379,24 +379,24 @@ func TestTLSClientHeadersWithPEM(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "No TLS, with pem option true",
|
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",
|
desc: "TLS with simple certificate, with pem option true",
|
||||||
certContents: []string{minimalCheeseCrt},
|
certContents: []string{minimalCheeseCrt},
|
||||||
config: config.PassTLSClientCert{PEM: true},
|
config: dynamic.PassTLSClientCert{PEM: true},
|
||||||
expectedHeader: getCleanCertContents([]string{minimalCert}),
|
expectedHeader: getCleanCertContents([]string{minimalCert}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "TLS with complete certificate, with pem option true",
|
desc: "TLS with complete certificate, with pem option true",
|
||||||
certContents: []string{minimalCheeseCrt},
|
certContents: []string{minimalCheeseCrt},
|
||||||
config: config.PassTLSClientCert{PEM: true},
|
config: dynamic.PassTLSClientCert{PEM: true},
|
||||||
expectedHeader: getCleanCertContents([]string{minimalCheeseCrt}),
|
expectedHeader: getCleanCertContents([]string{minimalCheeseCrt}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "TLS with two certificate, with pem option true",
|
desc: "TLS with two certificate, with pem option true",
|
||||||
certContents: []string{minimalCert, minimalCheeseCrt},
|
certContents: []string{minimalCert, minimalCheeseCrt},
|
||||||
config: config.PassTLSClientCert{PEM: true},
|
config: dynamic.PassTLSClientCert{PEM: true},
|
||||||
expectedHeader: getCleanCertContents([]string{minimalCert, minimalCheeseCrt}),
|
expectedHeader: getCleanCertContents([]string{minimalCert, minimalCheeseCrt}),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
certContents []string // set the request TLS attribute if defined
|
certContents []string // set the request TLS attribute if defined
|
||||||
config config.PassTLSClientCert
|
config dynamic.PassTLSClientCert
|
||||||
expectedHeader string
|
expectedHeader string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
@ -500,9 +500,9 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "No TLS, with subject info",
|
desc: "No TLS, with subject info",
|
||||||
config: config.PassTLSClientCert{
|
config: dynamic.PassTLSClientCert{
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
CommonName: true,
|
CommonName: true,
|
||||||
Organization: true,
|
Organization: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -515,22 +515,22 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "No TLS, with pem option false with empty subject info",
|
desc: "No TLS, with pem option false with empty subject info",
|
||||||
config: config.PassTLSClientCert{
|
config: dynamic.PassTLSClientCert{
|
||||||
PEM: false,
|
PEM: false,
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{},
|
Subject: &dynamic.TLSCLientCertificateDNInfo{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "TLS with simple certificate, with all info",
|
desc: "TLS with simple certificate, with all info",
|
||||||
certContents: []string{minimalCheeseCrt},
|
certContents: []string{minimalCheeseCrt},
|
||||||
config: config.PassTLSClientCert{
|
config: dynamic.PassTLSClientCert{
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
NotAfter: true,
|
NotAfter: true,
|
||||||
NotBefore: true,
|
NotBefore: true,
|
||||||
Sans: true,
|
Sans: true,
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
CommonName: true,
|
CommonName: true,
|
||||||
Country: true,
|
Country: true,
|
||||||
DomainComponent: true,
|
DomainComponent: true,
|
||||||
|
@ -539,7 +539,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
Province: true,
|
Province: true,
|
||||||
SerialNumber: true,
|
SerialNumber: true,
|
||||||
},
|
},
|
||||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
CommonName: true,
|
CommonName: true,
|
||||||
Country: true,
|
Country: true,
|
||||||
DomainComponent: true,
|
DomainComponent: true,
|
||||||
|
@ -555,14 +555,14 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "TLS with simple certificate, with some info",
|
desc: "TLS with simple certificate, with some info",
|
||||||
certContents: []string{minimalCheeseCrt},
|
certContents: []string{minimalCheeseCrt},
|
||||||
config: config.PassTLSClientCert{
|
config: dynamic.PassTLSClientCert{
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
NotAfter: true,
|
NotAfter: true,
|
||||||
Sans: true,
|
Sans: true,
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Organization: true,
|
Organization: true,
|
||||||
},
|
},
|
||||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -572,12 +572,12 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "TLS with complete certificate, with all info",
|
desc: "TLS with complete certificate, with all info",
|
||||||
certContents: []string{completeCheeseCrt},
|
certContents: []string{completeCheeseCrt},
|
||||||
config: config.PassTLSClientCert{
|
config: dynamic.PassTLSClientCert{
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
NotAfter: true,
|
NotAfter: true,
|
||||||
NotBefore: true,
|
NotBefore: true,
|
||||||
Sans: true,
|
Sans: true,
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -586,7 +586,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
SerialNumber: true,
|
SerialNumber: true,
|
||||||
DomainComponent: true,
|
DomainComponent: true,
|
||||||
},
|
},
|
||||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -602,12 +602,12 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "TLS with 2 certificates, with all info",
|
desc: "TLS with 2 certificates, with all info",
|
||||||
certContents: []string{minimalCheeseCrt, completeCheeseCrt},
|
certContents: []string{minimalCheeseCrt, completeCheeseCrt},
|
||||||
config: config.PassTLSClientCert{
|
config: dynamic.PassTLSClientCert{
|
||||||
Info: &config.TLSClientCertificateInfo{
|
Info: &dynamic.TLSClientCertificateInfo{
|
||||||
NotAfter: true,
|
NotAfter: true,
|
||||||
NotBefore: true,
|
NotBefore: true,
|
||||||
Sans: true,
|
Sans: true,
|
||||||
Subject: &config.TLSCLientCertificateDNInfo{
|
Subject: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
@ -616,7 +616,7 @@ func TestTLSClientHeadersWithCertInfo(t *testing.T) {
|
||||||
SerialNumber: true,
|
SerialNumber: true,
|
||||||
DomainComponent: true,
|
DomainComponent: true,
|
||||||
},
|
},
|
||||||
Issuer: &config.TLSCLientCertificateDNInfo{
|
Issuer: &dynamic.TLSCLientCertificateDNInfo{
|
||||||
Country: true,
|
Country: true,
|
||||||
Province: true,
|
Province: true,
|
||||||
Locality: true,
|
Locality: true,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -23,7 +23,7 @@ type rateLimiter struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates rate limiter middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
extractFunc, err := utils.NewExtractor(config.ExtractorFunc)
|
extractFunc, err := utils.NewExtractor(config.ExtractorFunc)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"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/middlewares"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewRedirectRegex creates a redirect middleware.
|
// 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 := middlewares.GetLogger(ctx, name, typeRegexName)
|
||||||
logger.Debug("Creating middleware")
|
logger.Debug("Creating middleware")
|
||||||
logger.Debugf("Setting up redirection from %s to %s", conf.Regex, conf.Replacement)
|
logger.Debugf("Setting up redirection from %s to %s", conf.Regex, conf.Replacement)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
func TestRedirectRegexHandler(t *testing.T) {
|
func TestRedirectRegexHandler(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
config config.RedirectRegex
|
config dynamic.RedirectRegex
|
||||||
method string
|
method string
|
||||||
url string
|
url string
|
||||||
secured bool
|
secured bool
|
||||||
|
@ -26,7 +26,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "simple redirection",
|
desc: "simple redirection",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||||
Replacement: "https://${1}bar$2:443$4",
|
Replacement: "https://${1}bar$2:443$4",
|
||||||
},
|
},
|
||||||
|
@ -36,7 +36,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "use request header",
|
desc: "use request header",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||||
Replacement: `https://${1}{{ .Request.Header.Get "X-Foo" }}$2:443$4`,
|
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",
|
desc: "URL doesn't match regex",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
Regex: `^(?:http?:\/\/)(foo)(\.com)(:\d+)(.*)$`,
|
||||||
Replacement: "https://${1}bar$2:443$4",
|
Replacement: "https://${1}bar$2:443$4",
|
||||||
},
|
},
|
||||||
|
@ -55,7 +55,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "invalid rewritten URL",
|
desc: "invalid rewritten URL",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^(.*)$`,
|
Regex: `^(.*)$`,
|
||||||
Replacement: "http://192.168.0.%31/",
|
Replacement: "http://192.168.0.%31/",
|
||||||
},
|
},
|
||||||
|
@ -64,7 +64,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "invalid regex",
|
desc: "invalid regex",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^(.*`,
|
Regex: `^(.*`,
|
||||||
Replacement: "$1",
|
Replacement: "$1",
|
||||||
},
|
},
|
||||||
|
@ -73,7 +73,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTPS permanent",
|
desc: "HTTP to HTTPS permanent",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^http://`,
|
Regex: `^http://`,
|
||||||
Replacement: "https://$1",
|
Replacement: "https://$1",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
|
@ -84,7 +84,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTPS to HTTP permanent",
|
desc: "HTTPS to HTTP permanent",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `https://foo`,
|
Regex: `https://foo`,
|
||||||
Replacement: "http://foo",
|
Replacement: "http://foo",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
|
@ -96,7 +96,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTPS",
|
desc: "HTTP to HTTPS",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `http://foo:80`,
|
Regex: `http://foo:80`,
|
||||||
Replacement: "https://foo:443",
|
Replacement: "https://foo:443",
|
||||||
},
|
},
|
||||||
|
@ -106,7 +106,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTPS to HTTP",
|
desc: "HTTPS to HTTP",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `https://foo:443`,
|
Regex: `https://foo:443`,
|
||||||
Replacement: "http://foo:80",
|
Replacement: "http://foo:80",
|
||||||
},
|
},
|
||||||
|
@ -117,7 +117,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTP",
|
desc: "HTTP to HTTP",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `http://foo:80`,
|
Regex: `http://foo:80`,
|
||||||
Replacement: "http://foo:88",
|
Replacement: "http://foo:88",
|
||||||
},
|
},
|
||||||
|
@ -127,7 +127,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTP POST",
|
desc: "HTTP to HTTP POST",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^http://`,
|
Regex: `^http://`,
|
||||||
Replacement: "https://$1",
|
Replacement: "https://$1",
|
||||||
},
|
},
|
||||||
|
@ -138,7 +138,7 @@ func TestRedirectRegexHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTP POST permanent",
|
desc: "HTTP to HTTP POST permanent",
|
||||||
config: config.RedirectRegex{
|
config: dynamic.RedirectRegex{
|
||||||
Regex: `^http://`,
|
Regex: `^http://`,
|
||||||
Replacement: "https://$1",
|
Replacement: "https://$1",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"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/middlewares"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewRedirectScheme creates a new RedirectScheme middleware.
|
// 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 := middlewares.GetLogger(ctx, name, typeSchemeName)
|
||||||
logger.Debug("Creating middleware")
|
logger.Debug("Creating middleware")
|
||||||
logger.Debugf("Setting up redirection to %s %s", conf.Scheme, conf.Port)
|
logger.Debugf("Setting up redirection to %s %s", conf.Scheme, conf.Port)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
func TestRedirectSchemeHandler(t *testing.T) {
|
func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
config config.RedirectScheme
|
config dynamic.RedirectScheme
|
||||||
method string
|
method string
|
||||||
url string
|
url string
|
||||||
secured bool
|
secured bool
|
||||||
|
@ -26,13 +26,13 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Without scheme",
|
desc: "Without scheme",
|
||||||
config: config.RedirectScheme{},
|
config: dynamic.RedirectScheme{},
|
||||||
url: "http://foo",
|
url: "http://foo",
|
||||||
errorExpected: true,
|
errorExpected: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTPS",
|
desc: "HTTP to HTTPS",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
},
|
},
|
||||||
url: "http://foo",
|
url: "http://foo",
|
||||||
|
@ -41,7 +41,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP with port to HTTPS without port",
|
desc: "HTTP with port to HTTPS without port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
},
|
},
|
||||||
url: "http://foo:8080",
|
url: "http://foo:8080",
|
||||||
|
@ -50,7 +50,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP without port to HTTPS with port",
|
desc: "HTTP without port to HTTPS with port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Port: "8443",
|
Port: "8443",
|
||||||
},
|
},
|
||||||
|
@ -60,7 +60,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP with port to HTTPS with port",
|
desc: "HTTP with port to HTTPS with port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Port: "8443",
|
Port: "8443",
|
||||||
},
|
},
|
||||||
|
@ -70,7 +70,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTPS with port to HTTPS with port",
|
desc: "HTTPS with port to HTTPS with port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Port: "8443",
|
Port: "8443",
|
||||||
},
|
},
|
||||||
|
@ -80,7 +80,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTPS with port to HTTPS without port",
|
desc: "HTTPS with port to HTTPS without port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
},
|
},
|
||||||
url: "https://foo:8000",
|
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",
|
desc: "redirection to HTTPS without port from an URL already in https",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
},
|
},
|
||||||
url: "https://foo:8000/theother",
|
url: "https://foo:8000/theother",
|
||||||
|
@ -98,7 +98,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTPS permanent",
|
desc: "HTTP to HTTPS permanent",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Port: "8443",
|
Port: "8443",
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
|
@ -109,7 +109,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "to HTTP 80",
|
desc: "to HTTP 80",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Port: "80",
|
Port: "80",
|
||||||
},
|
},
|
||||||
|
@ -119,7 +119,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to wss",
|
desc: "HTTP to wss",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "wss",
|
Scheme: "wss",
|
||||||
Port: "9443",
|
Port: "9443",
|
||||||
},
|
},
|
||||||
|
@ -129,7 +129,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to wss without port",
|
desc: "HTTP to wss without port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "wss",
|
Scheme: "wss",
|
||||||
},
|
},
|
||||||
url: "http://foo",
|
url: "http://foo",
|
||||||
|
@ -138,7 +138,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP with port to wss without port",
|
desc: "HTTP with port to wss without port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "wss",
|
Scheme: "wss",
|
||||||
},
|
},
|
||||||
url: "http://foo:5678",
|
url: "http://foo:5678",
|
||||||
|
@ -147,7 +147,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP to HTTPS without port",
|
desc: "HTTP to HTTPS without port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
},
|
},
|
||||||
url: "http://foo:443",
|
url: "http://foo:443",
|
||||||
|
@ -156,7 +156,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTP port redirection",
|
desc: "HTTP port redirection",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "http",
|
Scheme: "http",
|
||||||
Port: "8181",
|
Port: "8181",
|
||||||
},
|
},
|
||||||
|
@ -166,7 +166,7 @@ func TestRedirectSchemeHandler(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "HTTPS with port 80 to HTTPS without port",
|
desc: "HTTPS with port 80 to HTTPS without port",
|
||||||
config: config.RedirectScheme{
|
config: dynamic.RedirectScheme{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
},
|
},
|
||||||
url: "https://foo:80",
|
url: "https://foo:80",
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -24,7 +24,7 @@ type replacePath struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new replace path middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
return &replacePath{
|
return &replacePath{
|
||||||
|
|
|
@ -5,14 +5,14 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestReplacePath(t *testing.T) {
|
func TestReplacePath(t *testing.T) {
|
||||||
var replacementConfig = config.ReplacePath{
|
var replacementConfig = dynamic.ReplacePath{
|
||||||
Path: "/replacement-path",
|
Path: "/replacement-path",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/containous/traefik/pkg/middlewares/replacepath"
|
"github.com/containous/traefik/pkg/middlewares/replacepath"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
|
@ -27,7 +27,7 @@ type replacePathRegex struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new replace path regex middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
exp, err := regexp.Compile(strings.TrimSpace(config.Regex))
|
exp, err := regexp.Compile(strings.TrimSpace(config.Regex))
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"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/middlewares/replacepath"
|
||||||
"github.com/containous/traefik/pkg/testhelpers"
|
"github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -16,7 +16,7 @@ func TestReplacePathRegex(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
path string
|
path string
|
||||||
config config.ReplacePathRegex
|
config dynamic.ReplacePathRegex
|
||||||
expectedPath string
|
expectedPath string
|
||||||
expectedHeader string
|
expectedHeader string
|
||||||
expectsError bool
|
expectsError bool
|
||||||
|
@ -24,7 +24,7 @@ func TestReplacePathRegex(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "simple regex",
|
desc: "simple regex",
|
||||||
path: "/whoami/and/whoami",
|
path: "/whoami/and/whoami",
|
||||||
config: config.ReplacePathRegex{
|
config: dynamic.ReplacePathRegex{
|
||||||
Replacement: "/who-am-i/$1",
|
Replacement: "/who-am-i/$1",
|
||||||
Regex: `^/whoami/(.*)`,
|
Regex: `^/whoami/(.*)`,
|
||||||
},
|
},
|
||||||
|
@ -34,7 +34,7 @@ func TestReplacePathRegex(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "simple replace (no regex)",
|
desc: "simple replace (no regex)",
|
||||||
path: "/whoami/and/whoami",
|
path: "/whoami/and/whoami",
|
||||||
config: config.ReplacePathRegex{
|
config: dynamic.ReplacePathRegex{
|
||||||
Replacement: "/who-am-i",
|
Replacement: "/who-am-i",
|
||||||
Regex: `/whoami`,
|
Regex: `/whoami`,
|
||||||
},
|
},
|
||||||
|
@ -44,7 +44,7 @@ func TestReplacePathRegex(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "no match",
|
desc: "no match",
|
||||||
path: "/whoami/and/whoami",
|
path: "/whoami/and/whoami",
|
||||||
config: config.ReplacePathRegex{
|
config: dynamic.ReplacePathRegex{
|
||||||
Replacement: "/whoami",
|
Replacement: "/whoami",
|
||||||
Regex: `/no-match`,
|
Regex: `/no-match`,
|
||||||
},
|
},
|
||||||
|
@ -53,7 +53,7 @@ func TestReplacePathRegex(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "multiple replacement",
|
desc: "multiple replacement",
|
||||||
path: "/downloads/src/source.go",
|
path: "/downloads/src/source.go",
|
||||||
config: config.ReplacePathRegex{
|
config: dynamic.ReplacePathRegex{
|
||||||
Replacement: "/downloads/$1-$2",
|
Replacement: "/downloads/$1-$2",
|
||||||
Regex: `^(?i)/downloads/([^/]+)/([^/]+)$`,
|
Regex: `^(?i)/downloads/([^/]+)/([^/]+)$`,
|
||||||
},
|
},
|
||||||
|
@ -63,7 +63,7 @@ func TestReplacePathRegex(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "invalid regular expression",
|
desc: "invalid regular expression",
|
||||||
path: "/invalid/regexp/test",
|
path: "/invalid/regexp/test",
|
||||||
config: config.ReplacePathRegex{
|
config: dynamic.ReplacePathRegex{
|
||||||
Replacement: "/valid/regexp/$1",
|
Replacement: "/valid/regexp/$1",
|
||||||
Regex: `^(?err)/invalid/regexp/([^/]+)$`,
|
Regex: `^(?err)/invalid/regexp/([^/]+)$`,
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptrace"
|
"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/middlewares"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -42,7 +42,7 @@ type retry struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new retry middleware.
|
// 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 := middlewares.GetLogger(ctx, name, typeName)
|
||||||
logger.Debug("Creating middleware")
|
logger.Debug("Creating middleware")
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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/middlewares/emptybackendhandler"
|
||||||
"github.com/containous/traefik/pkg/testhelpers"
|
"github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
@ -22,42 +22,42 @@ import (
|
||||||
func TestRetry(t *testing.T) {
|
func TestRetry(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
config config.Retry
|
config dynamic.Retry
|
||||||
wantRetryAttempts int
|
wantRetryAttempts int
|
||||||
wantResponseStatus int
|
wantResponseStatus int
|
||||||
amountFaultyEndpoints int
|
amountFaultyEndpoints int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "no retry on success",
|
desc: "no retry on success",
|
||||||
config: config.Retry{Attempts: 1},
|
config: dynamic.Retry{Attempts: 1},
|
||||||
wantRetryAttempts: 0,
|
wantRetryAttempts: 0,
|
||||||
wantResponseStatus: http.StatusOK,
|
wantResponseStatus: http.StatusOK,
|
||||||
amountFaultyEndpoints: 0,
|
amountFaultyEndpoints: 0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "no retry when max request attempts is one",
|
desc: "no retry when max request attempts is one",
|
||||||
config: config.Retry{Attempts: 1},
|
config: dynamic.Retry{Attempts: 1},
|
||||||
wantRetryAttempts: 0,
|
wantRetryAttempts: 0,
|
||||||
wantResponseStatus: http.StatusInternalServerError,
|
wantResponseStatus: http.StatusInternalServerError,
|
||||||
amountFaultyEndpoints: 1,
|
amountFaultyEndpoints: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "one retry when one server is faulty",
|
desc: "one retry when one server is faulty",
|
||||||
config: config.Retry{Attempts: 2},
|
config: dynamic.Retry{Attempts: 2},
|
||||||
wantRetryAttempts: 1,
|
wantRetryAttempts: 1,
|
||||||
wantResponseStatus: http.StatusOK,
|
wantResponseStatus: http.StatusOK,
|
||||||
amountFaultyEndpoints: 1,
|
amountFaultyEndpoints: 1,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "two retries when two servers are faulty",
|
desc: "two retries when two servers are faulty",
|
||||||
config: config.Retry{Attempts: 3},
|
config: dynamic.Retry{Attempts: 3},
|
||||||
wantRetryAttempts: 2,
|
wantRetryAttempts: 2,
|
||||||
wantResponseStatus: http.StatusOK,
|
wantResponseStatus: http.StatusOK,
|
||||||
amountFaultyEndpoints: 2,
|
amountFaultyEndpoints: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "max attempts exhausted delivers the 5xx response",
|
desc: "max attempts exhausted delivers the 5xx response",
|
||||||
config: config.Retry{Attempts: 3},
|
config: dynamic.Retry{Attempts: 3},
|
||||||
wantRetryAttempts: 2,
|
wantRetryAttempts: 2,
|
||||||
wantResponseStatus: http.StatusInternalServerError,
|
wantResponseStatus: http.StatusInternalServerError,
|
||||||
amountFaultyEndpoints: 3,
|
amountFaultyEndpoints: 3,
|
||||||
|
@ -124,7 +124,7 @@ func TestRetryEmptyServerList(t *testing.T) {
|
||||||
next := emptybackendhandler.New(loadBalancer)
|
next := emptybackendhandler.New(loadBalancer)
|
||||||
|
|
||||||
retryListener := &countingRetryListener{}
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
recorder := httptest.NewRecorder()
|
recorder := httptest.NewRecorder()
|
||||||
|
@ -172,7 +172,7 @@ func TestMultipleRetriesShouldNotLooseHeaders(t *testing.T) {
|
||||||
rw.WriteHeader(http.StatusNoContent)
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
responseRecorder := httptest.NewRecorder()
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
responseRecorder := httptest.NewRecorder()
|
responseRecorder := httptest.NewRecorder()
|
||||||
|
@ -293,7 +293,7 @@ func TestRetryWebsocket(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
retryListener := &countingRetryListener{}
|
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)
|
require.NoError(t, err)
|
||||||
|
|
||||||
retryServer := httptest.NewServer(retryH)
|
retryServer := httptest.NewServer(retryH)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"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"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
"github.com/opentracing/opentracing-go/ext"
|
"github.com/opentracing/opentracing-go/ext"
|
||||||
|
@ -25,7 +25,7 @@ type stripPrefix struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new strip prefix middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
return &stripPrefix{
|
return &stripPrefix{
|
||||||
prefixes: config.Prefixes,
|
prefixes: config.Prefixes,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -15,7 +15,7 @@ import (
|
||||||
func TestStripPrefix(t *testing.T) {
|
func TestStripPrefix(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
config config.StripPrefix
|
config dynamic.StripPrefix
|
||||||
path string
|
path string
|
||||||
expectedStatusCode int
|
expectedStatusCode int
|
||||||
expectedPath string
|
expectedPath string
|
||||||
|
@ -24,7 +24,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "no prefixes configured",
|
desc: "no prefixes configured",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{},
|
Prefixes: []string{},
|
||||||
},
|
},
|
||||||
path: "/noprefixes",
|
path: "/noprefixes",
|
||||||
|
@ -32,7 +32,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "wildcard (.*) requests",
|
desc: "wildcard (.*) requests",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/"},
|
Prefixes: []string{"/"},
|
||||||
},
|
},
|
||||||
path: "/",
|
path: "/",
|
||||||
|
@ -42,7 +42,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "prefix and path matching",
|
desc: "prefix and path matching",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat"},
|
Prefixes: []string{"/stat"},
|
||||||
},
|
},
|
||||||
path: "/stat",
|
path: "/stat",
|
||||||
|
@ -52,7 +52,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "path prefix on exactly matching path",
|
desc: "path prefix on exactly matching path",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat/"},
|
Prefixes: []string{"/stat/"},
|
||||||
},
|
},
|
||||||
path: "/stat/",
|
path: "/stat/",
|
||||||
|
@ -62,7 +62,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "path prefix on matching longer path",
|
desc: "path prefix on matching longer path",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat/"},
|
Prefixes: []string{"/stat/"},
|
||||||
},
|
},
|
||||||
path: "/stat/us",
|
path: "/stat/us",
|
||||||
|
@ -72,7 +72,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "path prefix on mismatching path",
|
desc: "path prefix on mismatching path",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat/"},
|
Prefixes: []string{"/stat/"},
|
||||||
},
|
},
|
||||||
path: "/status",
|
path: "/status",
|
||||||
|
@ -80,7 +80,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "general prefix on matching path",
|
desc: "general prefix on matching path",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat"},
|
Prefixes: []string{"/stat"},
|
||||||
},
|
},
|
||||||
path: "/stat/",
|
path: "/stat/",
|
||||||
|
@ -90,7 +90,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "earlier prefix matching",
|
desc: "earlier prefix matching",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
|
|
||||||
Prefixes: []string{"/stat", "/stat/us"},
|
Prefixes: []string{"/stat", "/stat/us"},
|
||||||
},
|
},
|
||||||
|
@ -101,7 +101,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "later prefix matching",
|
desc: "later prefix matching",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/mismatch", "/stat"},
|
Prefixes: []string{"/mismatch", "/stat"},
|
||||||
},
|
},
|
||||||
path: "/stat",
|
path: "/stat",
|
||||||
|
@ -111,7 +111,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "prefix matching within slash boundaries",
|
desc: "prefix matching within slash boundaries",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat"},
|
Prefixes: []string{"/stat"},
|
||||||
},
|
},
|
||||||
path: "/status",
|
path: "/status",
|
||||||
|
@ -121,7 +121,7 @@ func TestStripPrefix(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "raw path is also stripped",
|
desc: "raw path is also stripped",
|
||||||
config: config.StripPrefix{
|
config: dynamic.StripPrefix{
|
||||||
Prefixes: []string{"/stat"},
|
Prefixes: []string{"/stat"},
|
||||||
},
|
},
|
||||||
path: "/stat/a%2Fb",
|
path: "/stat/a%2Fb",
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containous/mux"
|
"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"
|
||||||
"github.com/containous/traefik/pkg/middlewares/stripprefix"
|
"github.com/containous/traefik/pkg/middlewares/stripprefix"
|
||||||
"github.com/containous/traefik/pkg/tracing"
|
"github.com/containous/traefik/pkg/tracing"
|
||||||
|
@ -25,7 +25,7 @@ type stripPrefixRegex struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New builds a new StripPrefixRegex middleware.
|
// 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")
|
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
|
||||||
|
|
||||||
stripPrefix := stripPrefixRegex{
|
stripPrefix := stripPrefixRegex{
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/middlewares/stripprefix"
|
||||||
"github.com/containous/traefik/pkg/testhelpers"
|
"github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStripPrefixRegex(t *testing.T) {
|
func TestStripPrefixRegex(t *testing.T) {
|
||||||
testPrefixRegex := config.StripPrefixRegex{
|
testPrefixRegex := dynamic.StripPrefixRegex{
|
||||||
Regex: []string{"/a/api/", "/b/{regex}/", "/c/{category}/{id:[0-9]+}/"},
|
Regex: []string{"/a/api/", "/b/{regex}/", "/c/{category}/{id:[0-9]+}/"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/rules"
|
"github.com/containous/traefik/pkg/rules"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"github.com/containous/traefik/pkg/safe"
|
||||||
|
@ -89,10 +89,10 @@ type Provider struct {
|
||||||
account *Account
|
account *Account
|
||||||
client *lego.Client
|
client *lego.Client
|
||||||
certsChan chan *Certificate
|
certsChan chan *Certificate
|
||||||
configurationChan chan<- config.Message
|
configurationChan chan<- dynamic.Message
|
||||||
tlsManager *traefiktls.Manager
|
tlsManager *traefiktls.Manager
|
||||||
clientMutex sync.Mutex
|
clientMutex sync.Mutex
|
||||||
configFromListenerChan chan config.Configuration
|
configFromListenerChan chan dynamic.Configuration
|
||||||
pool *safe.Pool
|
pool *safe.Pool
|
||||||
resolvingDomains map[string]struct{}
|
resolvingDomains map[string]struct{}
|
||||||
resolvingDomainsMutex sync.RWMutex
|
resolvingDomainsMutex sync.RWMutex
|
||||||
|
@ -104,12 +104,12 @@ func (p *Provider) SetTLSManager(tlsManager *traefiktls.Manager) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetConfigListenerChan initializes the configFromListenerChan
|
// SetConfigListenerChan initializes the configFromListenerChan
|
||||||
func (p *Provider) SetConfigListenerChan(configFromListenerChan chan config.Configuration) {
|
func (p *Provider) SetConfigListenerChan(configFromListenerChan chan dynamic.Configuration) {
|
||||||
p.configFromListenerChan = configFromListenerChan
|
p.configFromListenerChan = configFromListenerChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenConfiguration sets a new Configuration into the 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
|
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
|
// Provide allows the file provider to provide configurations to traefik
|
||||||
// using the given Configuration channel.
|
// 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"))
|
ctx := log.With(context.Background(), log.Str(log.ProviderName, "acme"))
|
||||||
|
|
||||||
p.pool = pool
|
p.pool = pool
|
||||||
|
@ -581,15 +581,15 @@ func (p *Provider) saveCertificates() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) refreshCertificates() {
|
func (p *Provider) refreshCertificates() {
|
||||||
conf := config.Message{
|
conf := dynamic.Message{
|
||||||
ProviderName: "ACME",
|
ProviderName: "ACME",
|
||||||
Configuration: &config.Configuration{
|
Configuration: &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
TLS: &config.TLSConfiguration{},
|
TLS: &dynamic.TLSConfiguration{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package aggregator
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"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/config/static"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"github.com/containous/traefik/pkg/provider"
|
||||||
|
@ -80,7 +80,7 @@ func (p ProviderAggregator) Init() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provide calls the provide method of every providers
|
// 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 {
|
if p.fileProvider != nil {
|
||||||
launchProvider(configurationChan, pool, p.fileProvider)
|
launchProvider(configurationChan, pool, p.fileProvider)
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ func (p ProviderAggregator) Provide(configurationChan chan<- config.Message, poo
|
||||||
return nil
|
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)
|
jsonConf, err := json.Marshal(prd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithoutContext().Debugf("Cannot marshal the provider configuration %T: %v", prd, err)
|
log.WithoutContext().Debugf("Cannot marshal the provider configuration %T: %v", prd, err)
|
||||||
|
|
|
@ -10,23 +10,23 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"github.com/Masterminds/sprig"
|
"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/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Merge Merges multiple configurations.
|
// 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)
|
logger := log.FromContext(ctx)
|
||||||
|
|
||||||
configuration := &config.Configuration{
|
configuration := &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: make(map[string]*config.Router),
|
Routers: make(map[string]*dynamic.Router),
|
||||||
Middlewares: make(map[string]*config.Middleware),
|
Middlewares: make(map[string]*dynamic.Middleware),
|
||||||
Services: make(map[string]*config.Service),
|
Services: make(map[string]*dynamic.Service),
|
||||||
},
|
},
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: make(map[string]*config.TCPRouter),
|
Routers: make(map[string]*dynamic.TCPRouter),
|
||||||
Services: make(map[string]*config.TCPService),
|
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.
|
// 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 {
|
if _, ok := configuration.Services[serviceName]; !ok {
|
||||||
configuration.Services[serviceName] = service
|
configuration.Services[serviceName] = service
|
||||||
return true
|
return true
|
||||||
|
@ -138,7 +138,7 @@ func AddServiceTCP(configuration *config.TCPConfiguration, serviceName string, s
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRouterTCP Adds a router to a configurations.
|
// 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 {
|
if _, ok := configuration.Routers[routerName]; !ok {
|
||||||
configuration.Routers[routerName] = router
|
configuration.Routers[routerName] = router
|
||||||
return true
|
return true
|
||||||
|
@ -148,7 +148,7 @@ func AddRouterTCP(configuration *config.TCPConfiguration, routerName string, rou
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddService Adds a service to a configurations.
|
// 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 {
|
if _, ok := configuration.Services[serviceName]; !ok {
|
||||||
configuration.Services[serviceName] = service
|
configuration.Services[serviceName] = service
|
||||||
return true
|
return true
|
||||||
|
@ -163,7 +163,7 @@ func AddService(configuration *config.HTTPConfiguration, serviceName string, ser
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddRouter Adds a router to a configurations.
|
// 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 {
|
if _, ok := configuration.Routers[routerName]; !ok {
|
||||||
configuration.Routers[routerName] = router
|
configuration.Routers[routerName] = router
|
||||||
return true
|
return true
|
||||||
|
@ -173,7 +173,7 @@ func AddRouter(configuration *config.HTTPConfiguration, routerName string, route
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMiddleware Adds a middleware to a configurations.
|
// 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 {
|
if _, ok := configuration.Middlewares[middlewareName]; !ok {
|
||||||
configuration.Middlewares[middlewareName] = middleware
|
configuration.Middlewares[middlewareName] = middleware
|
||||||
return true
|
return true
|
||||||
|
@ -195,7 +195,7 @@ func MakeDefaultRuleTemplate(defaultRule string, funcMap template.FuncMap) (*tem
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildTCPRouterConfiguration Builds a router configuration.
|
// 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 {
|
for routerName, router := range configuration.Routers {
|
||||||
loggerRouter := log.FromContext(ctx).WithField(log.RouterName, routerName)
|
loggerRouter := log.FromContext(ctx).WithField(log.RouterName, routerName)
|
||||||
if len(router.Rule) == 0 {
|
if len(router.Rule) == 0 {
|
||||||
|
@ -220,13 +220,13 @@ func BuildTCPRouterConfiguration(ctx context.Context, configuration *config.TCPC
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildRouterConfiguration Builds a router configuration.
|
// 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.Routers) == 0 {
|
||||||
if len(configuration.Services) > 1 {
|
if len(configuration.Services) > 1 {
|
||||||
log.FromContext(ctx).Info("Could not create a router for the container: too many services")
|
log.FromContext(ctx).Info("Could not create a router for the container: too many services")
|
||||||
} else {
|
} else {
|
||||||
configuration.Routers = make(map[string]*config.Router)
|
configuration.Routers = make(map[string]*dynamic.Router)
|
||||||
configuration.Routers[defaultRouterName] = &config.Router{}
|
configuration.Routers[defaultRouterName] = &dynamic.Router{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"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/config/label"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"github.com/containous/traefik/pkg/provider"
|
||||||
|
@ -15,8 +15,8 @@ import (
|
||||||
"github.com/docker/go-connections/nat"
|
"github.com/docker/go-connections/nat"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Provider) buildConfiguration(ctx context.Context, containersInspected []dockerData) *config.Configuration {
|
func (p *Provider) buildConfiguration(ctx context.Context, containersInspected []dockerData) *dynamic.Configuration {
|
||||||
configurations := make(map[string]*config.Configuration)
|
configurations := make(map[string]*dynamic.Configuration)
|
||||||
|
|
||||||
for _, container := range containersInspected {
|
for _, container := range containersInspected {
|
||||||
containerName := getServiceName(container) + "-" + container.ID
|
containerName := getServiceName(container) + "-" + container.ID
|
||||||
|
@ -73,13 +73,13 @@ func (p *Provider) buildConfiguration(ctx context.Context, containersInspected [
|
||||||
return provider.Merge(ctx, configurations)
|
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)
|
serviceName := getServiceName(container)
|
||||||
|
|
||||||
if len(configuration.Services) == 0 {
|
if len(configuration.Services) == 0 {
|
||||||
configuration.Services = make(map[string]*config.TCPService)
|
configuration.Services = make(map[string]*dynamic.TCPService)
|
||||||
lb := &config.TCPLoadBalancerService{}
|
lb := &dynamic.TCPLoadBalancerService{}
|
||||||
configuration.Services[serviceName] = &config.TCPService{
|
configuration.Services[serviceName] = &dynamic.TCPService{
|
||||||
LoadBalancer: lb,
|
LoadBalancer: lb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,14 +94,14 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, container d
|
||||||
return nil
|
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)
|
serviceName := getServiceName(container)
|
||||||
|
|
||||||
if len(configuration.Services) == 0 {
|
if len(configuration.Services) == 0 {
|
||||||
configuration.Services = make(map[string]*config.Service)
|
configuration.Services = make(map[string]*dynamic.Service)
|
||||||
lb := &config.LoadBalancerService{}
|
lb := &dynamic.LoadBalancerService{}
|
||||||
lb.SetDefaults()
|
lb.SetDefaults()
|
||||||
configuration.Services[serviceName] = &config.Service{
|
configuration.Services[serviceName] = &dynamic.Service{
|
||||||
LoadBalancer: lb,
|
LoadBalancer: lb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func (p *Provider) keepContainer(ctx context.Context, container dockerData) bool
|
||||||
return true
|
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 := ""
|
serverPort := ""
|
||||||
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
|
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
|
||||||
serverPort = loadBalancer.Servers[0].Port
|
serverPort = loadBalancer.Servers[0].Port
|
||||||
|
@ -153,9 +153,9 @@ func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadB
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(loadBalancer.Servers) == 0 {
|
if len(loadBalancer.Servers) == 0 {
|
||||||
server := config.TCPServer{}
|
server := dynamic.TCPServer{}
|
||||||
|
|
||||||
loadBalancer.Servers = []config.TCPServer{server}
|
loadBalancer.Servers = []dynamic.TCPServer{server}
|
||||||
}
|
}
|
||||||
|
|
||||||
if serverPort != "" {
|
if serverPort != "" {
|
||||||
|
@ -171,7 +171,7 @@ func (p *Provider) addServerTCP(ctx context.Context, container dockerData, loadB
|
||||||
return nil
|
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)
|
serverPort := getLBServerPort(loadBalancer)
|
||||||
ip, port, err := p.getIPPort(ctx, container, serverPort)
|
ip, port, err := p.getIPPort(ctx, container, serverPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -179,10 +179,10 @@ func (p *Provider) addServer(ctx context.Context, container dockerData, loadBala
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(loadBalancer.Servers) == 0 {
|
if len(loadBalancer.Servers) == 0 {
|
||||||
server := config.Server{}
|
server := dynamic.Server{}
|
||||||
server.SetDefaults()
|
server.SetDefaults()
|
||||||
|
|
||||||
loadBalancer.Servers = []config.Server{server}
|
loadBalancer.Servers = []dynamic.Server{server}
|
||||||
}
|
}
|
||||||
|
|
||||||
if serverPort != "" {
|
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)
|
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 {
|
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
|
||||||
return loadBalancer.Servers[0].Port
|
return loadBalancer.Servers[0].Port
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -12,7 +12,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff"
|
"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/job"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"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.
|
// 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) {
|
pool.GoCtx(func(routineCtx context.Context) {
|
||||||
ctxLog := log.With(routineCtx, log.Str(log.ProviderName, "docker"))
|
ctxLog := log.With(routineCtx, log.Str(log.ProviderName, "docker"))
|
||||||
logger := log.FromContext(ctxLog)
|
logger := log.FromContext(ctxLog)
|
||||||
|
@ -186,7 +186,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration := p.buildConfiguration(ctxLog, dockerDataList)
|
configuration := p.buildConfiguration(ctxLog, dockerDataList)
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "docker",
|
ProviderName: "docker",
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
|
|
||||||
configuration := p.buildConfiguration(ctx, services)
|
configuration := p.buildConfiguration(ctx, services)
|
||||||
if configuration != nil {
|
if configuration != nil {
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "docker",
|
ProviderName: "docker",
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
|
@ -248,7 +248,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
|
|
||||||
configuration := p.buildConfiguration(ctx, containers)
|
configuration := p.buildConfiguration(ctx, containers)
|
||||||
if configuration != nil {
|
if configuration != nil {
|
||||||
message := config.Message{
|
message := dynamic.Message{
|
||||||
ProviderName: "docker",
|
ProviderName: "docker",
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/Masterminds/sprig"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"github.com/containous/traefik/pkg/provider"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"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
|
// Provide allows the file provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// 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()
|
configuration, err := p.BuildConfiguration()
|
||||||
|
|
||||||
if err != nil {
|
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'
|
// BuildConfiguration loads configuration either from file or a directory specified by 'Filename'/'Directory'
|
||||||
// and returns a 'Configuration' object
|
// 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))
|
ctx := log.With(context.Background(), log.Str(log.ProviderName, providerName))
|
||||||
|
|
||||||
if len(p.Directory) > 0 {
|
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")
|
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()
|
watcher, err := fsnotify.NewWatcher()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error creating file watcher: %s", err)
|
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
|
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
|
watchItem := p.TraefikFile
|
||||||
if len(p.Directory) > 0 {
|
if len(p.Directory) > 0 {
|
||||||
watchItem = p.Directory
|
watchItem = p.Directory
|
||||||
|
@ -163,16 +163,16 @@ func (p *Provider) watcherCallback(configurationChan chan<- config.Message, even
|
||||||
sendConfigToChannel(configurationChan, configuration)
|
sendConfigToChannel(configurationChan, configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sendConfigToChannel(configurationChan chan<- config.Message, configuration *config.Configuration) {
|
func sendConfigToChannel(configurationChan chan<- dynamic.Message, configuration *dynamic.Configuration) {
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "file",
|
ProviderName: "file",
|
||||||
Configuration: configuration,
|
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 err error
|
||||||
var configuration *config.Configuration
|
var configuration *dynamic.Configuration
|
||||||
if parseTemplate {
|
if parseTemplate {
|
||||||
configuration, err = p.CreateConfiguration(filename, template.FuncMap{}, false)
|
configuration, err = p.CreateConfiguration(filename, template.FuncMap{}, false)
|
||||||
} else {
|
} else {
|
||||||
|
@ -189,7 +189,7 @@ func (p *Provider) loadFileConfig(filename string, parseTemplate bool) (*config.
|
||||||
return configuration, nil
|
return configuration, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func flattenCertificates(tlsConfig *config.TLSConfiguration) []*tls.CertAndStores {
|
func flattenCertificates(tlsConfig *dynamic.TLSConfiguration) []*tls.CertAndStores {
|
||||||
var certs []*tls.CertAndStores
|
var certs []*tls.CertAndStores
|
||||||
for _, cert := range tlsConfig.Certificates {
|
for _, cert := range tlsConfig.Certificates {
|
||||||
content, err := cert.Certificate.CertFile.Read()
|
content, err := cert.Certificate.CertFile.Read()
|
||||||
|
@ -212,7 +212,7 @@ func flattenCertificates(tlsConfig *config.TLSConfiguration) []*tls.CertAndStore
|
||||||
return certs
|
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)
|
logger := log.FromContext(ctx)
|
||||||
|
|
||||||
fileList, err := ioutil.ReadDir(directory)
|
fileList, err := ioutil.ReadDir(directory)
|
||||||
|
@ -221,17 +221,17 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
|
||||||
}
|
}
|
||||||
|
|
||||||
if configuration == nil {
|
if configuration == nil {
|
||||||
configuration = &config.Configuration{
|
configuration = &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: make(map[string]*config.Router),
|
Routers: make(map[string]*dynamic.Router),
|
||||||
Middlewares: make(map[string]*config.Middleware),
|
Middlewares: make(map[string]*dynamic.Middleware),
|
||||||
Services: make(map[string]*config.Service),
|
Services: make(map[string]*dynamic.Service),
|
||||||
},
|
},
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: make(map[string]*config.TCPRouter),
|
Routers: make(map[string]*dynamic.TCPRouter),
|
||||||
Services: make(map[string]*config.TCPService),
|
Services: make(map[string]*dynamic.TCPService),
|
||||||
},
|
},
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Stores: make(map[string]tls.Store),
|
Stores: make(map[string]tls.Store),
|
||||||
Options: make(map[string]tls.Options),
|
Options: make(map[string]tls.Options),
|
||||||
},
|
},
|
||||||
|
@ -256,7 +256,7 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var c *config.Configuration
|
var c *dynamic.Configuration
|
||||||
c, err = p.loadFileConfig(filepath.Join(directory, item.Name()), true)
|
c, err = p.loadFileConfig(filepath.Join(directory, item.Name()), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return configuration, err
|
return configuration, err
|
||||||
|
@ -312,7 +312,7 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(configTLSMaps) > 0 {
|
if len(configTLSMaps) > 0 {
|
||||||
configuration.TLS = &config.TLSConfiguration{}
|
configuration.TLS = &dynamic.TLSConfiguration{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for conf := range configTLSMaps {
|
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.
|
// 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)
|
tmplContent, err := readFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading configuration file: %s - %s", filename, err)
|
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.
|
// 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)
|
content, err := readFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error reading configuration file: %s - %s", filename, err)
|
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)
|
return p.decodeConfiguration(filename, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) decodeConfiguration(filePath string, content string) (*config.Configuration, error) {
|
func (p *Provider) decodeConfiguration(filePath string, content string) (*dynamic.Configuration, error) {
|
||||||
configuration := &config.Configuration{
|
configuration := &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: make(map[string]*config.Router),
|
Routers: make(map[string]*dynamic.Router),
|
||||||
Middlewares: make(map[string]*config.Middleware),
|
Middlewares: make(map[string]*dynamic.Middleware),
|
||||||
Services: make(map[string]*config.Service),
|
Services: make(map[string]*dynamic.Service),
|
||||||
},
|
},
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: make(map[string]*config.TCPRouter),
|
Routers: make(map[string]*dynamic.TCPRouter),
|
||||||
Services: make(map[string]*config.TCPService),
|
Services: make(map[string]*dynamic.TCPService),
|
||||||
},
|
},
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Stores: make(map[string]tls.Store),
|
Stores: make(map[string]tls.Store),
|
||||||
Options: make(map[string]tls.Options),
|
Options: make(map[string]tls.Options),
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"github.com/containous/traefik/pkg/safe"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -55,7 +55,7 @@ func TestTLSContent(t *testing.T) {
|
||||||
|
|
||||||
func TestErrorWhenEmptyConfig(t *testing.T) {
|
func TestErrorWhenEmptyConfig(t *testing.T) {
|
||||||
provider := &Provider{}
|
provider := &Provider{}
|
||||||
configChan := make(chan config.Message)
|
configChan := make(chan dynamic.Message)
|
||||||
errorChan := make(chan struct{})
|
errorChan := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
err := provider.Provide(configChan, safe.NewPool(context.Background()))
|
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) {
|
t.Run(test.desc+" without watch", func(t *testing.T) {
|
||||||
provider, clean := createProvider(t, test, false)
|
provider, clean := createProvider(t, test, false)
|
||||||
defer clean()
|
defer clean()
|
||||||
configChan := make(chan config.Message)
|
configChan := make(chan dynamic.Message)
|
||||||
|
|
||||||
provider.DebugLogGeneratedTemplate = true
|
provider.DebugLogGeneratedTemplate = true
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ func TestProvideWithWatch(t *testing.T) {
|
||||||
t.Run(test.desc+" with watch", func(t *testing.T) {
|
t.Run(test.desc+" with watch", func(t *testing.T) {
|
||||||
provider, clean := createProvider(t, test, true)
|
provider, clean := createProvider(t, test, true)
|
||||||
defer clean()
|
defer clean()
|
||||||
configChan := make(chan config.Message)
|
configChan := make(chan dynamic.Message)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
err := provider.Provide(configChan, safe.NewPool(context.Background()))
|
err := provider.Provide(configChan, safe.NewPool(context.Background()))
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff"
|
"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/job"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider/kubernetes/crd/traefik/v1alpha1"
|
"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
|
// Provide allows the k8s provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// 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"))
|
ctxLog := log.With(context.Background(), log.Str(log.ProviderName, "kubernetescrd"))
|
||||||
logger := log.FromContext(ctxLog)
|
logger := log.FromContext(ctxLog)
|
||||||
// Tell glog (used by client-go) to log into STDERR. Otherwise, we risk
|
// 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)
|
logger.Debugf("Skipping Kubernetes event kind %T", event)
|
||||||
} else {
|
} else {
|
||||||
p.lastConfiguration.Set(conf)
|
p.lastConfiguration.Set(conf)
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "kubernetescrd",
|
ProviderName: "kubernetescrd",
|
||||||
Configuration: conf,
|
Configuration: conf,
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ func checkStringQuoteValidity(value string) error {
|
||||||
return err
|
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)
|
service, exists, err := client.GetService(namespace, svc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -172,9 +172,9 @@ func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([
|
||||||
return nil, errors.New("service port not found")
|
return nil, errors.New("service port not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
var servers []config.TCPServer
|
var servers []dynamic.TCPServer
|
||||||
if service.Spec.Type == corev1.ServiceTypeExternalName {
|
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),
|
Address: fmt.Sprintf("%s:%d", service.Spec.ExternalName, portSpec.Port),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -205,7 +205,7 @@ func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range subset.Addresses {
|
for _, addr := range subset.Addresses {
|
||||||
servers = append(servers, config.TCPServer{
|
servers = append(servers, dynamic.TCPServer{
|
||||||
Address: fmt.Sprintf("%s:%d", addr.IP, port),
|
Address: fmt.Sprintf("%s:%d", addr.IP, port),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ func loadTCPServers(client Client, namespace string, svc v1alpha1.ServiceTCP) ([
|
||||||
return servers, nil
|
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
|
strategy := svc.Strategy
|
||||||
if strategy == "" {
|
if strategy == "" {
|
||||||
strategy = "RoundRobin"
|
strategy = "RoundRobin"
|
||||||
|
@ -245,9 +245,9 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
|
||||||
return nil, errors.New("service port not found")
|
return nil, errors.New("service port not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
var servers []config.Server
|
var servers []dynamic.Server
|
||||||
if service.Spec.Type == corev1.ServiceTypeExternalName {
|
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),
|
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -290,7 +290,7 @@ func loadServers(client Client, namespace string, svc v1alpha1.Service) ([]confi
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range subset.Addresses {
|
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),
|
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
|
return tlsOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *config.HTTPConfiguration {
|
func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.HTTPConfiguration {
|
||||||
conf := &config.HTTPConfiguration{
|
conf := &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ingressRoute := range client.GetIngressRoutes() {
|
for _, ingressRoute := range client.GetIngressRoutes() {
|
||||||
|
@ -388,7 +388,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var allServers []config.Server
|
var allServers []dynamic.Server
|
||||||
for _, service := range route.Services {
|
for _, service := range route.Services {
|
||||||
servers, err := loadServers(client, ingressRoute.Namespace, service)
|
servers, err := loadServers(client, ingressRoute.Namespace, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -429,7 +429,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
||||||
|
|
||||||
serviceName := makeID(ingressRoute.Namespace, key)
|
serviceName := makeID(ingressRoute.Namespace, key)
|
||||||
|
|
||||||
conf.Routers[serviceName] = &config.Router{
|
conf.Routers[serviceName] = &dynamic.Router{
|
||||||
Middlewares: mds,
|
Middlewares: mds,
|
||||||
Priority: route.Priority,
|
Priority: route.Priority,
|
||||||
EntryPoints: ingressRoute.Spec.EntryPoints,
|
EntryPoints: ingressRoute.Spec.EntryPoints,
|
||||||
|
@ -438,7 +438,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
||||||
}
|
}
|
||||||
|
|
||||||
if ingressRoute.Spec.TLS != nil {
|
if ingressRoute.Spec.TLS != nil {
|
||||||
tlsConf := &config.RouterTLSConfig{}
|
tlsConf := &dynamic.RouterTLSConfig{}
|
||||||
if ingressRoute.Spec.TLS.Options != nil && len(ingressRoute.Spec.TLS.Options.Name) > 0 {
|
if ingressRoute.Spec.TLS.Options != nil && len(ingressRoute.Spec.TLS.Options.Name) > 0 {
|
||||||
tlsOptionsName := ingressRoute.Spec.TLS.Options.Name
|
tlsOptionsName := ingressRoute.Spec.TLS.Options.Name
|
||||||
// Is a Kubernetes CRD reference, (i.e. not a cross-provider reference)
|
// 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.Routers[serviceName].TLS = tlsConf
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.Services[serviceName] = &config.Service{
|
conf.Services[serviceName] = &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: allServers,
|
Servers: allServers,
|
||||||
// TODO: support other strategies.
|
// TODO: support other strategies.
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
|
@ -472,10 +472,10 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
||||||
return conf
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *config.TCPConfiguration {
|
func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client Client, tlsConfigs map[string]*tls.CertAndStores) *dynamic.TCPConfiguration {
|
||||||
conf := &config.TCPConfiguration{
|
conf := &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ingressRouteTCP := range client.GetIngressRouteTCPs() {
|
for _, ingressRouteTCP := range client.GetIngressRouteTCPs() {
|
||||||
|
@ -508,7 +508,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var allServers []config.TCPServer
|
var allServers []dynamic.TCPServer
|
||||||
for _, service := range route.Services {
|
for _, service := range route.Services {
|
||||||
servers, err := loadTCPServers(client, ingressRouteTCP.Namespace, service)
|
servers, err := loadTCPServers(client, ingressRouteTCP.Namespace, service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -529,14 +529,14 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceName := makeID(ingressRouteTCP.Namespace, key)
|
serviceName := makeID(ingressRouteTCP.Namespace, key)
|
||||||
conf.Routers[serviceName] = &config.TCPRouter{
|
conf.Routers[serviceName] = &dynamic.TCPRouter{
|
||||||
EntryPoints: ingressRouteTCP.Spec.EntryPoints,
|
EntryPoints: ingressRouteTCP.Spec.EntryPoints,
|
||||||
Rule: route.Match,
|
Rule: route.Match,
|
||||||
Service: serviceName,
|
Service: serviceName,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ingressRouteTCP.Spec.TLS != nil {
|
if ingressRouteTCP.Spec.TLS != nil {
|
||||||
conf.Routers[serviceName].TLS = &config.RouterTCPTLSConfig{
|
conf.Routers[serviceName].TLS = &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: ingressRouteTCP.Spec.TLS.Passthrough,
|
Passthrough: ingressRouteTCP.Spec.TLS.Passthrough,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,8 +560,8 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.Services[serviceName] = &config.TCPService{
|
conf.Services[serviceName] = &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: allServers,
|
Servers: allServers,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -571,12 +571,12 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
||||||
return conf
|
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)
|
tlsConfigs := make(map[string]*tls.CertAndStores)
|
||||||
conf := &config.Configuration{
|
conf := &dynamic.Configuration{
|
||||||
HTTP: p.loadIngressRouteConfiguration(ctx, client, tlsConfigs),
|
HTTP: p.loadIngressRouteConfiguration(ctx, client, tlsConfigs),
|
||||||
TCP: p.loadIngressRouteTCPConfiguration(ctx, client, tlsConfigs),
|
TCP: p.loadIngressRouteTCPConfiguration(ctx, client, tlsConfigs),
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Certificates: getTLSConfig(tlsConfigs),
|
Certificates: getTLSConfig(tlsConfigs),
|
||||||
Options: buildTLSOptions(ctx, client),
|
Options: buildTLSOptions(ctx, client),
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
||||||
package v1alpha1
|
package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ type Middleware struct {
|
||||||
metav1.TypeMeta `json:",inline"`
|
metav1.TypeMeta `json:",inline"`
|
||||||
metav1.ObjectMeta `json:"metadata"`
|
metav1.ObjectMeta `json:"metadata"`
|
||||||
|
|
||||||
Spec config.Middleware `json:"spec"`
|
Spec dynamic.Middleware `json:"spec"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff"
|
"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/job"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"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
|
// Provide allows the k8s provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// 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"))
|
ctxLog := log.With(context.Background(), log.Str(log.ProviderName, "kubernetes"))
|
||||||
logger := log.FromContext(ctxLog)
|
logger := log.FromContext(ctxLog)
|
||||||
// Tell glog (used by client-go) to log into STDERR. Otherwise, we risk
|
// 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)
|
logger.Debugf("Skipping Kubernetes event kind %T", event)
|
||||||
} else {
|
} else {
|
||||||
p.lastConfiguration.Set(conf)
|
p.lastConfiguration.Set(conf)
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "kubernetes",
|
ProviderName: "kubernetes",
|
||||||
Configuration: conf,
|
Configuration: conf,
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func checkStringQuoteValidity(value string) error {
|
||||||
return err
|
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)
|
service, exists, err := client.GetService(namespace, backend.ServiceName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -174,7 +174,7 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
|
||||||
return nil, errors.New("service not found")
|
return nil, errors.New("service not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
var servers []config.Server
|
var servers []dynamic.Server
|
||||||
var portName string
|
var portName string
|
||||||
var portSpec corev1.ServicePort
|
var portSpec corev1.ServicePort
|
||||||
var match bool
|
var match bool
|
||||||
|
@ -193,7 +193,7 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Spec.Type == corev1.ServiceTypeExternalName {
|
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),
|
URL: fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, portSpec.Port),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -230,29 +230,29 @@ func loadService(client Client, namespace string, backend v1beta1.IngressBackend
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, addr := range subset.Addresses {
|
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),
|
URL: fmt.Sprintf("%s://%s:%d", protocol, addr.IP, port),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &config.Service{
|
return &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: servers,
|
Servers: servers,
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Client) *config.Configuration {
|
func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Client) *dynamic.Configuration {
|
||||||
conf := &config.Configuration{
|
conf := &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
}
|
}
|
||||||
|
|
||||||
ingresses := client.GetIngresses()
|
ingresses := client.GetIngresses()
|
||||||
|
@ -286,7 +286,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
conf.HTTP.Routers["/"] = &config.Router{
|
conf.HTTP.Routers["/"] = &dynamic.Router{
|
||||||
Rule: "PathPrefix(`/`)",
|
Rule: "PathPrefix(`/`)",
|
||||||
Priority: math.MinInt32,
|
Priority: math.MinInt32,
|
||||||
Service: "default-backend",
|
Service: "default-backend",
|
||||||
|
@ -327,7 +327,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
rules = append(rules, "PathPrefix(`"+p.Path+"`)")
|
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, " && "),
|
Rule: strings.Join(rules, " && "),
|
||||||
Service: serviceName,
|
Service: serviceName,
|
||||||
}
|
}
|
||||||
|
@ -343,7 +343,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
|
||||||
|
|
||||||
certs := getTLSConfig(tlsConfigs)
|
certs := getTLSConfig(tlsConfigs)
|
||||||
if len(certs) > 0 {
|
if len(certs) > 0 {
|
||||||
conf.TLS = &config.TLSConfiguration{
|
conf.TLS = &dynamic.TLSConfiguration{
|
||||||
Certificates: certs,
|
Certificates: certs,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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/provider"
|
||||||
"github.com/containous/traefik/pkg/tls"
|
"github.com/containous/traefik/pkg/tls"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -23,36 +23,36 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
ingressClass string
|
ingressClass string
|
||||||
expected *config.Configuration
|
expected *dynamic.Configuration
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Empty ingresses",
|
desc: "Empty ingresses",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with a basic rule on one path",
|
desc: "Ingress with a basic rule on one path",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
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",
|
desc: "Ingress with two different rules with one path",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
|
@ -82,11 +82,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
URL: "http://10.10.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -102,11 +102,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress one rule with two paths",
|
desc: "Ingress one rule with two paths",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
|
@ -116,11 +116,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
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",
|
desc: "Ingress one rule with one path and one host",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
URL: "http://10.10.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -165,21 +165,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
desc: "Ingress with one host without path",
|
desc: "Ingress with one host without path",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"example-com": {
|
"example-com": {
|
||||||
Rule: "Host(`example.com`)",
|
Rule: "Host(`example.com`)",
|
||||||
Service: "testing/example-com/80",
|
Service: "testing/example-com/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/example-com/80": {
|
"testing/example-com/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.11.0.1:80",
|
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",
|
desc: "Ingress one rule with one host and two paths",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
|
@ -206,11 +206,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
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",
|
desc: "Ingress Two rules with one host and one path",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
|
@ -240,11 +240,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
URL: "http://10.10.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -260,11 +260,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with a bad path syntax",
|
desc: "Ingress with a bad path syntax",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
|
@ -274,11 +274,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
URL: "http://10.10.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -294,32 +294,32 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with only a bad path syntax",
|
desc: "Ingress with only a bad path syntax",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with a bad host syntax",
|
desc: "Ingress with a bad host syntax",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-courgette/carotte": {
|
"traefik-courgette/carotte": {
|
||||||
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
|
Rule: "Host(`traefik.courgette`) && PathPrefix(`/carotte`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
URL: "http://10.10.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -335,22 +335,22 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with only a bad host syntax",
|
desc: "Ingress with only a bad host syntax",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with two services",
|
desc: "Ingress with two services",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
|
@ -360,11 +360,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service2/8082",
|
Service: "testing/service2/8082",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
URL: "http://10.10.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -375,9 +375,9 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"testing/service2/8082": {
|
"testing/service2/8082": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.2:8080",
|
URL: "http://10.10.0.2:8080",
|
||||||
},
|
},
|
||||||
|
@ -393,44 +393,44 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with one service without endpoints subset",
|
desc: "Ingress with one service without endpoints subset",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with one service without endpoint",
|
desc: "Ingress with one service without endpoint",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Single Service Ingress (without any rules)",
|
desc: "Single Service Ingress (without any rules)",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/": {
|
"/": {
|
||||||
Rule: "PathPrefix(`/`)",
|
Rule: "PathPrefix(`/`)",
|
||||||
Service: "default-backend",
|
Service: "default-backend",
|
||||||
Priority: math.MinInt32,
|
Priority: math.MinInt32,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"default-backend": {
|
"default-backend": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
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",
|
desc: "Ingress with port value in backend and no pod replica",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8089",
|
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",
|
desc: "Ingress with port name in backend and no pod replica",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/tchouk",
|
Service: "testing/service1/tchouk",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/tchouk": {
|
"testing/service1/tchouk": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8089",
|
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",
|
desc: "Ingress with with port name in backend and 2 pod replica",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/tchouk",
|
Service: "testing/service1/tchouk",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/tchouk": {
|
"testing/service1/tchouk": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8089",
|
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",
|
desc: "Ingress with two paths using same service and different port name",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/tchouk",
|
Service: "testing/service1/tchouk",
|
||||||
|
@ -550,11 +550,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "testing/service1/carotte",
|
Service: "testing/service1/carotte",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/tchouk": {
|
"testing/service1/tchouk": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8089",
|
URL: "http://10.10.0.1:8089",
|
||||||
},
|
},
|
||||||
|
@ -565,9 +565,9 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"testing/service1/carotte": {
|
"testing/service1/carotte": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8090",
|
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",
|
desc: "2 ingresses in different namespace with same service name",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/tchouk",
|
Service: "testing/service1/tchouk",
|
||||||
|
@ -597,11 +597,11 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
Service: "toto/service1/tchouk",
|
Service: "toto/service1/tchouk",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/tchouk": {
|
"testing/service1/tchouk": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8089",
|
URL: "http://10.10.0.1:8089",
|
||||||
},
|
},
|
||||||
|
@ -612,9 +612,9 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"toto/service1/tchouk": {
|
"toto/service1/tchouk": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.11.0.1:8089",
|
URL: "http://10.11.0.1:8089",
|
||||||
},
|
},
|
||||||
|
@ -630,43 +630,43 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with unknown service port name",
|
desc: "Ingress with unknown service port name",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with unknown service port",
|
desc: "Ingress with unknown service port",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with service with externalName",
|
desc: "Ingress with service with externalName",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"traefik-tchouk/bar": {
|
"traefik-tchouk/bar": {
|
||||||
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
Rule: "Host(`traefik.tchouk`) && PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/8080",
|
Service: "testing/service1/8080",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/8080": {
|
"testing/service1/8080": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://traefik.wtf:8080",
|
URL: "http://traefik.wtf:8080",
|
||||||
},
|
},
|
||||||
|
@ -679,21 +679,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "TLS support",
|
desc: "TLS support",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"example-com": {
|
"example-com": {
|
||||||
Rule: "Host(`example.com`)",
|
Rule: "Host(`example.com`)",
|
||||||
Service: "testing/example-com/80",
|
Service: "testing/example-com/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/example-com/80": {
|
"testing/example-com/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.11.0.1:80",
|
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{
|
Certificates: []*tls.CertAndStores{
|
||||||
{
|
{
|
||||||
Certificate: tls.Certificate{
|
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)",
|
desc: "Ingress with a basic rule on one path with https (port == 443)",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/443",
|
Service: "testing/service1/443",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/443": {
|
"testing/service1/443": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "https://10.10.0.1:443",
|
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)",
|
desc: "Ingress with a basic rule on one path with https (portname == https)",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/8443",
|
Service: "testing/service1/8443",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/8443": {
|
"testing/service1/8443": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "https://10.10.0.1:8443",
|
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)",
|
desc: "Ingress with a basic rule on one path with https (portname starts with https)",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
|
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/8443",
|
Service: "testing/service1/8443",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/8443": {
|
"testing/service1/8443": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "https://10.10.0.1:8443",
|
URL: "https://10.10.0.1:8443",
|
||||||
},
|
},
|
||||||
|
@ -807,22 +807,22 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Double Single Service Ingress",
|
desc: "Double Single Service Ingress",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/": {
|
"/": {
|
||||||
Rule: "PathPrefix(`/`)",
|
Rule: "PathPrefix(`/`)",
|
||||||
Service: "default-backend",
|
Service: "default-backend",
|
||||||
Priority: math.MinInt32,
|
Priority: math.MinInt32,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"default-backend": {
|
"default-backend": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.30.0.1:8080",
|
URL: "http://10.30.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -838,21 +838,21 @@ func TestLoadConfigurationFromIngresses(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with default traefik ingressClass",
|
desc: "Ingress with default traefik ingressClass",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"/bar": {
|
"/bar": {
|
||||||
Rule: "PathPrefix(`/bar`)",
|
Rule: "PathPrefix(`/bar`)",
|
||||||
Service: "testing/service1/80",
|
Service: "testing/service1/80",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"testing/service1/80": {
|
"testing/service1/80": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://10.10.0.1:8080",
|
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",
|
desc: "Ingress without provider traefik ingressClass and unknown annotation",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with non matching provider traefik ingressClass and annotation",
|
desc: "Ingress with non matching provider traefik ingressClass and annotation",
|
||||||
ingressClass: "tchouk",
|
ingressClass: "tchouk",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with ingressClass without annotation",
|
desc: "Ingress with ingressClass without annotation",
|
||||||
ingressClass: "tchouk",
|
ingressClass: "tchouk",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Ingress with ingressClass without annotation",
|
desc: "Ingress with ingressClass without annotation",
|
||||||
ingressClass: "toto",
|
ingressClass: "toto",
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{},
|
TCP: &dynamic.TCPConfiguration{},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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/config/label"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"github.com/containous/traefik/pkg/provider"
|
||||||
|
@ -17,8 +17,8 @@ import (
|
||||||
"github.com/gambol99/go-marathon"
|
"github.com/gambol99/go-marathon"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Provider) buildConfiguration(ctx context.Context, applications *marathon.Applications) *config.Configuration {
|
func (p *Provider) buildConfiguration(ctx context.Context, applications *marathon.Applications) *dynamic.Configuration {
|
||||||
configurations := make(map[string]*config.Configuration)
|
configurations := make(map[string]*dynamic.Configuration)
|
||||||
|
|
||||||
for _, app := range applications.Apps {
|
for _, app := range applications.Apps {
|
||||||
ctxApp := log.With(ctx, log.Str("applicationID", app.ID))
|
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)
|
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)
|
appName := getServiceName(app)
|
||||||
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
|
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
|
||||||
|
|
||||||
if len(conf.Services) == 0 {
|
if len(conf.Services) == 0 {
|
||||||
conf.Services = make(map[string]*config.Service)
|
conf.Services = make(map[string]*dynamic.Service)
|
||||||
lb := &config.LoadBalancerService{}
|
lb := &dynamic.LoadBalancerService{}
|
||||||
lb.SetDefaults()
|
lb.SetDefaults()
|
||||||
conf.Services[appName] = &config.Service{
|
conf.Services[appName] = &dynamic.Service{
|
||||||
LoadBalancer: lb,
|
LoadBalancer: lb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for serviceName, service := range conf.Services {
|
for serviceName, service := range conf.Services {
|
||||||
var servers []config.Server
|
var servers []dynamic.Server
|
||||||
|
|
||||||
defaultServer := config.Server{}
|
defaultServer := dynamic.Server{}
|
||||||
defaultServer.SetDefaults()
|
defaultServer.SetDefaults()
|
||||||
|
|
||||||
if len(service.LoadBalancer.Servers) > 0 {
|
if len(service.LoadBalancer.Servers) > 0 {
|
||||||
|
@ -134,22 +134,22 @@ func (p *Provider) buildServiceConfiguration(ctx context.Context, app marathon.A
|
||||||
return nil
|
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)
|
appName := getServiceName(app)
|
||||||
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
|
appCtx := log.With(ctx, log.Str("ApplicationID", appName))
|
||||||
|
|
||||||
if len(conf.Services) == 0 {
|
if len(conf.Services) == 0 {
|
||||||
conf.Services = make(map[string]*config.TCPService)
|
conf.Services = make(map[string]*dynamic.TCPService)
|
||||||
lb := &config.TCPLoadBalancerService{}
|
lb := &dynamic.TCPLoadBalancerService{}
|
||||||
conf.Services[appName] = &config.TCPService{
|
conf.Services[appName] = &dynamic.TCPService{
|
||||||
LoadBalancer: lb,
|
LoadBalancer: lb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for serviceName, service := range conf.Services {
|
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 {
|
if len(service.LoadBalancer.Servers) > 0 {
|
||||||
defaultServer = 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
|
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)
|
host, err := p.getServerHost(task, app, extraConf)
|
||||||
if len(host) == 0 {
|
if len(host) == 0 {
|
||||||
return config.TCPServer{}, err
|
return dynamic.TCPServer{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := getPort(task, app, defaultServer.Port)
|
port, err := getPort(task, app, defaultServer.Port)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return config.TCPServer{}, err
|
return dynamic.TCPServer{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
server := config.TCPServer{
|
server := dynamic.TCPServer{
|
||||||
Address: net.JoinHostPort(host, port),
|
Address: net.JoinHostPort(host, port),
|
||||||
}
|
}
|
||||||
|
|
||||||
return server, nil
|
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)
|
host, err := p.getServerHost(task, app, extraConf)
|
||||||
if len(host) == 0 {
|
if len(host) == 0 {
|
||||||
return config.Server{}, err
|
return dynamic.Server{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
port, err := getPort(task, app, defaultServer.Port)
|
port, err := getPort(task, app, defaultServer.Port)
|
||||||
if err != nil {
|
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)),
|
URL: fmt.Sprintf("%s://%s", defaultServer.Scheme, net.JoinHostPort(host, port)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -10,7 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff"
|
"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/job"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"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
|
// Provide allows the marathon provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// 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"))
|
ctx := log.With(context.Background(), log.Str(log.ProviderName, "marathon"))
|
||||||
logger := log.FromContext(ctx)
|
logger := log.FromContext(ctx)
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
|
|
||||||
conf := p.getConfigurations(ctx)
|
conf := p.getConfigurations(ctx)
|
||||||
if conf != nil {
|
if conf != nil {
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "marathon",
|
ProviderName: "marathon",
|
||||||
Configuration: conf,
|
Configuration: conf,
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration := p.getConfigurations(ctx)
|
configuration := p.getConfigurations(ctx)
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "marathon",
|
ProviderName: "marathon",
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ func (p *Provider) Provide(configurationChan chan<- config.Message, pool *safe.P
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Provider) getConfigurations(ctx context.Context) *config.Configuration {
|
func (p *Provider) getConfigurations(ctx context.Context) *dynamic.Configuration {
|
||||||
applications, err := p.getApplications()
|
applications, err := p.getApplications()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.FromContext(ctx).Errorf("Failed to retrieve Marathon applications: %v", err)
|
log.FromContext(ctx).Errorf("Failed to retrieve Marathon applications: %v", err)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package provider
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"github.com/containous/traefik/pkg/safe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ import (
|
||||||
type Provider interface {
|
type Provider interface {
|
||||||
// Provide allows the provider to provide configurations to traefik
|
// Provide allows the provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// 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
|
Init() error
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,15 +7,15 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"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/config/label"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"github.com/containous/traefik/pkg/provider"
|
||||||
"github.com/containous/traefik/pkg/provider/constraints"
|
"github.com/containous/traefik/pkg/provider/constraints"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p *Provider) buildConfiguration(ctx context.Context, services []rancherData) *config.Configuration {
|
func (p *Provider) buildConfiguration(ctx context.Context, services []rancherData) *dynamic.Configuration {
|
||||||
configurations := make(map[string]*config.Configuration)
|
configurations := make(map[string]*dynamic.Configuration)
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
ctxService := log.With(ctx, log.Str("service", service.Name))
|
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)
|
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
|
serviceName := service.Name
|
||||||
|
|
||||||
if len(configuration.Services) == 0 {
|
if len(configuration.Services) == 0 {
|
||||||
configuration.Services = make(map[string]*config.TCPService)
|
configuration.Services = make(map[string]*dynamic.TCPService)
|
||||||
lb := &config.TCPLoadBalancerService{}
|
lb := &dynamic.TCPLoadBalancerService{}
|
||||||
configuration.Services[serviceName] = &config.TCPService{
|
configuration.Services[serviceName] = &dynamic.TCPService{
|
||||||
LoadBalancer: lb,
|
LoadBalancer: lb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,15 +90,15 @@ func (p *Provider) buildTCPServiceConfiguration(ctx context.Context, service ran
|
||||||
return nil
|
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
|
serviceName := service.Name
|
||||||
|
|
||||||
if len(configuration.Services) == 0 {
|
if len(configuration.Services) == 0 {
|
||||||
configuration.Services = make(map[string]*config.Service)
|
configuration.Services = make(map[string]*dynamic.Service)
|
||||||
lb := &config.LoadBalancerService{}
|
lb := &dynamic.LoadBalancerService{}
|
||||||
lb.SetDefaults()
|
lb.SetDefaults()
|
||||||
configuration.Services[serviceName] = &config.Service{
|
configuration.Services[serviceName] = &dynamic.Service{
|
||||||
LoadBalancer: lb,
|
LoadBalancer: lb,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (p *Provider) keepService(ctx context.Context, service rancherData) bool {
|
||||||
return true
|
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)
|
log.FromContext(ctx).Debugf("Trying to add servers for service %s \n", service.Name)
|
||||||
|
|
||||||
serverPort := ""
|
serverPort := ""
|
||||||
|
@ -157,9 +157,9 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
|
||||||
port := getServicePort(service)
|
port := getServicePort(service)
|
||||||
|
|
||||||
if len(loadBalancer.Servers) == 0 {
|
if len(loadBalancer.Servers) == 0 {
|
||||||
server := config.TCPServer{}
|
server := dynamic.TCPServer{}
|
||||||
|
|
||||||
loadBalancer.Servers = []config.TCPServer{server}
|
loadBalancer.Servers = []dynamic.TCPServer{server}
|
||||||
}
|
}
|
||||||
|
|
||||||
if serverPort != "" {
|
if serverPort != "" {
|
||||||
|
@ -171,9 +171,9 @@ func (p *Provider) addServerTCP(ctx context.Context, service rancherData, loadBa
|
||||||
return errors.New("port is missing")
|
return errors.New("port is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
var servers []config.TCPServer
|
var servers []dynamic.TCPServer
|
||||||
for _, containerIP := range service.Containers {
|
for _, containerIP := range service.Containers {
|
||||||
servers = append(servers, config.TCPServer{
|
servers = append(servers, dynamic.TCPServer{
|
||||||
Address: net.JoinHostPort(containerIP, port),
|
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)
|
log.FromContext(ctx).Debugf("Trying to add servers for service %s \n", service.Name)
|
||||||
|
|
||||||
serverPort := getLBServerPort(loadBalancer)
|
serverPort := getLBServerPort(loadBalancer)
|
||||||
port := getServicePort(service)
|
port := getServicePort(service)
|
||||||
|
|
||||||
if len(loadBalancer.Servers) == 0 {
|
if len(loadBalancer.Servers) == 0 {
|
||||||
server := config.Server{}
|
server := dynamic.Server{}
|
||||||
server.SetDefaults()
|
server.SetDefaults()
|
||||||
|
|
||||||
loadBalancer.Servers = []config.Server{server}
|
loadBalancer.Servers = []dynamic.Server{server}
|
||||||
}
|
}
|
||||||
|
|
||||||
if serverPort != "" {
|
if serverPort != "" {
|
||||||
|
@ -205,9 +205,9 @@ func (p *Provider) addServers(ctx context.Context, service rancherData, loadBala
|
||||||
return errors.New("port is missing")
|
return errors.New("port is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
var servers []config.Server
|
var servers []dynamic.Server
|
||||||
for _, containerIP := range service.Containers {
|
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)),
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLBServerPort(loadBalancer *config.LoadBalancerService) string {
|
func getLBServerPort(loadBalancer *dynamic.LoadBalancerService) string {
|
||||||
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
|
if loadBalancer != nil && len(loadBalancer.Servers) > 0 {
|
||||||
return loadBalancer.Servers[0].Port
|
return loadBalancer.Servers[0].Port
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -14,7 +14,7 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
desc string
|
desc string
|
||||||
containers []rancherData
|
containers []rancherData
|
||||||
constraints string
|
constraints string
|
||||||
expected *config.Configuration
|
expected *dynamic.Configuration
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "one service no label",
|
desc: "one service no label",
|
||||||
|
@ -28,23 +28,23 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test": {
|
"Test": {
|
||||||
Service: "Test",
|
Service: "Test",
|
||||||
Rule: "Host(`Test.traefik.wtf`)",
|
Rule: "Host(`Test.traefik.wtf`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Test": {
|
"Test": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -76,13 +76,13 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test1": {
|
"Test1": {
|
||||||
Service: "Test1",
|
Service: "Test1",
|
||||||
Rule: "Host(`Test1.traefik.wtf`)",
|
Rule: "Host(`Test1.traefik.wtf`)",
|
||||||
|
@ -92,11 +92,11 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
Rule: "Host(`Test2.traefik.wtf`)",
|
Rule: "Host(`Test2.traefik.wtf`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Test1": {
|
"Test1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -105,8 +105,8 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Test2": {
|
"Test2": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.2:80",
|
URL: "http://127.0.0.2:80",
|
||||||
},
|
},
|
||||||
|
@ -138,13 +138,13 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test1": {
|
"Test1": {
|
||||||
Service: "Test1",
|
Service: "Test1",
|
||||||
Rule: "Host(`Test1.traefik.wtf`)",
|
Rule: "Host(`Test1.traefik.wtf`)",
|
||||||
|
@ -154,11 +154,11 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
Rule: "Host(`Test2.traefik.wtf`)",
|
Rule: "Host(`Test2.traefik.wtf`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Test1": {
|
"Test1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -170,8 +170,8 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"Test2": {
|
"Test2": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://128.0.0.1:80",
|
URL: "http://128.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -199,23 +199,23 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Router1": {
|
"Router1": {
|
||||||
Service: "Service1",
|
Service: "Service1",
|
||||||
Rule: "Host(`foo.com`)",
|
Rule: "Host(`foo.com`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Service1": {
|
"Service1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -238,15 +238,15 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -261,15 +261,15 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "upgradefailed",
|
State: "upgradefailed",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -287,23 +287,23 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Router1": {
|
"Router1": {
|
||||||
Service: "Test",
|
Service: "Test",
|
||||||
Rule: "Host(`foo.com`)",
|
Rule: "Host(`foo.com`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Test": {
|
"Test": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -330,15 +330,15 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
constraints: `Label("traefik.tags", "bar")`,
|
constraints: `Label("traefik.tags", "bar")`,
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -357,23 +357,23 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
constraints: `Label("traefik.tags", "foo")`,
|
constraints: `Label("traefik.tags", "foo")`,
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test": {
|
"Test": {
|
||||||
Service: "Test",
|
Service: "Test",
|
||||||
Rule: "Host(`Test.traefik.wtf`)",
|
Rule: "Host(`Test.traefik.wtf`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Test": {
|
"Test": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -400,22 +400,22 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test": {
|
"Test": {
|
||||||
Service: "Test",
|
Service: "Test",
|
||||||
Rule: "Host(`Test.traefik.wtf`)",
|
Rule: "Host(`Test.traefik.wtf`)",
|
||||||
Middlewares: []string{"Middleware1"},
|
Middlewares: []string{"Middleware1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"Middleware1": {
|
"Middleware1": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{
|
Users: []string{
|
||||||
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
|
"test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/",
|
||||||
"test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0",
|
"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": {
|
"Test": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -452,23 +452,23 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{},
|
Services: map[string]*dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test": {
|
"Test": {
|
||||||
Service: "Test",
|
Service: "Test",
|
||||||
Rule: "Host(`Test.traefik.wtf`)",
|
Rule: "Host(`Test.traefik.wtf`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Test": {
|
"Test": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -495,19 +495,19 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{
|
Routers: map[string]*dynamic.TCPRouter{
|
||||||
"foo": {
|
"foo": {
|
||||||
Service: "Test",
|
Service: "Test",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
TLS: &config.RouterTCPTLSConfig{},
|
TLS: &dynamic.RouterTCPTLSConfig{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"Test": {
|
"Test": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:80",
|
Address: "127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -516,10 +516,10 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -537,13 +537,13 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"Test": {
|
"Test": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:80",
|
Address: "127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -552,10 +552,10 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -574,18 +574,18 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{
|
Routers: map[string]*dynamic.TCPRouter{
|
||||||
"foo": {
|
"foo": {
|
||||||
Service: "foo",
|
Service: "foo",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"foo": {
|
"foo": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:8080",
|
Address: "127.0.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -594,10 +594,10 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -618,19 +618,19 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{
|
Routers: map[string]*dynamic.TCPRouter{
|
||||||
"foo": {
|
"foo": {
|
||||||
Service: "foo",
|
Service: "foo",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
TLS: &config.RouterTCPTLSConfig{},
|
TLS: &dynamic.RouterTCPTLSConfig{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"foo": {
|
"foo": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:8080",
|
Address: "127.0.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -642,18 +642,18 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"Test": {
|
"Test": {
|
||||||
Service: "Service1",
|
Service: "Service1",
|
||||||
Rule: "Host(`Test.traefik.wtf`)",
|
Rule: "Host(`Test.traefik.wtf`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"Service1": {
|
"Service1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:80",
|
URL: "http://127.0.0.1:80",
|
||||||
},
|
},
|
||||||
|
@ -682,13 +682,13 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
State: "",
|
State: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.Configuration{
|
expected: &dynamic.Configuration{
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: map[string]*config.TCPRouter{},
|
Routers: map[string]*dynamic.TCPRouter{},
|
||||||
Services: map[string]*config.TCPService{
|
Services: map[string]*dynamic.TCPService{
|
||||||
"foo": {
|
"foo": {
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:8080",
|
Address: "127.0.0.1:8080",
|
||||||
},
|
},
|
||||||
|
@ -697,10 +697,10 @@ func Test_buildConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{},
|
Routers: map[string]*dynamic.Router{},
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
Services: map[string]*config.Service{},
|
Services: map[string]*dynamic.Service{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cenkalti/backoff"
|
"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/job"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"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.
|
// 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) {
|
pool.GoCtx(func(routineCtx context.Context) {
|
||||||
ctxLog := log.With(routineCtx, log.Str(log.ProviderName, "rancher"))
|
ctxLog := log.With(routineCtx, log.Str(log.ProviderName, "rancher"))
|
||||||
logger := log.FromContext(ctxLog)
|
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)
|
logger.Printf("Received Rancher data %+v", rancherData)
|
||||||
|
|
||||||
configuration := p.buildConfiguration(ctxLog, rancherData)
|
configuration := p.buildConfiguration(ctxLog, rancherData)
|
||||||
configurationChan <- config.Message{
|
configurationChan <- dynamic.Message{
|
||||||
ProviderName: "rancher",
|
ProviderName: "rancher",
|
||||||
Configuration: configuration,
|
Configuration: configuration,
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containous/mux"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/provider"
|
"github.com/containous/traefik/pkg/provider"
|
||||||
"github.com/containous/traefik/pkg/safe"
|
"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.
|
// Provider is a provider.Provider implementation that provides a Rest API.
|
||||||
type Provider struct {
|
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"`
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
configuration := new(config.HTTPConfiguration)
|
configuration := new(dynamic.HTTPConfiguration)
|
||||||
body, _ := ioutil.ReadAll(request.Body)
|
body, _ := ioutil.ReadAll(request.Body)
|
||||||
|
|
||||||
if err := json.Unmarshal(body, configuration); err != nil {
|
if err := json.Unmarshal(body, configuration); err != nil {
|
||||||
|
@ -57,7 +57,7 @@ func (p *Provider) Append(systemRouter *mux.Router) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.configurationChan <- config.Message{ProviderName: "rest", Configuration: &config.Configuration{
|
p.configurationChan <- dynamic.Message{ProviderName: "rest", Configuration: &dynamic.Configuration{
|
||||||
HTTP: configuration,
|
HTTP: configuration,
|
||||||
}}
|
}}
|
||||||
if err := templatesRenderer.JSON(response, http.StatusOK, configuration); err != nil {
|
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
|
// Provide allows the provider to provide configurations to traefik
|
||||||
// using the given configuration channel.
|
// 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
|
p.configurationChan = configurationChan
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@ package responsemodifiers
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/middlewares/headers"
|
"github.com/containous/traefik/pkg/middlewares/headers"
|
||||||
"github.com/unrolled/secure"
|
"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{
|
opt := secure.Options{
|
||||||
BrowserXssFilter: hdrs.BrowserXSSFilter,
|
BrowserXssFilter: hdrs.BrowserXSSFilter,
|
||||||
ContentTypeNosniff: hdrs.ContentTypeNosniff,
|
ContentTypeNosniff: hdrs.ContentTypeNosniff,
|
||||||
|
|
|
@ -4,17 +4,17 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewBuilder creates a builder.
|
// NewBuilder creates a builder.
|
||||||
func NewBuilder(configs map[string]*config.MiddlewareInfo) *Builder {
|
func NewBuilder(configs map[string]*dynamic.MiddlewareInfo) *Builder {
|
||||||
return &Builder{configs: configs}
|
return &Builder{configs: configs}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builder holds builder configuration.
|
// Builder holds builder configuration.
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
configs map[string]*config.MiddlewareInfo
|
configs map[string]*dynamic.MiddlewareInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build Builds the response modifier.
|
// Build Builds the response modifier.
|
||||||
|
|
|
@ -6,13 +6,13 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/middlewares/headers"
|
"github.com/containous/traefik/pkg/middlewares/headers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"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)}
|
return &http.Response{Header: make(http.Header)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,24 +21,24 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
desc string
|
desc string
|
||||||
middlewares []string
|
middlewares []string
|
||||||
// buildResponse is needed because secure use a private context key
|
// buildResponse is needed because secure use a private context key
|
||||||
buildResponse func(map[string]*config.Middleware) *http.Response
|
buildResponse func(map[string]*dynamic.Middleware) *http.Response
|
||||||
conf map[string]*config.Middleware
|
conf map[string]*dynamic.Middleware
|
||||||
assertResponse func(*testing.T, *http.Response)
|
assertResponse func(*testing.T, *http.Response)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "no configuration",
|
desc: "no configuration",
|
||||||
middlewares: []string{"foo", "bar"},
|
middlewares: []string{"foo", "bar"},
|
||||||
buildResponse: stubResponse,
|
buildResponse: stubResponse,
|
||||||
conf: map[string]*config.Middleware{},
|
conf: map[string]*dynamic.Middleware{},
|
||||||
assertResponse: func(t *testing.T, resp *http.Response) {},
|
assertResponse: func(t *testing.T, resp *http.Response) {},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "one modifier",
|
desc: "one modifier",
|
||||||
middlewares: []string{"foo", "bar"},
|
middlewares: []string{"foo", "bar"},
|
||||||
buildResponse: stubResponse,
|
buildResponse: stubResponse,
|
||||||
conf: map[string]*config.Middleware{
|
conf: map[string]*dynamic.Middleware{
|
||||||
"foo": {
|
"foo": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -52,7 +52,7 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "secure: one modifier",
|
desc: "secure: one modifier",
|
||||||
middlewares: []string{"foo", "bar"},
|
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()
|
ctx := context.Background()
|
||||||
|
|
||||||
var request *http.Request
|
var request *http.Request
|
||||||
|
@ -69,14 +69,14 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
|
|
||||||
return &http.Response{Header: make(http.Header), Request: request}
|
return &http.Response{Header: make(http.Header), Request: request}
|
||||||
},
|
},
|
||||||
conf: map[string]*config.Middleware{
|
conf: map[string]*dynamic.Middleware{
|
||||||
"foo": {
|
"foo": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
ReferrerPolicy: "no-referrer",
|
ReferrerPolicy: "no-referrer",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
|
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -91,14 +91,14 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
desc: "two modifiers",
|
desc: "two modifiers",
|
||||||
middlewares: []string{"foo", "bar"},
|
middlewares: []string{"foo", "bar"},
|
||||||
buildResponse: stubResponse,
|
buildResponse: stubResponse,
|
||||||
conf: map[string]*config.Middleware{
|
conf: map[string]*dynamic.Middleware{
|
||||||
"foo": {
|
"foo": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
|
CustomResponseHeaders: map[string]string{"X-Bar": "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -114,14 +114,14 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
desc: "modifier order",
|
desc: "modifier order",
|
||||||
middlewares: []string{"foo", "bar"},
|
middlewares: []string{"foo", "bar"},
|
||||||
buildResponse: stubResponse,
|
buildResponse: stubResponse,
|
||||||
conf: map[string]*config.Middleware{
|
conf: map[string]*dynamic.Middleware{
|
||||||
"foo": {
|
"foo": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
|
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -136,19 +136,19 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
desc: "chain",
|
desc: "chain",
|
||||||
middlewares: []string{"chain"},
|
middlewares: []string{"chain"},
|
||||||
buildResponse: stubResponse,
|
buildResponse: stubResponse,
|
||||||
conf: map[string]*config.Middleware{
|
conf: map[string]*dynamic.Middleware{
|
||||||
"foo": {
|
"foo": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
CustomResponseHeaders: map[string]string{"X-Foo": "foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
|
CustomResponseHeaders: map[string]string{"X-Foo": "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"chain": {
|
"chain": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"foo", "bar"},
|
Middlewares: []string{"foo", "bar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -166,8 +166,8 @@ func TestBuilderBuild(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: test.conf,
|
Middlewares: test.conf,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
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/log"
|
||||||
"github.com/containous/traefik/pkg/server/internal"
|
"github.com/containous/traefik/pkg/server/internal"
|
||||||
"github.com/containous/traefik/pkg/tls"
|
"github.com/containous/traefik/pkg/tls"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mergeConfiguration(configurations config.Configurations) config.Configuration {
|
func mergeConfiguration(configurations dynamic.Configurations) dynamic.Configuration {
|
||||||
conf := config.Configuration{
|
conf := dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: make(map[string]*config.Router),
|
Routers: make(map[string]*dynamic.Router),
|
||||||
Middlewares: make(map[string]*config.Middleware),
|
Middlewares: make(map[string]*dynamic.Middleware),
|
||||||
Services: make(map[string]*config.Service),
|
Services: make(map[string]*dynamic.Service),
|
||||||
},
|
},
|
||||||
TCP: &config.TCPConfiguration{
|
TCP: &dynamic.TCPConfiguration{
|
||||||
Routers: make(map[string]*config.TCPRouter),
|
Routers: make(map[string]*dynamic.TCPRouter),
|
||||||
Services: make(map[string]*config.TCPService),
|
Services: make(map[string]*dynamic.TCPService),
|
||||||
},
|
},
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Stores: make(map[string]tls.Store),
|
Stores: make(map[string]tls.Store),
|
||||||
Options: make(map[string]tls.Options),
|
Options: make(map[string]tls.Options),
|
||||||
},
|
},
|
||||||
|
|
|
@ -3,7 +3,7 @@ package server
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/containous/traefik/pkg/config"
|
"github.com/containous/traefik/pkg/config/dynamic"
|
||||||
"github.com/containous/traefik/pkg/tls"
|
"github.com/containous/traefik/pkg/tls"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
@ -11,87 +11,87 @@ import (
|
||||||
func TestAggregator(t *testing.T) {
|
func TestAggregator(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
given config.Configurations
|
given dynamic.Configurations
|
||||||
expected *config.HTTPConfiguration
|
expected *dynamic.HTTPConfiguration
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Nil returns an empty configuration",
|
desc: "Nil returns an empty configuration",
|
||||||
given: nil,
|
given: nil,
|
||||||
expected: &config.HTTPConfiguration{
|
expected: &dynamic.HTTPConfiguration{
|
||||||
Routers: make(map[string]*config.Router),
|
Routers: make(map[string]*dynamic.Router),
|
||||||
Middlewares: make(map[string]*config.Middleware),
|
Middlewares: make(map[string]*dynamic.Middleware),
|
||||||
Services: make(map[string]*config.Service),
|
Services: make(map[string]*dynamic.Service),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Returns fully qualified elements from a mono-provider configuration map",
|
desc: "Returns fully qualified elements from a mono-provider configuration map",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router-1": {},
|
"router-1": {},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"middleware-1": {},
|
"middleware-1": {},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"service-1": {},
|
"service-1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.HTTPConfiguration{
|
expected: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router-1@provider-1": {},
|
"router-1@provider-1": {},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"middleware-1@provider-1": {},
|
"middleware-1@provider-1": {},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"service-1@provider-1": {},
|
"service-1@provider-1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Returns fully qualified elements from a multi-provider configuration map",
|
desc: "Returns fully qualified elements from a multi-provider configuration map",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router-1": {},
|
"router-1": {},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"middleware-1": {},
|
"middleware-1": {},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"service-1": {},
|
"service-1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"provider-2": &config.Configuration{
|
"provider-2": &dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router-1": {},
|
"router-1": {},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"middleware-1": {},
|
"middleware-1": {},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"service-1": {},
|
"service-1": {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: &config.HTTPConfiguration{
|
expected: &dynamic.HTTPConfiguration{
|
||||||
Routers: map[string]*config.Router{
|
Routers: map[string]*dynamic.Router{
|
||||||
"router-1@provider-1": {},
|
"router-1@provider-1": {},
|
||||||
"router-1@provider-2": {},
|
"router-1@provider-2": {},
|
||||||
},
|
},
|
||||||
Middlewares: map[string]*config.Middleware{
|
Middlewares: map[string]*dynamic.Middleware{
|
||||||
"middleware-1@provider-1": {},
|
"middleware-1@provider-1": {},
|
||||||
"middleware-1@provider-2": {},
|
"middleware-1@provider-2": {},
|
||||||
},
|
},
|
||||||
Services: map[string]*config.Service{
|
Services: map[string]*dynamic.Service{
|
||||||
"service-1@provider-1": {},
|
"service-1@provider-1": {},
|
||||||
"service-1@provider-2": {},
|
"service-1@provider-2": {},
|
||||||
},
|
},
|
||||||
|
@ -113,7 +113,7 @@ func TestAggregator(t *testing.T) {
|
||||||
func TestAggregator_tlsoptions(t *testing.T) {
|
func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
given config.Configurations
|
given dynamic.Configurations
|
||||||
expected map[string]tls.Options
|
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",
|
desc: "Returns fully qualified elements from a mono-provider configuration map",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS12",
|
MinVersion: "VersionTLS12",
|
||||||
|
@ -145,9 +145,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Returns fully qualified elements from a multi-provider configuration map",
|
desc: "Returns fully qualified elements from a multi-provider configuration map",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS13",
|
MinVersion: "VersionTLS13",
|
||||||
|
@ -155,8 +155,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"provider-2": &config.Configuration{
|
"provider-2": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS12",
|
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",
|
desc: "Create a valid default tls option when appears only in one provider",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS13",
|
MinVersion: "VersionTLS13",
|
||||||
|
@ -190,8 +190,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"provider-2": &config.Configuration{
|
"provider-2": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS12",
|
MinVersion: "VersionTLS12",
|
||||||
|
@ -214,9 +214,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "No default tls option if it is defined in multiple providers",
|
desc: "No default tls option if it is defined in multiple providers",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS12",
|
MinVersion: "VersionTLS12",
|
||||||
|
@ -227,8 +227,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"provider-2": &config.Configuration{
|
"provider-2": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS13",
|
MinVersion: "VersionTLS13",
|
||||||
|
@ -251,9 +251,9 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Create a default TLS Options configuration if none was provided",
|
desc: "Create a default TLS Options configuration if none was provided",
|
||||||
given: config.Configurations{
|
given: dynamic.Configurations{
|
||||||
"provider-1": &config.Configuration{
|
"provider-1": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS12",
|
MinVersion: "VersionTLS12",
|
||||||
|
@ -261,8 +261,8 @@ func TestAggregator_tlsoptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"provider-2": &config.Configuration{
|
"provider-2": &dynamic.Configuration{
|
||||||
TLS: &config.TLSConfiguration{
|
TLS: &dynamic.TLSConfiguration{
|
||||||
Options: map[string]tls.Options{
|
Options: map[string]tls.Options{
|
||||||
"foo": {
|
"foo": {
|
||||||
MinVersion: "VersionTLS13",
|
MinVersion: "VersionTLS13",
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containous/alice"
|
"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/addprefix"
|
||||||
"github.com/containous/traefik/pkg/middlewares/auth"
|
"github.com/containous/traefik/pkg/middlewares/auth"
|
||||||
"github.com/containous/traefik/pkg/middlewares/buffering"
|
"github.com/containous/traefik/pkg/middlewares/buffering"
|
||||||
|
@ -39,7 +39,7 @@ const (
|
||||||
|
|
||||||
// Builder the middleware builder
|
// Builder the middleware builder
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
configs map[string]*config.MiddlewareInfo
|
configs map[string]*dynamic.MiddlewareInfo
|
||||||
serviceBuilder serviceBuilder
|
serviceBuilder serviceBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ type serviceBuilder interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBuilder creates a new Builder
|
// 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}
|
return &Builder{configs: configs, serviceBuilder: serviceBuilder}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,14 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"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/server/internal"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuilder_BuildChainNilConfig(t *testing.T) {
|
func TestBuilder_BuildChainNilConfig(t *testing.T) {
|
||||||
testConfig := map[string]*config.MiddlewareInfo{
|
testConfig := map[string]*dynamic.MiddlewareInfo{
|
||||||
"empty": {},
|
"empty": {},
|
||||||
}
|
}
|
||||||
middlewaresBuilder := NewBuilder(testConfig, nil)
|
middlewaresBuilder := NewBuilder(testConfig, nil)
|
||||||
|
@ -25,7 +25,7 @@ func TestBuilder_BuildChainNilConfig(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
|
func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
|
||||||
testConfig := map[string]*config.MiddlewareInfo{
|
testConfig := map[string]*dynamic.MiddlewareInfo{
|
||||||
"foobar": {},
|
"foobar": {},
|
||||||
}
|
}
|
||||||
middlewaresBuilder := NewBuilder(testConfig, nil)
|
middlewaresBuilder := NewBuilder(testConfig, nil)
|
||||||
|
@ -39,7 +39,7 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
buildChain []string
|
buildChain []string
|
||||||
configuration map[string]*config.Middleware
|
configuration map[string]*dynamic.Middleware
|
||||||
expected map[string]string
|
expected map[string]string
|
||||||
contextProvider string
|
contextProvider string
|
||||||
expectedError error
|
expectedError error
|
||||||
|
@ -47,9 +47,9 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Simple middleware",
|
desc: "Simple middleware",
|
||||||
buildChain: []string{"middleware-1"},
|
buildChain: []string{"middleware-1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"middleware-1": {
|
"middleware-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
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",
|
desc: "Middleware that references a chain",
|
||||||
buildChain: []string{"middleware-chain-1"},
|
buildChain: []string{"middleware-chain-1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"middleware-1": {
|
"middleware-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"middleware-chain-1": {
|
"middleware-chain-1": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"middleware-1"},
|
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",
|
desc: "Should suffix the middlewareName with the provider in the context",
|
||||||
buildChain: []string{"middleware-1"},
|
buildChain: []string{"middleware-1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"middleware-1@provider-1": {
|
"middleware-1@provider-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-1@provider-1": "value-middleware-1"},
|
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",
|
desc: "Should not suffix a qualified middlewareName with the provider in the context",
|
||||||
buildChain: []string{"middleware-1@provider-1"},
|
buildChain: []string{"middleware-1@provider-1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"middleware-1@provider-1": {
|
"middleware-1@provider-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-1@provider-1": "value-middleware-1"},
|
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",
|
desc: "Should be context aware if a chain references another middleware",
|
||||||
buildChain: []string{"middleware-chain-1@provider-1"},
|
buildChain: []string{"middleware-chain-1@provider-1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"middleware-1@provider-1": {
|
"middleware-1@provider-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"middleware-chain-1@provider-1": {
|
"middleware-chain-1@provider-1": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"middleware-1"},
|
Middlewares: []string{"middleware-1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -119,29 +119,29 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Should handle nested chains with different context",
|
desc: "Should handle nested chains with different context",
|
||||||
buildChain: []string{"middleware-chain-1@provider-1", "middleware-chain-1"},
|
buildChain: []string{"middleware-chain-1@provider-1", "middleware-chain-1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"middleware-1@provider-1": {
|
"middleware-1@provider-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
CustomRequestHeaders: map[string]string{"middleware-1": "value-middleware-1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"middleware-2@provider-1": {
|
"middleware-2@provider-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"middleware-2": "value-middleware-2"},
|
CustomRequestHeaders: map[string]string{"middleware-2": "value-middleware-2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"middleware-chain-1@provider-1": {
|
"middleware-chain-1@provider-1": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"middleware-1"},
|
Middlewares: []string{"middleware-1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"middleware-chain-2@provider-1": {
|
"middleware-chain-2@provider-1": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"middleware-2"},
|
Middlewares: []string{"middleware-2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"middleware-chain-1@provider-2": {
|
"middleware-chain-1@provider-2": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"middleware-2@provider-1", "middleware-chain-2@provider-1"},
|
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",
|
desc: "Detects recursion in Middleware chain",
|
||||||
buildChain: []string{"m1"},
|
buildChain: []string{"m1"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"ok": {
|
"ok": {
|
||||||
Retry: &config.Retry{},
|
Retry: &dynamic.Retry{},
|
||||||
},
|
},
|
||||||
"m1": {
|
"m1": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m2"},
|
Middlewares: []string{"m2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m2": {
|
"m2": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"ok", "m3"},
|
Middlewares: []string{"ok", "m3"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m3": {
|
"m3": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m1"},
|
Middlewares: []string{"m1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -177,22 +177,22 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Detects recursion in Middleware chain",
|
desc: "Detects recursion in Middleware chain",
|
||||||
buildChain: []string{"m1@provider"},
|
buildChain: []string{"m1@provider"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"ok@provider2": {
|
"ok@provider2": {
|
||||||
Retry: &config.Retry{},
|
Retry: &dynamic.Retry{},
|
||||||
},
|
},
|
||||||
"m1@provider": {
|
"m1@provider": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m2@provider2"},
|
Middlewares: []string{"m2@provider2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m2@provider2": {
|
"m2@provider2": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"ok", "m3@provider"},
|
Middlewares: []string{"ok", "m3@provider"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m3@provider": {
|
"m3@provider": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m1"},
|
Middlewares: []string{"m1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -201,12 +201,12 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
buildChain: []string{"ok", "m0"},
|
buildChain: []string{"ok", "m0"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"ok": {
|
"ok": {
|
||||||
Retry: &config.Retry{},
|
Retry: &dynamic.Retry{},
|
||||||
},
|
},
|
||||||
"m0": {
|
"m0": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m0"},
|
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",
|
desc: "Detects MiddlewareChain that references a Chain that references a Chain with a missing middleware",
|
||||||
buildChain: []string{"m0"},
|
buildChain: []string{"m0"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"m0": {
|
"m0": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m1"},
|
Middlewares: []string{"m1"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m1": {
|
"m1": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m2"},
|
Middlewares: []string{"m2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m2": {
|
"m2": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m3"},
|
Middlewares: []string{"m3"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"m3": {
|
"m3": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m2"},
|
Middlewares: []string{"m2"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -243,9 +243,9 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "--",
|
desc: "--",
|
||||||
buildChain: []string{"m0"},
|
buildChain: []string{"m0"},
|
||||||
configuration: map[string]*config.Middleware{
|
configuration: map[string]*dynamic.Middleware{
|
||||||
"m0": {
|
"m0": {
|
||||||
Chain: &config.Chain{
|
Chain: &dynamic.Chain{
|
||||||
Middlewares: []string{"m0"},
|
Middlewares: []string{"m0"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -264,8 +264,8 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
ctx = internal.AddProviderInContext(ctx, "foobar@"+test.contextProvider)
|
ctx = internal.AddProviderInContext(ctx, "foobar@"+test.contextProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: test.configuration,
|
Middlewares: test.configuration,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -292,31 +292,31 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilder_buildConstructor(t *testing.T) {
|
func TestBuilder_buildConstructor(t *testing.T) {
|
||||||
testConfig := map[string]*config.Middleware{
|
testConfig := map[string]*dynamic.Middleware{
|
||||||
"cb-empty": {
|
"cb-empty": {
|
||||||
CircuitBreaker: &config.CircuitBreaker{
|
CircuitBreaker: &dynamic.CircuitBreaker{
|
||||||
Expression: "",
|
Expression: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"cb-foo": {
|
"cb-foo": {
|
||||||
CircuitBreaker: &config.CircuitBreaker{
|
CircuitBreaker: &dynamic.CircuitBreaker{
|
||||||
Expression: "NetworkErrorRatio() > 0.5",
|
Expression: "NetworkErrorRatio() > 0.5",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"ap-empty": {
|
"ap-empty": {
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "",
|
Prefix: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"ap-foo": {
|
"ap-foo": {
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "foo/",
|
Prefix: "foo/",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Middlewares: testConfig,
|
Middlewares: testConfig,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"github.com/containous/alice"
|
"github.com/containous/alice"
|
||||||
"github.com/containous/mux"
|
"github.com/containous/mux"
|
||||||
"github.com/containous/traefik/pkg/api"
|
"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/config/static"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/metrics"
|
"github.com/containous/traefik/pkg/metrics"
|
||||||
|
@ -20,7 +20,7 @@ type chainBuilder interface {
|
||||||
|
|
||||||
// NewRouteAppenderAggregator Creates a new RouteAppenderAggregator
|
// NewRouteAppenderAggregator Creates a new RouteAppenderAggregator
|
||||||
func NewRouteAppenderAggregator(ctx context.Context, chainBuilder chainBuilder, conf static.Configuration,
|
func NewRouteAppenderAggregator(ctx context.Context, chainBuilder chainBuilder, conf static.Configuration,
|
||||||
entryPointName string, runtimeConfiguration *config.RuntimeConfiguration) *RouteAppenderAggregator {
|
entryPointName string, runtimeConfiguration *dynamic.RuntimeConfiguration) *RouteAppenderAggregator {
|
||||||
aggregator := &RouteAppenderAggregator{}
|
aggregator := &RouteAppenderAggregator{}
|
||||||
|
|
||||||
if conf.Providers != nil && conf.Providers.Rest != nil {
|
if conf.Providers != nil && conf.Providers.Rest != nil {
|
||||||
|
|
|
@ -3,7 +3,7 @@ package router
|
||||||
import (
|
import (
|
||||||
"context"
|
"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/config/static"
|
||||||
"github.com/containous/traefik/pkg/provider/acme"
|
"github.com/containous/traefik/pkg/provider/acme"
|
||||||
"github.com/containous/traefik/pkg/server/middleware"
|
"github.com/containous/traefik/pkg/server/middleware"
|
||||||
|
@ -27,7 +27,7 @@ type RouteAppenderFactory struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAppender Creates a new RouteAppender
|
// 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)
|
aggregator := NewRouteAppenderAggregator(ctx, middlewaresBuilder, r.staticConfiguration, r.entryPointName, runtimeConfiguration)
|
||||||
|
|
||||||
if r.acmeProvider != nil && r.acmeProvider.HTTPChallenge != nil && r.acmeProvider.HTTPChallenge.EntryPoint == r.entryPointName {
|
if r.acmeProvider != nil && r.acmeProvider.HTTPChallenge != nil && r.acmeProvider.HTTPChallenge.EntryPoint == r.entryPointName {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/containous/alice"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||||
"github.com/containous/traefik/pkg/middlewares/recovery"
|
"github.com/containous/traefik/pkg/middlewares/recovery"
|
||||||
|
@ -22,7 +22,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewManager Creates a new Manager
|
// NewManager Creates a new Manager
|
||||||
func NewManager(conf *config.RuntimeConfiguration,
|
func NewManager(conf *dynamic.RuntimeConfiguration,
|
||||||
serviceManager *service.Manager,
|
serviceManager *service.Manager,
|
||||||
middlewaresBuilder *middleware.Builder,
|
middlewaresBuilder *middleware.Builder,
|
||||||
modifierBuilder *responsemodifiers.Builder,
|
modifierBuilder *responsemodifiers.Builder,
|
||||||
|
@ -42,15 +42,15 @@ type Manager struct {
|
||||||
serviceManager *service.Manager
|
serviceManager *service.Manager
|
||||||
middlewaresBuilder *middleware.Builder
|
middlewaresBuilder *middleware.Builder
|
||||||
modifierBuilder *responsemodifiers.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 {
|
if m.conf != nil {
|
||||||
return m.conf.GetRoutersByEntrypoints(ctx, entryPoints, tls)
|
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
|
// BuildHandlers Builds handler for all entry points
|
||||||
|
@ -83,7 +83,7 @@ func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string, t
|
||||||
return entryPointHandlers
|
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()
|
router, err := rules.NewRouter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -118,7 +118,7 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
|
||||||
return chain.Then(router)
|
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 {
|
if handler, ok := m.routerHandlers[routerName]; ok {
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ func (m *Manager) buildRouterHandler(ctx context.Context, routerName string, rou
|
||||||
return m.routerHandlers[routerName], nil
|
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))
|
qualifiedNames := make([]string, len(router.Middlewares))
|
||||||
for i, name := range router.Middlewares {
|
for i, name := range router.Middlewares {
|
||||||
qualifiedNames[i] = internal.GetQualifiedName(ctx, name)
|
qualifiedNames[i] = internal.GetQualifiedName(ctx, name)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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/accesslog"
|
||||||
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
|
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
|
||||||
"github.com/containous/traefik/pkg/responsemodifiers"
|
"github.com/containous/traefik/pkg/responsemodifiers"
|
||||||
|
@ -30,25 +30,25 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
routersConfig map[string]*config.Router
|
routersConfig map[string]*dynamic.Router
|
||||||
serviceConfig map[string]*config.Service
|
serviceConfig map[string]*dynamic.Service
|
||||||
middlewaresConfig map[string]*config.Middleware
|
middlewaresConfig map[string]*dynamic.Middleware
|
||||||
entryPoints []string
|
entryPoints []string
|
||||||
expected ExpectedResult
|
expected ExpectedResult
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "no middleware",
|
desc: "no middleware",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -61,14 +61,14 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "no load balancer",
|
desc: "no load balancer",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {},
|
"foo-service": {},
|
||||||
},
|
},
|
||||||
entryPoints: []string{"web"},
|
entryPoints: []string{"web"},
|
||||||
|
@ -76,16 +76,16 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "no middleware, default entry point",
|
desc: "no middleware, default entry point",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -98,17 +98,17 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "no middleware, no matching",
|
desc: "no middleware, no matching",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "Host(`bar.bar`)",
|
Rule: "Host(`bar.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -121,7 +121,7 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "middleware: headers > auth",
|
desc: "middleware: headers > auth",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Middlewares: []string{"headers-middle", "auth-middle"},
|
Middlewares: []string{"headers-middle", "auth-middle"},
|
||||||
|
@ -129,10 +129,10 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
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": {
|
"auth-middle": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"toto:titi"},
|
Users: []string{"toto:titi"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"headers-middle": {
|
"headers-middle": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
|
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -162,7 +162,7 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "middleware: auth > header",
|
desc: "middleware: auth > header",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Middlewares: []string{"auth-middle", "headers-middle"},
|
Middlewares: []string{"auth-middle", "headers-middle"},
|
||||||
|
@ -170,10 +170,10 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
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": {
|
"auth-middle": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"toto:titi"},
|
Users: []string{"toto:titi"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"headers-middle": {
|
"headers-middle": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
|
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -203,17 +203,17 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "no middleware with provider name",
|
desc: "no middleware with provider name",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo@provider-1": {
|
"foo@provider-1": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service@provider-1": {
|
"foo-service@provider-1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -226,17 +226,17 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "no middleware with specified provider name",
|
desc: "no middleware with specified provider name",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo@provider-1": {
|
"foo@provider-1": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service@provider-2",
|
Service: "foo-service@provider-2",
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service@provider-2": {
|
"foo-service@provider-2": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -249,7 +249,7 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "middleware: chain with provider name",
|
desc: "middleware: chain with provider name",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo@provider-1": {
|
"foo@provider-1": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Middlewares: []string{"chain-middle@provider-2", "headers-middle"},
|
Middlewares: []string{"chain-middle@provider-2", "headers-middle"},
|
||||||
|
@ -257,10 +257,10 @@ func TestRouterManager_Get(t *testing.T) {
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service@provider-1": {
|
"foo-service@provider-1": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
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-middle@provider-2": {
|
||||||
Chain: &config.Chain{Middlewares: []string{"auth-middle"}},
|
Chain: &dynamic.Chain{Middlewares: []string{"auth-middle"}},
|
||||||
},
|
},
|
||||||
"auth-middle@provider-2": {
|
"auth-middle@provider-2": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"toto:titi"},
|
Users: []string{"toto:titi"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"headers-middle@provider-1": {
|
"headers-middle@provider-1": {
|
||||||
Headers: &config.Headers{
|
Headers: &dynamic.Headers{
|
||||||
CustomRequestHeaders: map[string]string{"X-Apero": "beer"},
|
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.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Services: test.serviceConfig,
|
Services: test.serviceConfig,
|
||||||
Routers: test.routersConfig,
|
Routers: test.routersConfig,
|
||||||
Middlewares: test.middlewaresConfig,
|
Middlewares: test.middlewaresConfig,
|
||||||
|
@ -332,15 +332,15 @@ func TestAccessLog(t *testing.T) {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
routersConfig map[string]*config.Router
|
routersConfig map[string]*dynamic.Router
|
||||||
serviceConfig map[string]*config.Service
|
serviceConfig map[string]*dynamic.Service
|
||||||
middlewaresConfig map[string]*config.Middleware
|
middlewaresConfig map[string]*dynamic.Middleware
|
||||||
entryPoints []string
|
entryPoints []string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "apply routerName in accesslog (first match)",
|
desc: "apply routerName in accesslog (first match)",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -352,10 +352,10 @@ func TestAccessLog(t *testing.T) {
|
||||||
Rule: "Host(`bar.foo`)",
|
Rule: "Host(`bar.foo`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -368,7 +368,7 @@ func TestAccessLog(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "apply routerName in accesslog (second match)",
|
desc: "apply routerName in accesslog (second match)",
|
||||||
routersConfig: map[string]*config.Router{
|
routersConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -380,10 +380,10 @@ func TestAccessLog(t *testing.T) {
|
||||||
Rule: "Host(`foo.bar`)",
|
Rule: "Host(`foo.bar`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -399,8 +399,8 @@ func TestAccessLog(t *testing.T) {
|
||||||
for _, test := range testCases {
|
for _, test := range testCases {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Services: test.serviceConfig,
|
Services: test.serviceConfig,
|
||||||
Routers: test.routersConfig,
|
Routers: test.routersConfig,
|
||||||
Middlewares: test.middlewaresConfig,
|
Middlewares: test.middlewaresConfig,
|
||||||
|
@ -438,17 +438,17 @@ func TestAccessLog(t *testing.T) {
|
||||||
func TestRuntimeConfiguration(t *testing.T) {
|
func TestRuntimeConfiguration(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
serviceConfig map[string]*config.Service
|
serviceConfig map[string]*dynamic.Service
|
||||||
routerConfig map[string]*config.Router
|
routerConfig map[string]*dynamic.Router
|
||||||
middlewareConfig map[string]*config.Middleware
|
middlewareConfig map[string]*dynamic.Middleware
|
||||||
expectedError int
|
expectedError int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "No error",
|
desc: "No error",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1:8085",
|
URL: "http://127.0.0.1:8085",
|
||||||
},
|
},
|
||||||
|
@ -456,14 +456,14 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
URL: "http://127.0.0.1:8086",
|
URL: "http://127.0.0.1:8086",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
HealthCheck: &config.HealthCheck{
|
HealthCheck: &dynamic.HealthCheck{
|
||||||
Interval: "500ms",
|
Interval: "500ms",
|
||||||
Path: "/health",
|
Path: "/health",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routerConfig: map[string]*config.Router{
|
routerConfig: map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -479,10 +479,10 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "One router with wrong rule",
|
desc: "One router with wrong rule",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -506,10 +506,10 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "All router with wrong rule",
|
desc: "All router with wrong rule",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -533,10 +533,10 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Router with unknown service",
|
desc: "Router with unknown service",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "wrong-service",
|
Service: "wrong-service",
|
||||||
|
@ -560,12 +560,12 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Router with broken service",
|
desc: "Router with broken service",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: nil,
|
LoadBalancer: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routerConfig: map[string]*config.Router{
|
routerConfig: map[string]*dynamic.Router{
|
||||||
"bar": {
|
"bar": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -576,10 +576,10 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Router with middleware",
|
desc: "Router with middleware",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"auth": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"addPrefixTest": {
|
"addPrefixTest": {
|
||||||
AddPrefix: &config.AddPrefix{
|
AddPrefix: &dynamic.AddPrefix{
|
||||||
Prefix: "/toto",
|
Prefix: "/toto",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routerConfig: map[string]*config.Router{
|
routerConfig: map[string]*dynamic.Router{
|
||||||
"bar": {
|
"bar": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -616,10 +616,10 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Router with unknown middleware",
|
desc: "Router with unknown middleware",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"auth": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"admin:admin"},
|
Users: []string{"admin:admin"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routerConfig: map[string]*config.Router{
|
routerConfig: map[string]*dynamic.Router{
|
||||||
"bar": {
|
"bar": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -647,10 +647,10 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
|
|
||||||
{
|
{
|
||||||
desc: "Router with broken middleware",
|
desc: "Router with broken middleware",
|
||||||
serviceConfig: map[string]*config.Service{
|
serviceConfig: map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://127.0.0.1",
|
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": {
|
"auth": {
|
||||||
BasicAuth: &config.BasicAuth{
|
BasicAuth: &dynamic.BasicAuth{
|
||||||
Users: []string{"foo"},
|
Users: []string{"foo"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routerConfig: map[string]*config.Router{
|
routerConfig: map[string]*dynamic.Router{
|
||||||
"bar": {
|
"bar": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -685,8 +685,8 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
|
|
||||||
entryPoints := []string{"web"}
|
entryPoints := []string{"web"}
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Services: test.serviceConfig,
|
Services: test.serviceConfig,
|
||||||
Routers: test.routerConfig,
|
Routers: test.routerConfig,
|
||||||
Middlewares: test.middlewareConfig,
|
Middlewares: test.middlewareConfig,
|
||||||
|
@ -694,7 +694,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
})
|
})
|
||||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport)
|
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport)
|
||||||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
|
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 := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||||
|
|
||||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints, false)
|
_ = routerManager.BuildHandlers(context.Background(), entryPoints, false)
|
||||||
|
@ -739,17 +739,17 @@ func BenchmarkRouterServe(b *testing.B) {
|
||||||
StatusCode: 200,
|
StatusCode: 200,
|
||||||
Body: ioutil.NopCloser(strings.NewReader("")),
|
Body: ioutil.NopCloser(strings.NewReader("")),
|
||||||
}
|
}
|
||||||
routersConfig := map[string]*config.Router{
|
routersConfig := map[string]*dynamic.Router{
|
||||||
"foo": {
|
"foo": {
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "Host(`foo.bar`) && Path(`/`)",
|
Rule: "Host(`foo.bar`) && Path(`/`)",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
serviceConfig := map[string]*config.Service{
|
serviceConfig := map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server.URL,
|
URL: server.URL,
|
||||||
},
|
},
|
||||||
|
@ -759,11 +759,11 @@ func BenchmarkRouterServe(b *testing.B) {
|
||||||
}
|
}
|
||||||
entryPoints := []string{"web"}
|
entryPoints := []string{"web"}
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Services: serviceConfig,
|
Services: serviceConfig,
|
||||||
Routers: routersConfig,
|
Routers: routersConfig,
|
||||||
Middlewares: map[string]*config.Middleware{},
|
Middlewares: map[string]*dynamic.Middleware{},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res})
|
serviceManager := service.NewManager(rtConf.Services, &staticTransport{res})
|
||||||
|
@ -790,10 +790,10 @@ func BenchmarkService(b *testing.B) {
|
||||||
Body: ioutil.NopCloser(strings.NewReader("")),
|
Body: ioutil.NopCloser(strings.NewReader("")),
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceConfig := map[string]*config.Service{
|
serviceConfig := map[string]*dynamic.Service{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
LoadBalancer: &config.LoadBalancerService{
|
LoadBalancer: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "tchouck",
|
URL: "tchouck",
|
||||||
},
|
},
|
||||||
|
@ -802,8 +802,8 @@ func BenchmarkService(b *testing.B) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rtConf := config.NewRuntimeConfig(config.Configuration{
|
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{
|
||||||
HTTP: &config.HTTPConfiguration{
|
HTTP: &dynamic.HTTPConfiguration{
|
||||||
Services: serviceConfig,
|
Services: serviceConfig,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/rules"
|
"github.com/containous/traefik/pkg/rules"
|
||||||
"github.com/containous/traefik/pkg/server/internal"
|
"github.com/containous/traefik/pkg/server/internal"
|
||||||
|
@ -16,7 +16,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewManager Creates a new Manager
|
// NewManager Creates a new Manager
|
||||||
func NewManager(conf *config.RuntimeConfiguration,
|
func NewManager(conf *dynamic.RuntimeConfiguration,
|
||||||
serviceManager *tcpservice.Manager,
|
serviceManager *tcpservice.Manager,
|
||||||
httpHandlers map[string]http.Handler,
|
httpHandlers map[string]http.Handler,
|
||||||
httpsHandlers map[string]http.Handler,
|
httpsHandlers map[string]http.Handler,
|
||||||
|
@ -37,23 +37,23 @@ type Manager struct {
|
||||||
httpHandlers map[string]http.Handler
|
httpHandlers map[string]http.Handler
|
||||||
httpsHandlers map[string]http.Handler
|
httpsHandlers map[string]http.Handler
|
||||||
tlsManager *traefiktls.Manager
|
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 {
|
if m.conf != nil {
|
||||||
return m.conf.GetTCPRoutersByEntrypoints(ctx, entryPoints)
|
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 {
|
if m.conf != nil {
|
||||||
return m.conf.GetRoutersByEntrypoints(ctx, entryPoints, tls)
|
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
|
// BuildHandlers builds the handlers for the given entrypoints
|
||||||
|
@ -79,7 +79,7 @@ func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string) m
|
||||||
return entryPointHandlers
|
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 := &tcp.Router{}
|
||||||
router.HTTPHandler(handlerHTTP)
|
router.HTTPHandler(handlerHTTP)
|
||||||
const defaultTLSConfigName = "default"
|
const defaultTLSConfigName = "default"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"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/server/service/tcp"
|
||||||
"github.com/containous/traefik/pkg/tls"
|
"github.com/containous/traefik/pkg/tls"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -13,17 +13,17 @@ import (
|
||||||
func TestRuntimeConfiguration(t *testing.T) {
|
func TestRuntimeConfiguration(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
serviceConfig map[string]*config.TCPServiceInfo
|
serviceConfig map[string]*dynamic.TCPServiceInfo
|
||||||
routerConfig map[string]*config.TCPRouterInfo
|
routerConfig map[string]*dynamic.TCPRouterInfo
|
||||||
expectedError int
|
expectedError int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "No error",
|
desc: "No error",
|
||||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Port: "8085",
|
Port: "8085",
|
||||||
Address: "127.0.0.1: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": {
|
"foo": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "HostSNI(`bar.foo`)",
|
Rule: "HostSNI(`bar.foo`)",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
Options: "foo",
|
Options: "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
|
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
TLS: &config.RouterTCPTLSConfig{
|
TLS: &dynamic.RouterTCPTLSConfig{
|
||||||
Passthrough: false,
|
Passthrough: false,
|
||||||
Options: "bar",
|
Options: "bar",
|
||||||
},
|
},
|
||||||
|
@ -66,11 +66,11 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "One router with wrong rule",
|
desc: "One router with wrong rule",
|
||||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:80",
|
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": {
|
"foo": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "WrongRule(`bar.foo`)",
|
Rule: "WrongRule(`bar.foo`)",
|
||||||
|
@ -89,7 +89,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
|
|
||||||
"bar": {
|
"bar": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
|
@ -100,11 +100,11 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "All router with wrong rule",
|
desc: "All router with wrong rule",
|
||||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:80",
|
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": {
|
"foo": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "WrongRule(`bar.foo`)",
|
Rule: "WrongRule(`bar.foo`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "WrongRule(`foo.bar`)",
|
Rule: "WrongRule(`foo.bar`)",
|
||||||
|
@ -133,11 +133,11 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Router with unknown service",
|
desc: "Router with unknown service",
|
||||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "127.0.0.1:80",
|
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": {
|
"foo": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "wrong-service",
|
Service: "wrong-service",
|
||||||
Rule: "HostSNI(`bar.foo`)",
|
Rule: "HostSNI(`bar.foo`)",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"bar": {
|
"bar": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
|
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
|
@ -167,16 +167,16 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Router with broken service",
|
desc: "Router with broken service",
|
||||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||||
"foo-service": {
|
"foo-service": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: nil,
|
LoadBalancer: nil,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
routerConfig: map[string]*config.TCPRouterInfo{
|
routerConfig: map[string]*dynamic.TCPRouterInfo{
|
||||||
"bar": {
|
"bar": {
|
||||||
TCPRouter: &config.TCPRouter{
|
TCPRouter: &dynamic.TCPRouter{
|
||||||
EntryPoints: []string{"web"},
|
EntryPoints: []string{"web"},
|
||||||
Service: "foo-service",
|
Service: "foo-service",
|
||||||
Rule: "HostSNI(`foo.bar`)",
|
Rule: "HostSNI(`foo.bar`)",
|
||||||
|
@ -195,7 +195,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
||||||
|
|
||||||
entryPoints := []string{"web"}
|
entryPoints := []string{"web"}
|
||||||
|
|
||||||
conf := &config.RuntimeConfiguration{
|
conf := &dynamic.RuntimeConfiguration{
|
||||||
TCPServices: test.serviceConfig,
|
TCPServices: test.serviceConfig,
|
||||||
TCPRouters: test.routerConfig,
|
TCPRouters: test.routerConfig,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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/config/static"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/metrics"
|
"github.com/containous/traefik/pkg/metrics"
|
||||||
|
@ -27,19 +27,19 @@ import (
|
||||||
// Server is the reverse-proxy/load-balancer engine
|
// Server is the reverse-proxy/load-balancer engine
|
||||||
type Server struct {
|
type Server struct {
|
||||||
entryPointsTCP TCPEntryPoints
|
entryPointsTCP TCPEntryPoints
|
||||||
configurationChan chan config.Message
|
configurationChan chan dynamic.Message
|
||||||
configurationValidatedChan chan config.Message
|
configurationValidatedChan chan dynamic.Message
|
||||||
signals chan os.Signal
|
signals chan os.Signal
|
||||||
stopChan chan bool
|
stopChan chan bool
|
||||||
currentConfigurations safe.Safe
|
currentConfigurations safe.Safe
|
||||||
providerConfigUpdateMap map[string]chan config.Message
|
providerConfigUpdateMap map[string]chan dynamic.Message
|
||||||
accessLoggerMiddleware *accesslog.Handler
|
accessLoggerMiddleware *accesslog.Handler
|
||||||
tracer *tracing.Tracing
|
tracer *tracing.Tracing
|
||||||
routinesPool *safe.Pool
|
routinesPool *safe.Pool
|
||||||
defaultRoundTripper http.RoundTripper
|
defaultRoundTripper http.RoundTripper
|
||||||
metricsRegistry metrics.Registry
|
metricsRegistry metrics.Registry
|
||||||
provider provider.Provider
|
provider provider.Provider
|
||||||
configurationListeners []func(config.Configuration)
|
configurationListeners []func(dynamic.Configuration)
|
||||||
requestDecorator *requestdecorator.RequestDecorator
|
requestDecorator *requestdecorator.RequestDecorator
|
||||||
providersThrottleDuration time.Duration
|
providersThrottleDuration time.Duration
|
||||||
tlsManager *tls.Manager
|
tlsManager *tls.Manager
|
||||||
|
@ -47,7 +47,7 @@ type Server struct {
|
||||||
|
|
||||||
// RouteAppenderFactory the route appender factory interface
|
// RouteAppenderFactory the route appender factory interface
|
||||||
type RouteAppenderFactory 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 {
|
func setupTracing(conf *static.Tracing) tracing.Backend {
|
||||||
|
@ -104,14 +104,14 @@ func NewServer(staticConfiguration static.Configuration, provider provider.Provi
|
||||||
|
|
||||||
server.provider = provider
|
server.provider = provider
|
||||||
server.entryPointsTCP = entryPoints
|
server.entryPointsTCP = entryPoints
|
||||||
server.configurationChan = make(chan config.Message, 100)
|
server.configurationChan = make(chan dynamic.Message, 100)
|
||||||
server.configurationValidatedChan = make(chan config.Message, 100)
|
server.configurationValidatedChan = make(chan dynamic.Message, 100)
|
||||||
server.signals = make(chan os.Signal, 1)
|
server.signals = make(chan os.Signal, 1)
|
||||||
server.stopChan = make(chan bool, 1)
|
server.stopChan = make(chan bool, 1)
|
||||||
server.configureSignals()
|
server.configureSignals()
|
||||||
currentConfigurations := make(config.Configurations)
|
currentConfigurations := make(dynamic.Configurations)
|
||||||
server.currentConfigurations.Set(currentConfigurations)
|
server.currentConfigurations.Set(currentConfigurations)
|
||||||
server.providerConfigUpdateMap = make(map[string]chan config.Message)
|
server.providerConfigUpdateMap = make(map[string]chan dynamic.Message)
|
||||||
server.tlsManager = tlsManager
|
server.tlsManager = tlsManager
|
||||||
|
|
||||||
if staticConfiguration.Providers != nil {
|
if staticConfiguration.Providers != nil {
|
||||||
|
@ -236,7 +236,7 @@ func (s *Server) Close() {
|
||||||
|
|
||||||
func (s *Server) startTCPServers() {
|
func (s *Server) startTCPServers() {
|
||||||
// Use an empty configuration in order to initialize the default handlers with internal routes
|
// 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 {
|
for entryPointName, router := range routers {
|
||||||
s.entryPointsTCP[entryPointName].switchRouter(router)
|
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
|
// 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 {
|
if s.configurationListeners == nil {
|
||||||
s.configurationListeners = make([]func(config.Configuration), 0)
|
s.configurationListeners = make([]func(dynamic.Configuration), 0)
|
||||||
}
|
}
|
||||||
s.configurationListeners = append(s.configurationListeners, listener)
|
s.configurationListeners = append(s.configurationListeners, listener)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/containous/alice"
|
"github.com/containous/alice"
|
||||||
"github.com/containous/mux"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||||
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
|
"github.com/containous/traefik/pkg/middlewares/requestdecorator"
|
||||||
|
@ -26,8 +26,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// loadConfiguration manages dynamically routers, middlewares, servers and TLS configurations
|
// loadConfiguration manages dynamically routers, middlewares, servers and TLS configurations
|
||||||
func (s *Server) loadConfiguration(configMsg config.Message) {
|
func (s *Server) loadConfiguration(configMsg dynamic.Message) {
|
||||||
currentConfigurations := s.currentConfigurations.Get().(config.Configurations)
|
currentConfigurations := s.currentConfigurations.Get().(dynamic.Configurations)
|
||||||
|
|
||||||
// Copy configurations to new map so we don't change current if LoadConfig fails
|
// Copy configurations to new map so we don't change current if LoadConfig fails
|
||||||
newConfigurations := currentConfigurations.DeepCopy()
|
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
|
// loadConfigurationTCP returns a new gorilla.mux Route from the specified global configuration and the dynamic
|
||||||
// provider configurations.
|
// 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()
|
ctx := context.TODO()
|
||||||
|
|
||||||
var entryPoints []string
|
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)
|
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)
|
handlersNonTLS, handlersTLS := s.createHTTPHandlers(ctx, rtConf, entryPoints)
|
||||||
routersTCP := s.createTCPRouters(ctx, rtConf, entryPoints, handlersNonTLS, handlersTLS)
|
routersTCP := s.createTCPRouters(ctx, rtConf, entryPoints, handlersNonTLS, handlersTLS)
|
||||||
rtConf.PopulateUsedBy()
|
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.
|
// 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 {
|
if configuration == nil {
|
||||||
return make(map[string]*tcpCore.Router)
|
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.
|
// 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)
|
serviceManager := service.NewManager(configuration.Services, s.defaultRoundTripper)
|
||||||
middlewaresBuilder := middleware.NewBuilder(configuration.Middlewares, serviceManager)
|
middlewaresBuilder := middleware.NewBuilder(configuration.Middlewares, serviceManager)
|
||||||
responseModifierFactory := responsemodifiers.NewBuilder(configuration.Middlewares)
|
responseModifierFactory := responsemodifiers.NewBuilder(configuration.Middlewares)
|
||||||
|
@ -150,15 +150,15 @@ func (s *Server) createHTTPHandlers(ctx context.Context, configuration *config.R
|
||||||
return routerHandlers, handlersTLS
|
return routerHandlers, handlersTLS
|
||||||
}
|
}
|
||||||
|
|
||||||
func isEmptyConfiguration(conf *config.Configuration) bool {
|
func isEmptyConfiguration(conf *dynamic.Configuration) bool {
|
||||||
if conf == nil {
|
if conf == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if conf.TCP == nil {
|
if conf.TCP == nil {
|
||||||
conf.TCP = &config.TCPConfiguration{}
|
conf.TCP = &dynamic.TCPConfiguration{}
|
||||||
}
|
}
|
||||||
if conf.HTTP == nil {
|
if conf.HTTP == nil {
|
||||||
conf.HTTP = &config.HTTPConfiguration{}
|
conf.HTTP = &dynamic.HTTPConfiguration{}
|
||||||
}
|
}
|
||||||
|
|
||||||
return conf.HTTP.Routers == nil &&
|
return conf.HTTP.Routers == nil &&
|
||||||
|
@ -169,9 +169,9 @@ func isEmptyConfiguration(conf *config.Configuration) bool {
|
||||||
conf.TCP.Services == nil
|
conf.TCP.Services == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) preLoadConfiguration(configMsg config.Message) {
|
func (s *Server) preLoadConfiguration(configMsg dynamic.Message) {
|
||||||
s.defaultConfigurationValues(configMsg.Configuration.HTTP)
|
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)
|
logger := log.WithoutContext().WithField(log.ProviderName, configMsg.ProviderName)
|
||||||
if log.GetLevel() == logrus.DebugLevel {
|
if log.GetLevel() == logrus.DebugLevel {
|
||||||
|
@ -191,7 +191,7 @@ func (s *Server) preLoadConfiguration(configMsg config.Message) {
|
||||||
|
|
||||||
providerConfigUpdateCh, ok := s.providerConfigUpdateMap[configMsg.ProviderName]
|
providerConfigUpdateCh, ok := s.providerConfigUpdateMap[configMsg.ProviderName]
|
||||||
if !ok {
|
if !ok {
|
||||||
providerConfigUpdateCh = make(chan config.Message)
|
providerConfigUpdateCh = make(chan dynamic.Message)
|
||||||
s.providerConfigUpdateMap[configMsg.ProviderName] = providerConfigUpdateCh
|
s.providerConfigUpdateMap[configMsg.ProviderName] = providerConfigUpdateCh
|
||||||
s.routinesPool.Go(func(stop chan bool) {
|
s.routinesPool.Go(func(stop chan bool) {
|
||||||
s.throttleProviderConfigReload(s.providersThrottleDuration, s.configurationValidatedChan, providerConfigUpdateCh, stop)
|
s.throttleProviderConfigReload(s.providersThrottleDuration, s.configurationValidatedChan, providerConfigUpdateCh, stop)
|
||||||
|
@ -201,7 +201,7 @@ func (s *Server) preLoadConfiguration(configMsg config.Message) {
|
||||||
providerConfigUpdateCh <- configMsg
|
providerConfigUpdateCh <- configMsg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) defaultConfigurationValues(configuration *config.HTTPConfiguration) {
|
func (s *Server) defaultConfigurationValues(configuration *dynamic.HTTPConfiguration) {
|
||||||
// FIXME create a config hook
|
// 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.
|
// 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,
|
// 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.
|
// 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)
|
ring := channels.NewRingChannel(1)
|
||||||
defer ring.Close()
|
defer ring.Close()
|
||||||
|
|
||||||
|
@ -233,7 +233,7 @@ func (s *Server) throttleProviderConfigReload(throttle time.Duration, publish ch
|
||||||
case <-stop:
|
case <-stop:
|
||||||
return
|
return
|
||||||
case nextConfig := <-ring.Out():
|
case nextConfig := <-ring.Out():
|
||||||
if config, ok := nextConfig.(config.Message); ok {
|
if config, ok := nextConfig.(dynamic.Message); ok {
|
||||||
publish <- config
|
publish <- config
|
||||||
time.Sleep(throttle)
|
time.Sleep(throttle)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/config/static"
|
||||||
th "github.com/containous/traefik/pkg/testhelpers"
|
th "github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -37,7 +37,7 @@ func TestReuseService(t *testing.T) {
|
||||||
th.WithRouterMiddlewares("basicauth")),
|
th.WithRouterMiddlewares("basicauth")),
|
||||||
),
|
),
|
||||||
th.WithMiddlewares(th.WithMiddleware("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.WithLoadBalancerServices(th.WithService("bar",
|
||||||
th.WithServers(th.WithServer(testServer.URL))),
|
th.WithServers(th.WithServer(testServer.URL))),
|
||||||
|
@ -46,7 +46,7 @@ func TestReuseService(t *testing.T) {
|
||||||
|
|
||||||
srv := NewServer(staticConfig, nil, entryPoints, nil)
|
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"})
|
entrypointsHandlers, _ := srv.createHTTPHandlers(context.Background(), rtConf, []string{"http"})
|
||||||
|
|
||||||
// Test that the /ok path returns a status 200.
|
// Test that the /ok path returns a status 200.
|
||||||
|
@ -67,8 +67,8 @@ func TestReuseService(t *testing.T) {
|
||||||
|
|
||||||
func TestThrottleProviderConfigReload(t *testing.T) {
|
func TestThrottleProviderConfigReload(t *testing.T) {
|
||||||
throttleDuration := 30 * time.Millisecond
|
throttleDuration := 30 * time.Millisecond
|
||||||
publishConfig := make(chan config.Message)
|
publishConfig := make(chan dynamic.Message)
|
||||||
providerConfig := make(chan config.Message)
|
providerConfig := make(chan dynamic.Message)
|
||||||
stop := make(chan bool)
|
stop := make(chan bool)
|
||||||
defer func() {
|
defer func() {
|
||||||
stop <- true
|
stop <- true
|
||||||
|
@ -96,7 +96,7 @@ func TestThrottleProviderConfigReload(t *testing.T) {
|
||||||
|
|
||||||
// publish 5 new configs, one new config each 10 milliseconds
|
// publish 5 new configs, one new config each 10 milliseconds
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
providerConfig <- config.Message{}
|
providerConfig <- dynamic.Message{}
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/config/static"
|
||||||
th "github.com/containous/traefik/pkg/testhelpers"
|
th "github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"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
|
// give some time so that the configuration can be processed
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
@ -49,7 +49,7 @@ func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
|
||||||
// set the current configuration
|
// set the current configuration
|
||||||
// this is usually done in the processing part of the published configuration
|
// this is usually done in the processing part of the published configuration
|
||||||
// so we have to emulate the behavior here
|
// 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
|
currentConfigurations[conf.ProviderName] = conf.Configuration
|
||||||
server.currentConfigurations.Set(currentConfigurations)
|
server.currentConfigurations.Set(currentConfigurations)
|
||||||
|
|
||||||
|
@ -60,20 +60,20 @@ func TestListenProvidersSkipsSameConfigurationForProvider(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
conf := &config.Configuration{}
|
conf := &dynamic.Configuration{}
|
||||||
conf.HTTP = th.BuildConfiguration(
|
conf.HTTP = th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo")),
|
th.WithRouters(th.WithRouter("foo")),
|
||||||
th.WithLoadBalancerServices(th.WithService("bar")),
|
th.WithLoadBalancerServices(th.WithService("bar")),
|
||||||
)
|
)
|
||||||
|
|
||||||
// provide a configuration
|
// 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
|
// give some time so that the configuration can be processed
|
||||||
time.Sleep(20 * time.Millisecond)
|
time.Sleep(20 * time.Millisecond)
|
||||||
|
|
||||||
// provide the same configuration a second time
|
// 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
|
// give some time so that the configuration can be processed
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
@ -102,13 +102,13 @@ func TestListenProvidersPublishesConfigForEachProvider(t *testing.T) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
conf := &config.Configuration{}
|
conf := &dynamic.Configuration{}
|
||||||
conf.HTTP = th.BuildConfiguration(
|
conf.HTTP = th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo")),
|
th.WithRouters(th.WithRouter("foo")),
|
||||||
th.WithLoadBalancerServices(th.WithService("bar")),
|
th.WithLoadBalancerServices(th.WithService("bar")),
|
||||||
)
|
)
|
||||||
server.configurationChan <- config.Message{ProviderName: "kubernetes", Configuration: conf}
|
server.configurationChan <- dynamic.Message{ProviderName: "kubernetes", Configuration: conf}
|
||||||
server.configurationChan <- config.Message{ProviderName: "marathon", Configuration: conf}
|
server.configurationChan <- dynamic.Message{ProviderName: "marathon", Configuration: conf}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-consumePublishedConfigsDone:
|
case <-consumePublishedConfigsDone:
|
||||||
|
@ -148,12 +148,12 @@ func TestServerResponseEmptyBackend(t *testing.T) {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
config func(testServerURL string) *config.HTTPConfiguration
|
config func(testServerURL string) *dynamic.HTTPConfiguration
|
||||||
expectedStatusCode int
|
expectedStatusCode int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Ok",
|
desc: "Ok",
|
||||||
config: func(testServerURL string) *config.HTTPConfiguration {
|
config: func(testServerURL string) *dynamic.HTTPConfiguration {
|
||||||
return th.BuildConfiguration(
|
return th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo",
|
th.WithRouters(th.WithRouter("foo",
|
||||||
th.WithEntryPoints("http"),
|
th.WithEntryPoints("http"),
|
||||||
|
@ -169,14 +169,14 @@ func TestServerResponseEmptyBackend(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "No Frontend",
|
desc: "No Frontend",
|
||||||
config: func(testServerURL string) *config.HTTPConfiguration {
|
config: func(testServerURL string) *dynamic.HTTPConfiguration {
|
||||||
return th.BuildConfiguration()
|
return th.BuildConfiguration()
|
||||||
},
|
},
|
||||||
expectedStatusCode: http.StatusNotFound,
|
expectedStatusCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Empty Backend LB",
|
desc: "Empty Backend LB",
|
||||||
config: func(testServerURL string) *config.HTTPConfiguration {
|
config: func(testServerURL string) *dynamic.HTTPConfiguration {
|
||||||
return th.BuildConfiguration(
|
return th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo",
|
th.WithRouters(th.WithRouter("foo",
|
||||||
th.WithEntryPoints("http"),
|
th.WithEntryPoints("http"),
|
||||||
|
@ -190,7 +190,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Empty Backend LB Sticky",
|
desc: "Empty Backend LB Sticky",
|
||||||
config: func(testServerURL string) *config.HTTPConfiguration {
|
config: func(testServerURL string) *dynamic.HTTPConfiguration {
|
||||||
return th.BuildConfiguration(
|
return th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo",
|
th.WithRouters(th.WithRouter("foo",
|
||||||
th.WithEntryPoints("http"),
|
th.WithEntryPoints("http"),
|
||||||
|
@ -206,7 +206,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Empty Backend LB",
|
desc: "Empty Backend LB",
|
||||||
config: func(testServerURL string) *config.HTTPConfiguration {
|
config: func(testServerURL string) *dynamic.HTTPConfiguration {
|
||||||
return th.BuildConfiguration(
|
return th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo",
|
th.WithRouters(th.WithRouter("foo",
|
||||||
th.WithEntryPoints("http"),
|
th.WithEntryPoints("http"),
|
||||||
|
@ -220,7 +220,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Empty Backend LB Sticky",
|
desc: "Empty Backend LB Sticky",
|
||||||
config: func(testServerURL string) *config.HTTPConfiguration {
|
config: func(testServerURL string) *dynamic.HTTPConfiguration {
|
||||||
return th.BuildConfiguration(
|
return th.BuildConfiguration(
|
||||||
th.WithRouters(th.WithRouter("foo",
|
th.WithRouters(th.WithRouter("foo",
|
||||||
th.WithEntryPoints("http"),
|
th.WithEntryPoints("http"),
|
||||||
|
@ -253,7 +253,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
srv := NewServer(globalConfig, nil, entryPointsConfig, nil)
|
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"})
|
entryPoints, _ := srv.createHTTPHandlers(context.Background(), rtConf, []string{"http"})
|
||||||
|
|
||||||
responseRecorder := &httptest.ResponseRecorder{}
|
responseRecorder := &httptest.ResponseRecorder{}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/types"
|
"github.com/containous/traefik/pkg/types"
|
||||||
)
|
)
|
||||||
|
@ -21,7 +21,7 @@ const StatusClientClosedRequest = 499
|
||||||
// StatusClientClosedRequestText non-standard HTTP status for client disconnection
|
// StatusClientClosedRequestText non-standard HTTP status for client disconnection
|
||||||
const StatusClientClosedRequestText = "Client Closed Request"
|
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
|
var flushInterval types.Duration
|
||||||
if responseForwarding != nil {
|
if responseForwarding != nil {
|
||||||
err := flushInterval.Set(responseForwarding.FlushInterval)
|
err := flushInterval.Set(responseForwarding.FlushInterval)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/alice"
|
"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/healthcheck"
|
||||||
"github.com/containous/traefik/pkg/log"
|
"github.com/containous/traefik/pkg/log"
|
||||||
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
||||||
|
@ -26,7 +26,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewManager creates a new Manager
|
// 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{
|
return &Manager{
|
||||||
bufferPool: newBufferPool(),
|
bufferPool: newBufferPool(),
|
||||||
defaultRoundTripper: defaultRoundTripper,
|
defaultRoundTripper: defaultRoundTripper,
|
||||||
|
@ -40,7 +40,7 @@ type Manager struct {
|
||||||
bufferPool httputil.BufferPool
|
bufferPool httputil.BufferPool
|
||||||
defaultRoundTripper http.RoundTripper
|
defaultRoundTripper http.RoundTripper
|
||||||
balancers map[string][]healthcheck.BalancerHandler
|
balancers map[string][]healthcheck.BalancerHandler
|
||||||
configs map[string]*config.ServiceInfo
|
configs map[string]*dynamic.ServiceInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildHTTP Creates a http.Handler for a service configuration.
|
// 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(
|
func (m *Manager) getLoadBalancerServiceHandler(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
serviceName string,
|
serviceName string,
|
||||||
service *config.LoadBalancerService,
|
service *dynamic.LoadBalancerService,
|
||||||
responseModifier func(*http.Response) error,
|
responseModifier func(*http.Response) error,
|
||||||
) (http.Handler, error) {
|
) (http.Handler, error) {
|
||||||
fwd, err := buildProxy(service.PassHostHeader, service.ResponseForwarding, m.defaultRoundTripper, m.bufferPool, responseModifier)
|
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)
|
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 == "" {
|
if hc == nil || hc.Path == "" {
|
||||||
return nil
|
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 := log.FromContext(ctx)
|
||||||
logger.Debug("Creating load-balancer")
|
logger.Debug("Creating load-balancer")
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ func (m *Manager) getLoadBalancer(ctx context.Context, serviceName string, servi
|
||||||
return lb, nil
|
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)
|
logger := log.FromContext(ctx)
|
||||||
|
|
||||||
for name, srv := range servers {
|
for name, srv := range servers {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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/server/internal"
|
||||||
"github.com/containous/traefik/pkg/testhelpers"
|
"github.com/containous/traefik/pkg/testhelpers"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -26,15 +26,15 @@ func TestGetLoadBalancer(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
serviceName string
|
serviceName string
|
||||||
service *config.LoadBalancerService
|
service *dynamic.LoadBalancerService
|
||||||
fwd http.Handler
|
fwd http.Handler
|
||||||
expectError bool
|
expectError bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Fails when provided an invalid URL",
|
desc: "Fails when provided an invalid URL",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: ":",
|
URL: ":",
|
||||||
},
|
},
|
||||||
|
@ -46,15 +46,15 @@ func TestGetLoadBalancer(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Succeeds when there are no servers",
|
desc: "Succeeds when there are no servers",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{},
|
service: &dynamic.LoadBalancerService{},
|
||||||
fwd: &MockForwarder{},
|
fwd: &MockForwarder{},
|
||||||
expectError: false,
|
expectError: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
desc: "Succeeds when stickiness is set",
|
desc: "Succeeds when stickiness is set",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{},
|
Stickiness: &dynamic.Stickiness{},
|
||||||
},
|
},
|
||||||
fwd: &MockForwarder{},
|
fwd: &MockForwarder{},
|
||||||
expectError: false,
|
expectError: false,
|
||||||
|
@ -113,7 +113,7 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
serviceName string
|
serviceName string
|
||||||
service *config.LoadBalancerService
|
service *dynamic.LoadBalancerService
|
||||||
responseModifier func(*http.Response) error
|
responseModifier func(*http.Response) error
|
||||||
|
|
||||||
expected []ExpectedResult
|
expected []ExpectedResult
|
||||||
|
@ -121,8 +121,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Load balances between the two servers",
|
desc: "Load balances between the two servers",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server1.URL,
|
URL: server1.URL,
|
||||||
},
|
},
|
||||||
|
@ -145,8 +145,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "StatusBadGateway when the server is not reachable",
|
desc: "StatusBadGateway when the server is not reachable",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: "http://foo",
|
URL: "http://foo",
|
||||||
},
|
},
|
||||||
|
@ -161,8 +161,8 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "ServiceUnavailable when no servers are available",
|
desc: "ServiceUnavailable when no servers are available",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Servers: []config.Server{},
|
Servers: []dynamic.Server{},
|
||||||
},
|
},
|
||||||
expected: []ExpectedResult{
|
expected: []ExpectedResult{
|
||||||
{
|
{
|
||||||
|
@ -173,9 +173,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Always call the same server when stickiness is true",
|
desc: "Always call the same server when stickiness is true",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{},
|
Stickiness: &dynamic.Stickiness{},
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server1.URL,
|
URL: server1.URL,
|
||||||
},
|
},
|
||||||
|
@ -198,9 +198,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Sticky Cookie's options set correctly",
|
desc: "Sticky Cookie's options set correctly",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{HTTPOnlyCookie: true, SecureCookie: true},
|
Stickiness: &dynamic.Stickiness{HTTPOnlyCookie: true, SecureCookie: true},
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: server1.URL,
|
URL: server1.URL,
|
||||||
},
|
},
|
||||||
|
@ -218,10 +218,10 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "PassHost passes the host instead of the IP",
|
desc: "PassHost passes the host instead of the IP",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{},
|
Stickiness: &dynamic.Stickiness{},
|
||||||
PassHostHeader: true,
|
PassHostHeader: true,
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: serverPassHost.URL,
|
URL: serverPassHost.URL,
|
||||||
},
|
},
|
||||||
|
@ -237,9 +237,9 @@ func TestGetLoadBalancerServiceHandler(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "PassHost doesn't passe the host instead of the IP",
|
desc: "PassHost doesn't passe the host instead of the IP",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
service: &config.LoadBalancerService{
|
service: &dynamic.LoadBalancerService{
|
||||||
Stickiness: &config.Stickiness{},
|
Stickiness: &dynamic.Stickiness{},
|
||||||
Servers: []config.Server{
|
Servers: []dynamic.Server{
|
||||||
{
|
{
|
||||||
URL: serverPassHostFalse.URL,
|
URL: serverPassHostFalse.URL,
|
||||||
},
|
},
|
||||||
|
@ -287,16 +287,16 @@ func TestManager_Build(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
serviceName string
|
serviceName string
|
||||||
configs map[string]*config.ServiceInfo
|
configs map[string]*dynamic.ServiceInfo
|
||||||
providerName string
|
providerName string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
desc: "Simple service name",
|
desc: "Simple service name",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.ServiceInfo{
|
configs: map[string]*dynamic.ServiceInfo{
|
||||||
"serviceName": {
|
"serviceName": {
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{},
|
LoadBalancer: &dynamic.LoadBalancerService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -304,10 +304,10 @@ func TestManager_Build(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Service name with provider",
|
desc: "Service name with provider",
|
||||||
serviceName: "serviceName@provider-1",
|
serviceName: "serviceName@provider-1",
|
||||||
configs: map[string]*config.ServiceInfo{
|
configs: map[string]*dynamic.ServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{},
|
LoadBalancer: &dynamic.LoadBalancerService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -315,10 +315,10 @@ func TestManager_Build(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Service name with provider in context",
|
desc: "Service name with provider in context",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.ServiceInfo{
|
configs: map[string]*dynamic.ServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
Service: &config.Service{
|
Service: &dynamic.Service{
|
||||||
LoadBalancer: &config.LoadBalancerService{},
|
LoadBalancer: &dynamic.LoadBalancerService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"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/log"
|
||||||
"github.com/containous/traefik/pkg/server/internal"
|
"github.com/containous/traefik/pkg/server/internal"
|
||||||
"github.com/containous/traefik/pkg/tcp"
|
"github.com/containous/traefik/pkg/tcp"
|
||||||
|
@ -13,11 +13,11 @@ import (
|
||||||
|
|
||||||
// Manager is the TCPHandlers factory
|
// Manager is the TCPHandlers factory
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
configs map[string]*config.TCPServiceInfo
|
configs map[string]*dynamic.TCPServiceInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewManager creates a new manager
|
// NewManager creates a new manager
|
||||||
func NewManager(conf *config.RuntimeConfiguration) *Manager {
|
func NewManager(conf *dynamic.RuntimeConfiguration) *Manager {
|
||||||
return &Manager{
|
return &Manager{
|
||||||
configs: conf.TCPServices,
|
configs: conf.TCPServices,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"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/server/internal"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -14,7 +14,7 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
serviceName string
|
serviceName string
|
||||||
configs map[string]*config.TCPServiceInfo
|
configs map[string]*dynamic.TCPServiceInfo
|
||||||
providerName string
|
providerName string
|
||||||
expectedError string
|
expectedError string
|
||||||
}{
|
}{
|
||||||
|
@ -27,9 +27,9 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "missing lb configuration",
|
desc: "missing lb configuration",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"test": {
|
"test": {
|
||||||
TCPService: &config.TCPService{},
|
TCPService: &dynamic.TCPService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: `the service "test" doesn't have any TCP load balancer`,
|
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",
|
desc: "no such host, server is skipped, error is logged",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"test": {
|
"test": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{Address: "test:31"},
|
{Address: "test:31"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -52,11 +52,11 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "invalid IP address, server is skipped, error is logged",
|
desc: "invalid IP address, server is skipped, error is logged",
|
||||||
serviceName: "test",
|
serviceName: "test",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"test": {
|
"test": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{Address: "foobar"},
|
{Address: "foobar"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -67,10 +67,10 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Simple service name",
|
desc: "Simple service name",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName": {
|
"serviceName": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{},
|
LoadBalancer: &dynamic.TCPLoadBalancerService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -78,10 +78,10 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Service name with provider",
|
desc: "Service name with provider",
|
||||||
serviceName: "serviceName@provider-1",
|
serviceName: "serviceName@provider-1",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{},
|
LoadBalancer: &dynamic.TCPLoadBalancerService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -89,10 +89,10 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Service name with provider in context",
|
desc: "Service name with provider in context",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{},
|
LoadBalancer: &dynamic.TCPLoadBalancerService{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -101,11 +101,11 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Server with correct host:port as address",
|
desc: "Server with correct host:port as address",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "foobar.com:80",
|
Address: "foobar.com:80",
|
||||||
},
|
},
|
||||||
|
@ -119,11 +119,11 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Server with correct ip:port as address",
|
desc: "Server with correct ip:port as address",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "192.168.0.12:80",
|
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",
|
desc: "missing port in address with hostname, server is skipped, error is logged",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "foobar.com",
|
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",
|
desc: "missing port in address with ip, server is skipped, error is logged",
|
||||||
serviceName: "serviceName",
|
serviceName: "serviceName",
|
||||||
configs: map[string]*config.TCPServiceInfo{
|
configs: map[string]*dynamic.TCPServiceInfo{
|
||||||
"serviceName@provider-1": {
|
"serviceName@provider-1": {
|
||||||
TCPService: &config.TCPService{
|
TCPService: &dynamic.TCPService{
|
||||||
LoadBalancer: &config.TCPLoadBalancerService{
|
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||||
Servers: []config.TCPServer{
|
Servers: []dynamic.TCPServer{
|
||||||
{
|
{
|
||||||
Address: "192.168.0.12",
|
Address: "192.168.0.12",
|
||||||
},
|
},
|
||||||
|
@ -177,7 +177,7 @@ func TestManager_BuildTCP(t *testing.T) {
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
manager := NewManager(&config.RuntimeConfiguration{
|
manager := NewManager(&dynamic.RuntimeConfiguration{
|
||||||
TCPServices: test.configs,
|
TCPServices: test.configs,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue