config: deal with multiple errors and their criticality

Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com>
This commit is contained in:
mpl 2019-07-15 17:04:04 +02:00 committed by Traefiker Bot
parent 62800116d3
commit 6fdd48509e
45 changed files with 725 additions and 412 deletions

View file

@ -0,0 +1,45 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web-secure]
address = ":4443"
[api]
[providers.file]
filename = "{{ .SelfFilename }}"
## dynamic configuration ##
[http.routers]
[http.routers.router4]
service = "service1"
rule = "Host(`snitest.net`)"
[http.routers.router4.tls]
options = "foo"
[http.routers.router5]
service = "service1"
rule = "Host(`snitest.net`)"
middlewares = [ "unknown" ]
[http.routers.router5.tls]
options = "baz"
[http.services]
[http.services.service1]
[http.services.service1.loadBalancer]
[[http.services.service1.loadBalancer.servers]]
url = "http://127.0.0.1:9010"
[tls.options]
[tls.options.foo]
minversion = "VersionTLS11"
[tls.options.baz]
minversion = "VersionTLS11"

View file

@ -0,0 +1,34 @@
[global]
checkNewVersion = false
sendAnonymousUsage = false
[log]
level = "DEBUG"
[entryPoints]
[entryPoints.web-secure]
address = ":4443"
[api]
[providers.file]
filename = "{{ .SelfFilename }}"
## dynamic configuration ##
[http.routers]
[http.routers.router4]
service = "service1"
rule = "Host(`snitest.net`)"
[http.routers.router5]
service = "service2"
rule = "Host(`snitest.com`)"
[http.services]
[http.services.service1]
[http.services.service2]
[http.services.service2.loadBalancer]
[[http.services.service2.loadBalancer.servers]]
url = "http://127.0.0.1:9010"

View file

@ -524,3 +524,48 @@ func (s *SimpleSuite) TestSimpleConfigurationHostRequestTrailingPeriod(c *check.
} }
} }
} }
func (s *SimpleSuite) TestRouterConfigErrors(c *check.C) {
file := s.adaptFile(c, "fixtures/router_errors.toml", struct{}{})
defer os.Remove(file)
cmd, output := s.traefikCmd(withConfigFile(file))
defer output(c)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
// All errors
err = try.GetRequest("http://127.0.0.1:8080/api/http/routers", 1000*time.Millisecond, try.BodyContains(`["middleware \"unknown@file\" does not exist","found different TLS options for routers on the same host snitest.net, so using the default TLS option instead"]`))
c.Assert(err, checker.IsNil)
// router4 is enabled, but in warning state because its tls options conf was messed up
err = try.GetRequest("http://127.0.0.1:8080/api/http/routers/router4@file", 1000*time.Millisecond, try.BodyContains(`"status":"warning"`))
c.Assert(err, checker.IsNil)
// router5 is disabled because its middleware conf is broken
err = try.GetRequest("http://127.0.0.1:8080/api/http/routers/router5@file", 1000*time.Millisecond, try.BodyContains())
c.Assert(err, checker.IsNil)
}
func (s *SimpleSuite) TestServiceConfigErrors(c *check.C) {
file := s.adaptFile(c, "fixtures/service_errors.toml", struct{}{})
defer os.Remove(file)
cmd, output := s.traefikCmd(withConfigFile(file))
defer output(c)
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
err = try.GetRequest("http://127.0.0.1:8080/api/http/services", 1000*time.Millisecond, try.BodyContains(`["the service \"service1@file\" doesn't have any load balancer"]`))
c.Assert(err, checker.IsNil)
err = try.GetRequest("http://127.0.0.1:8080/api/http/services/service1@file", 1000*time.Millisecond, try.BodyContains(`"status":"disabled"`))
c.Assert(err, checker.IsNil)
err = try.GetRequest("http://127.0.0.1:8080/api/http/services/service2@file", 1000*time.Millisecond, try.BodyContains(`"status":"enabled"`))
c.Assert(err, checker.IsNil)
}

View file

@ -9,7 +9,8 @@
"priority": 12, "priority": 12,
"tls": { "tls": {
"options": "default/mytlsoption" "options": "default/mytlsoption"
} },
"status": "enabled"
}, },
"default/test2.route-23c7f4c450289ee29016@kubernetescrd": { "default/test2.route-23c7f4c450289ee29016@kubernetescrd": {
"entryPoints": [ "entryPoints": [
@ -19,7 +20,8 @@
"default/stripprefix" "default/stripprefix"
], ],
"service": "default/test2.route-23c7f4c450289ee29016", "service": "default/test2.route-23c7f4c450289ee29016",
"rule": "Host(`foo.com`) \u0026\u0026 PathPrefix(`/tobestripped`)" "rule": "Host(`foo.com`) \u0026\u0026 PathPrefix(`/tobestripped`)",
"status": "enabled"
} }
}, },
"middlewares": { "middlewares": {
@ -39,7 +41,7 @@
"loadBalancer": { "loadBalancer": {
"servers": [ "servers": [
{ {
"url": "http://10.42.0.3:80" "url": "http://10.42.0.4:80"
}, },
{ {
"url": "http://10.42.0.5:80" "url": "http://10.42.0.5:80"
@ -47,11 +49,12 @@
], ],
"passHostHeader": true "passHostHeader": true
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"default/test.route-6b204d94623b3df4370c@kubernetescrd" "default/test.route-6b204d94623b3df4370c@kubernetescrd"
], ],
"serverStatus": { "serverStatus": {
"http://10.42.0.3:80": "UP", "http://10.42.0.4:80": "UP",
"http://10.42.0.5:80": "UP" "http://10.42.0.5:80": "UP"
} }
}, },
@ -59,7 +62,7 @@
"loadBalancer": { "loadBalancer": {
"servers": [ "servers": [
{ {
"url": "http://10.42.0.3:80" "url": "http://10.42.0.4:80"
}, },
{ {
"url": "http://10.42.0.5:80" "url": "http://10.42.0.5:80"
@ -67,11 +70,12 @@
], ],
"passHostHeader": true "passHostHeader": true
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"default/test2.route-23c7f4c450289ee29016@kubernetescrd" "default/test2.route-23c7f4c450289ee29016@kubernetescrd"
], ],
"serverStatus": { "serverStatus": {
"http://10.42.0.3:80": "UP", "http://10.42.0.4:80": "UP",
"http://10.42.0.5:80": "UP" "http://10.42.0.5:80": "UP"
} }
} }
@ -86,7 +90,8 @@
"tls": { "tls": {
"passthrough": false, "passthrough": false,
"options": "default/mytlsoption" "options": "default/mytlsoption"
} },
"status": "enabled"
} }
}, },
"tcpServices": { "tcpServices": {
@ -94,13 +99,14 @@
"loadBalancer": { "loadBalancer": {
"servers": [ "servers": [
{ {
"address": "10.42.0.4:8080" "address": "10.42.0.3:8080"
}, },
{ {
"address": "10.42.0.6:8080" "address": "10.42.0.6:8080"
} }
] ]
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"default/test3.crd-673acf455cb2dab0b43a@kubernetescrd" "default/test3.crd-673acf455cb2dab0b43a@kubernetescrd"
] ]

View file

@ -2,7 +2,8 @@
"routers": { "routers": {
"whoami-test/whoami@kubernetes": { "whoami-test/whoami@kubernetes": {
"service": "default/whoami/http", "service": "default/whoami/http",
"rule": "Host(`whoami.test`) \u0026\u0026 PathPrefix(`/whoami`)" "rule": "Host(`whoami.test`) \u0026\u0026 PathPrefix(`/whoami`)",
"status": "enabled"
} }
}, },
"services": { "services": {
@ -10,7 +11,7 @@
"loadBalancer": { "loadBalancer": {
"servers": [ "servers": [
{ {
"url": "http://10.42.0.2:80" "url": "http://10.42.0.4:80"
}, },
{ {
"url": "http://10.42.0.5:80" "url": "http://10.42.0.5:80"
@ -18,11 +19,12 @@
], ],
"passHostHeader": true "passHostHeader": true
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"whoami-test/whoami@kubernetes" "whoami-test/whoami@kubernetes"
], ],
"serverStatus": { "serverStatus": {
"http://10.42.0.2:80": "UP", "http://10.42.0.4:80": "UP",
"http://10.42.0.5:80": "UP" "http://10.42.0.5:80": "UP"
} }
} }

View file

@ -8,7 +8,7 @@ import (
"strings" "strings"
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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"
@ -24,17 +24,17 @@ const (
const nextPageHeader = "X-Next-Page" const nextPageHeader = "X-Next-Page"
type serviceInfoRepresentation struct { type serviceInfoRepresentation struct {
*dynamic.ServiceInfo *runtime.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]*dynamic.RouterInfo `json:"routers,omitempty"` Routers map[string]*runtime.RouterInfo `json:"routers,omitempty"`
Middlewares map[string]*dynamic.MiddlewareInfo `json:"middlewares,omitempty"` Middlewares map[string]*runtime.MiddlewareInfo `json:"middlewares,omitempty"`
Services map[string]*serviceInfoRepresentation `json:"services,omitempty"` Services map[string]*serviceInfoRepresentation `json:"services,omitempty"`
TCPRouters map[string]*dynamic.TCPRouterInfo `json:"tcpRouters,omitempty"` TCPRouters map[string]*runtime.TCPRouterInfo `json:"tcpRouters,omitempty"`
TCPServices map[string]*dynamic.TCPServiceInfo `json:"tcpServices,omitempty"` TCPServices map[string]*runtime.TCPServiceInfo `json:"tcpServices,omitempty"`
} }
type pageInfo struct { type pageInfo struct {
@ -48,7 +48,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 *dynamic.RuntimeConfiguration runtimeConfiguration *runtime.Configuration
staticConfig static.Configuration staticConfig static.Configuration
statistics *types.Statistics statistics *types.Statistics
// stats *thoasstats.Stats // FIXME stats // stats *thoasstats.Stats // FIXME stats
@ -58,10 +58,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 *dynamic.RuntimeConfiguration) *Handler { func New(staticConfig static.Configuration, runtimeConfig *runtime.Configuration) *Handler {
rConfig := runtimeConfig rConfig := runtimeConfig
if rConfig == nil { if rConfig == nil {
rConfig = &dynamic.RuntimeConfiguration{} rConfig = &runtime.Configuration{}
} }
return &Handler{ return &Handler{

View file

@ -10,7 +10,7 @@ import (
"testing" "testing"
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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"
@ -198,7 +198,7 @@ func TestHandler_EntryPoints(t *testing.T) {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
handler := New(test.conf, &dynamic.RuntimeConfiguration{}) handler := New(test.conf, &runtime.Configuration{})
router := mux.NewRouter() router := mux.NewRouter()
handler.Append(router) handler.Append(router)

View file

@ -7,25 +7,25 @@ import (
"strconv" "strconv"
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"github.com/containous/traefik/pkg/log" "github.com/containous/traefik/pkg/log"
) )
type routerRepresentation struct { type routerRepresentation struct {
*dynamic.RouterInfo *runtime.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 {
*dynamic.ServiceInfo *runtime.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 {
*dynamic.MiddlewareInfo *runtime.MiddlewareInfo
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"` Provider string `json:"provider,omitempty"`
} }

View file

@ -11,6 +11,7 @@ import (
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -26,13 +27,13 @@ func TestHandler_HTTP(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
path string path string
conf dynamic.RuntimeConfiguration conf runtime.Configuration
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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
nextPage: "1", nextPage: "1",
@ -42,8 +43,8 @@ func TestHandler_HTTP(t *testing.T) {
{ {
desc: "all routers", desc: "all routers",
path: "/api/http/routers", path: "/api/http/routers",
conf: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"test@myprovider": { "test@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -71,8 +72,8 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -107,7 +108,7 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: generateHTTPRouters(19), Routers: generateHTTPRouters(19),
}, },
expected: expected{ expected: expected{
@ -119,7 +120,7 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: generateHTTPRouters(5), Routers: generateHTTPRouters(5),
}, },
expected: expected{ expected: expected{
@ -129,7 +130,7 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: generateHTTPRouters(10), Routers: generateHTTPRouters(10),
}, },
expected: expected{ expected: expected{
@ -139,8 +140,8 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -148,6 +149,7 @@ func TestHandler_HTTP(t *testing.T) {
Rule: "Host(`foo.bar`)", Rule: "Host(`foo.bar`)",
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"}, Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
}, },
Status: "enabled",
}, },
}, },
}, },
@ -159,8 +161,8 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -178,7 +180,7 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusNotFound, statusCode: http.StatusNotFound,
}, },
@ -186,7 +188,7 @@ func TestHandler_HTTP(t *testing.T) {
{ {
desc: "all services, but no config", desc: "all services, but no config",
path: "/api/http/services", path: "/api/http/services",
conf: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
nextPage: "1", nextPage: "1",
@ -196,10 +198,10 @@ func TestHandler_HTTP(t *testing.T) {
{ {
desc: "all services", desc: "all services",
path: "/api/http/services", path: "/api/http/services",
conf: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo { "bar@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -211,11 +213,11 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider", "test@myprovider"}, UsedBy: []string{"foo@myprovider", "test@myprovider"},
} }
si.UpdateStatus("http://127.0.0.1", "UP") si.UpdateServerStatus("http://127.0.0.1", "UP")
return si return si
}(), }(),
"baz@myprovider": func() *dynamic.ServiceInfo { "baz@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -227,7 +229,7 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider"}, UsedBy: []string{"foo@myprovider"},
} }
si.UpdateStatus("http://127.0.0.2", "UP") si.UpdateServerStatus("http://127.0.0.2", "UP")
return si return si
}(), }(),
}, },
@ -241,10 +243,10 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo { "bar@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -256,11 +258,11 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider", "test@myprovider"}, UsedBy: []string{"foo@myprovider", "test@myprovider"},
} }
si.UpdateStatus("http://127.0.0.1", "UP") si.UpdateServerStatus("http://127.0.0.1", "UP")
return si return si
}(), }(),
"baz@myprovider": func() *dynamic.ServiceInfo { "baz@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -272,11 +274,11 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider"}, UsedBy: []string{"foo@myprovider"},
} }
si.UpdateStatus("http://127.0.0.2", "UP") si.UpdateServerStatus("http://127.0.0.2", "UP")
return si return si
}(), }(),
"test@myprovider": func() *dynamic.ServiceInfo { "test@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -288,7 +290,7 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider", "test@myprovider"}, UsedBy: []string{"foo@myprovider", "test@myprovider"},
} }
si.UpdateStatus("http://127.0.0.4", "UP") si.UpdateServerStatus("http://127.0.0.4", "UP")
return si return si
}(), }(),
}, },
@ -302,10 +304,10 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo { "bar@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -317,7 +319,7 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider", "test@myprovider"}, UsedBy: []string{"foo@myprovider", "test@myprovider"},
} }
si.UpdateStatus("http://127.0.0.1", "UP") si.UpdateServerStatus("http://127.0.0.1", "UP")
return si return si
}(), }(),
}, },
@ -330,10 +332,10 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"bar@myprovider": func() *dynamic.ServiceInfo { "bar@myprovider": func() *runtime.ServiceInfo {
si := &dynamic.ServiceInfo{ si := &runtime.ServiceInfo{
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{
@ -345,7 +347,7 @@ func TestHandler_HTTP(t *testing.T) {
}, },
UsedBy: []string{"foo@myprovider", "test@myprovider"}, UsedBy: []string{"foo@myprovider", "test@myprovider"},
} }
si.UpdateStatus("http://127.0.0.1", "UP") si.UpdateServerStatus("http://127.0.0.1", "UP")
return si return si
}(), }(),
}, },
@ -357,7 +359,7 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusNotFound, statusCode: http.StatusNotFound,
}, },
@ -365,7 +367,7 @@ func TestHandler_HTTP(t *testing.T) {
{ {
desc: "all middlewares, but no config", desc: "all middlewares, but no config",
path: "/api/http/middlewares", path: "/api/http/middlewares",
conf: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
nextPage: "1", nextPage: "1",
@ -375,8 +377,8 @@ func TestHandler_HTTP(t *testing.T) {
{ {
desc: "all middlewares", desc: "all middlewares",
path: "/api/http/middlewares", path: "/api/http/middlewares",
conf: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -412,8 +414,8 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -449,8 +451,8 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -485,8 +487,8 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -504,7 +506,7 @@ func TestHandler_HTTP(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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusNotFound, statusCode: http.StatusNotFound,
}, },
@ -517,6 +519,8 @@ func TestHandler_HTTP(t *testing.T) {
t.Parallel() t.Parallel()
rtConf := &test.conf rtConf := &test.conf
// To lazily initialize the Statuses.
rtConf.PopulateUsedBy()
handler := New(static.Configuration{API: &static.API{}, Global: &static.Global{}}, rtConf) handler := New(static.Configuration{API: &static.API{}, Global: &static.Global{}}, rtConf)
router := mux.NewRouter() router := mux.NewRouter()
handler.Append(router) handler.Append(router)
@ -560,10 +564,10 @@ func TestHandler_HTTP(t *testing.T) {
} }
} }
func generateHTTPRouters(nbRouters int) map[string]*dynamic.RouterInfo { func generateHTTPRouters(nbRouters int) map[string]*runtime.RouterInfo {
routers := make(map[string]*dynamic.RouterInfo, nbRouters) routers := make(map[string]*runtime.RouterInfo, nbRouters)
for i := 0; i < nbRouters; i++ { for i := 0; i < nbRouters; i++ {
routers[fmt.Sprintf("bar%2d@myprovider", i)] = &dynamic.RouterInfo{ routers[fmt.Sprintf("bar%2d@myprovider", i)] = &runtime.RouterInfo{
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
Service: "foo-service@myprovider", Service: "foo-service@myprovider",

View file

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"reflect" "reflect"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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"
) )
@ -60,37 +60,45 @@ func (h Handler) getOverview(rw http.ResponseWriter, request *http.Request) {
} }
} }
func getHTTPRouterSection(routers map[string]*dynamic.RouterInfo) *section { func getHTTPRouterSection(routers map[string]*runtime.RouterInfo) *section {
var countErrors int var countErrors int
var countWarnings int
for _, rt := range routers { for _, rt := range routers {
if rt.Err != "" { switch rt.Status {
case runtime.StatusDisabled:
countErrors++ countErrors++
case runtime.StatusWarning:
countWarnings++
} }
} }
return &section{ return &section{
Total: len(routers), Total: len(routers),
Warnings: 0, // TODO Warnings: countWarnings,
Errors: countErrors, Errors: countErrors,
} }
} }
func getHTTPServiceSection(services map[string]*dynamic.ServiceInfo) *section { func getHTTPServiceSection(services map[string]*runtime.ServiceInfo) *section {
var countErrors int var countErrors int
var countWarnings int
for _, svc := range services { for _, svc := range services {
if svc.Err != nil { switch svc.Status {
case runtime.StatusDisabled:
countErrors++ countErrors++
case runtime.StatusWarning:
countWarnings++
} }
} }
return &section{ return &section{
Total: len(services), Total: len(services),
Warnings: 0, // TODO Warnings: countWarnings,
Errors: countErrors, Errors: countErrors,
} }
} }
func getHTTPMiddlewareSection(middlewares map[string]*dynamic.MiddlewareInfo) *section { func getHTTPMiddlewareSection(middlewares map[string]*runtime.MiddlewareInfo) *section {
var countErrors int var countErrors int
for _, md := range middlewares { for _, md := range middlewares {
if md.Err != nil { if md.Err != nil {
@ -100,12 +108,12 @@ func getHTTPMiddlewareSection(middlewares map[string]*dynamic.MiddlewareInfo) *s
return &section{ return &section{
Total: len(middlewares), Total: len(middlewares),
Warnings: 0, // TODO Warnings: 0,
Errors: countErrors, Errors: countErrors,
} }
} }
func getTCPRouterSection(routers map[string]*dynamic.TCPRouterInfo) *section { func getTCPRouterSection(routers map[string]*runtime.TCPRouterInfo) *section {
var countErrors int var countErrors int
for _, rt := range routers { for _, rt := range routers {
if rt.Err != "" { if rt.Err != "" {
@ -120,7 +128,7 @@ func getTCPRouterSection(routers map[string]*dynamic.TCPRouterInfo) *section {
} }
} }
func getTCPServiceSection(services map[string]*dynamic.TCPServiceInfo) *section { func getTCPServiceSection(services map[string]*runtime.TCPServiceInfo) *section {
var countErrors int var countErrors int
for _, svc := range services { for _, svc := range services {
if svc.Err != nil { if svc.Err != nil {

View file

@ -9,6 +9,7 @@ import (
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"github.com/containous/traefik/pkg/config/static" "github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/provider/docker" "github.com/containous/traefik/pkg/provider/docker"
"github.com/containous/traefik/pkg/provider/file" "github.com/containous/traefik/pkg/provider/file"
@ -33,14 +34,14 @@ func TestHandler_Overview(t *testing.T) {
desc string desc string
path string path string
confStatic static.Configuration confStatic static.Configuration
confDyn dynamic.RuntimeConfiguration confDyn runtime.Configuration
expected expected expected expected
}{ }{
{ {
desc: "without data in the dynamic configuration", desc: "without data in the dynamic configuration",
path: "/api/overview", path: "/api/overview",
confStatic: static.Configuration{API: &static.API{}, Global: &static.Global{}}, confStatic: static.Configuration{API: &static.API{}, Global: &static.Global{}},
confDyn: dynamic.RuntimeConfiguration{}, confDyn: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
jsonFile: "testdata/overview-empty.json", jsonFile: "testdata/overview-empty.json",
@ -50,21 +51,34 @@ func TestHandler_Overview(t *testing.T) {
desc: "with data in the dynamic configuration", desc: "with data in the dynamic configuration",
path: "/api/overview", path: "/api/overview",
confStatic: static.Configuration{API: &static.API{}, Global: &static.Global{}}, confStatic: static.Configuration{API: &static.API{}, Global: &static.Global{}},
confDyn: dynamic.RuntimeConfiguration{ confDyn: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{ Servers: []dynamic.Server{{URL: "http://127.0.0.1"}},
{
URL: "http://127.0.0.1",
},
},
}, },
}, },
Status: runtime.StatusEnabled,
},
"bar-service@myprovider": {
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{{URL: "http://127.0.0.1"}},
},
},
Status: runtime.StatusWarning,
},
"fii-service@myprovider": {
Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{
Servers: []dynamic.Server{{URL: "http://127.0.0.1"}},
},
},
Status: runtime.StatusDisabled,
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -85,9 +99,10 @@ func TestHandler_Overview(t *testing.T) {
Prefix: "/toto", Prefix: "/toto",
}, },
}, },
Err: []string{"error"},
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -95,6 +110,7 @@ func TestHandler_Overview(t *testing.T) {
Rule: "Host(`foo.bar`)", Rule: "Host(`foo.bar`)",
Middlewares: []string{"auth", "addPrefixTest@anotherprovider"}, Middlewares: []string{"auth", "addPrefixTest@anotherprovider"},
}, },
Status: runtime.StatusEnabled,
}, },
"test@myprovider": { "test@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
@ -103,9 +119,19 @@ func TestHandler_Overview(t *testing.T) {
Rule: "Host(`foo.bar.other`)", Rule: "Host(`foo.bar.other`)",
Middlewares: []string{"addPrefixTest", "auth"}, Middlewares: []string{"addPrefixTest", "auth"},
}, },
Status: runtime.StatusWarning,
},
"foo@myprovider": {
Router: &dynamic.Router{
EntryPoints: []string{"web"},
Service: "foo-service@myprovider",
Rule: "Host(`foo.bar.other`)",
Middlewares: []string{"addPrefixTest", "auth"},
},
Status: runtime.StatusDisabled,
}, },
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"tcpfoo-service@myprovider": { "tcpfoo-service@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -118,7 +144,7 @@ func TestHandler_Overview(t *testing.T) {
}, },
}, },
}, },
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"tcpbar@myprovider": { "tcpbar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -156,7 +182,7 @@ func TestHandler_Overview(t *testing.T) {
Rancher: &rancher.Provider{}, Rancher: &rancher.Provider{},
}, },
}, },
confDyn: dynamic.RuntimeConfiguration{}, confDyn: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
jsonFile: "testdata/overview-providers.json", jsonFile: "testdata/overview-providers.json",
@ -175,7 +201,7 @@ func TestHandler_Overview(t *testing.T) {
Jaeger: &jaeger.Config{}, Jaeger: &jaeger.Config{},
}, },
}, },
confDyn: dynamic.RuntimeConfiguration{}, confDyn: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
jsonFile: "testdata/overview-features.json", jsonFile: "testdata/overview-features.json",

View file

@ -7,18 +7,18 @@ import (
"strconv" "strconv"
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"github.com/containous/traefik/pkg/log" "github.com/containous/traefik/pkg/log"
) )
type tcpRouterRepresentation struct { type tcpRouterRepresentation struct {
*dynamic.TCPRouterInfo *runtime.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 {
*dynamic.TCPServiceInfo *runtime.TCPServiceInfo
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Provider string `json:"provider,omitempty"` Provider string `json:"provider,omitempty"`
} }

View file

@ -9,6 +9,7 @@ import (
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -24,13 +25,13 @@ func TestHandler_TCP(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
path string path string
conf dynamic.RuntimeConfiguration conf runtime.Configuration
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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
nextPage: "1", nextPage: "1",
@ -40,8 +41,8 @@ func TestHandler_TCP(t *testing.T) {
{ {
desc: "all TCP routers", desc: "all TCP routers",
path: "/api/tcp/routers", path: "/api/tcp/routers",
conf: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"test@myprovider": { "test@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -70,8 +71,8 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"bar@myprovider": { "bar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -104,8 +105,8 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"bar@myprovider": { "bar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -123,8 +124,8 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"bar@myprovider": { "bar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -141,7 +142,7 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusNotFound, statusCode: http.StatusNotFound,
}, },
@ -149,7 +150,7 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusOK, statusCode: http.StatusOK,
nextPage: "1", nextPage: "1",
@ -159,8 +160,8 @@ func TestHandler_TCP(t *testing.T) {
{ {
desc: "all tcp services", desc: "all tcp services",
path: "/api/tcp/services", path: "/api/tcp/services",
conf: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"bar@myprovider": { "bar@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -196,8 +197,8 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"bar@myprovider": { "bar@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -244,8 +245,8 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"bar@myprovider": { "bar@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -268,8 +269,8 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"bar@myprovider": { "bar@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -291,7 +292,7 @@ func TestHandler_TCP(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: dynamic.RuntimeConfiguration{}, conf: runtime.Configuration{},
expected: expected{ expected: expected{
statusCode: http.StatusNotFound, statusCode: http.StatusNotFound,
}, },

View file

@ -10,6 +10,7 @@ import (
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -26,14 +27,14 @@ func TestHandler_RawData(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
path string path string
conf dynamic.RuntimeConfiguration conf runtime.Configuration
expected expected expected expected
}{ }{
{ {
desc: "Get rawdata", desc: "Get rawdata",
path: "/api/rawdata", path: "/api/rawdata",
conf: dynamic.RuntimeConfiguration{ conf: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -46,7 +47,7 @@ func TestHandler_RawData(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -69,7 +70,7 @@ func TestHandler_RawData(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -87,7 +88,7 @@ func TestHandler_RawData(t *testing.T) {
}, },
}, },
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"tcpfoo-service@myprovider": { "tcpfoo-service@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -100,7 +101,7 @@ func TestHandler_RawData(t *testing.T) {
}, },
}, },
}, },
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"tcpbar@myprovider": { "tcpbar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},

View file

@ -9,7 +9,8 @@
"addPrefixTest@anotherprovider" "addPrefixTest@anotherprovider"
], ],
"service": "foo-service@myprovider", "service": "foo-service@myprovider",
"rule": "Host(`foo.bar`)" "rule": "Host(`foo.bar`)",
"status": "enabled"
}, },
"test@myprovider": { "test@myprovider": {
"entryPoints": [ "entryPoints": [
@ -20,7 +21,8 @@
"auth" "auth"
], ],
"service": "foo-service@myprovider", "service": "foo-service@myprovider",
"rule": "Host(`foo.bar.other`)" "rule": "Host(`foo.bar.other`)",
"status": "enabled"
} }
}, },
"middlewares": { "middlewares": {
@ -62,6 +64,7 @@
], ],
"passHostHeader": false "passHostHeader": false
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"bar@myprovider", "bar@myprovider",
"test@myprovider" "test@myprovider"
@ -74,14 +77,16 @@
"web" "web"
], ],
"service": "tcpfoo-service@myprovider", "service": "tcpfoo-service@myprovider",
"rule": "HostSNI(`foo.bar`)" "rule": "HostSNI(`foo.bar`)",
"status": "enabled"
}, },
"tcptest@myprovider": { "tcptest@myprovider": {
"entryPoints": [ "entryPoints": [
"web" "web"
], ],
"service": "tcpfoo-service@myprovider", "service": "tcpfoo-service@myprovider",
"rule": "HostSNI(`foo.bar.other`)" "rule": "HostSNI(`foo.bar.other`)",
"status": "enabled"
} }
}, },
"tcpServices": { "tcpServices": {
@ -93,6 +98,7 @@
} }
] ]
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"tcpbar@myprovider", "tcpbar@myprovider",
"tcptest@myprovider" "tcptest@myprovider"

View file

@ -6,19 +6,19 @@
}, },
"http": { "http": {
"middlewares": { "middlewares": {
"errors": 0, "errors": 1,
"total": 3, "total": 3,
"warnings": 0 "warnings": 0
}, },
"routers": { "routers": {
"errors": 0, "errors": 1,
"total": 2, "total": 3,
"warnings": 0 "warnings": 1
}, },
"services": { "services": {
"errors": 0, "errors": 1,
"total": 1, "total": 3,
"warnings": 0 "warnings": 1
} }
}, },
"tcp": { "tcp": {

View file

@ -9,5 +9,6 @@
"name": "bar@myprovider", "name": "bar@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar`)", "rule": "Host(`foo.bar`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
} }

View file

@ -6,7 +6,8 @@
"name": "bar14@myprovider", "name": "bar14@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar14`)", "rule": "Host(`foo.bar14`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
}, },
{ {
"entryPoints": [ "entryPoints": [
@ -15,7 +16,8 @@
"name": "bar15@myprovider", "name": "bar15@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar15`)", "rule": "Host(`foo.bar15`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
}, },
{ {
"entryPoints": [ "entryPoints": [
@ -24,7 +26,8 @@
"name": "bar16@myprovider", "name": "bar16@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar16`)", "rule": "Host(`foo.bar16`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
}, },
{ {
"entryPoints": [ "entryPoints": [
@ -33,7 +36,8 @@
"name": "bar17@myprovider", "name": "bar17@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar17`)", "rule": "Host(`foo.bar17`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
}, },
{ {
"entryPoints": [ "entryPoints": [
@ -42,6 +46,7 @@
"name": "bar18@myprovider", "name": "bar18@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar18`)", "rule": "Host(`foo.bar18`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
} }
] ]

View file

@ -6,6 +6,7 @@
"name": "baz@myprovider", "name": "baz@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`toto.bar`)", "rule": "Host(`toto.bar`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
} }
] ]

View file

@ -10,7 +10,8 @@
"name": "bar@myprovider", "name": "bar@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar`)", "rule": "Host(`foo.bar`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
}, },
{ {
"entryPoints": [ "entryPoints": [
@ -23,6 +24,7 @@
"name": "test@myprovider", "name": "test@myprovider",
"provider": "myprovider", "provider": "myprovider",
"rule": "Host(`foo.bar.other`)", "rule": "Host(`foo.bar.other`)",
"service": "foo-service@myprovider" "service": "foo-service@myprovider",
"status": "enabled"
} }
] ]

View file

@ -12,6 +12,7 @@
"serverStatus": { "serverStatus": {
"http://127.0.0.1": "UP" "http://127.0.0.1": "UP"
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"foo@myprovider", "foo@myprovider",
"test@myprovider" "test@myprovider"

View file

@ -13,6 +13,7 @@
"serverStatus": { "serverStatus": {
"http://127.0.0.2": "UP" "http://127.0.0.2": "UP"
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"foo@myprovider" "foo@myprovider"
] ]

View file

@ -13,6 +13,7 @@
"serverStatus": { "serverStatus": {
"http://127.0.0.1": "UP" "http://127.0.0.1": "UP"
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"foo@myprovider", "foo@myprovider",
"test@myprovider" "test@myprovider"
@ -32,6 +33,7 @@
"serverStatus": { "serverStatus": {
"http://127.0.0.2": "UP" "http://127.0.0.2": "UP"
}, },
"status": "enabled",
"usedBy": [ "usedBy": [
"foo@myprovider" "foo@myprovider"
] ]

View file

@ -1,4 +1,4 @@
package dynamic package runtime
import ( import (
"context" "context"
@ -6,11 +6,19 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/log" "github.com/containous/traefik/pkg/log"
) )
// RuntimeConfiguration holds the information about the currently running traefik instance. // Status of the router/service
type RuntimeConfiguration struct { const (
StatusEnabled = "enabled"
StatusDisabled = "disabled"
StatusWarning = "warning"
)
// Configuration holds the information about the currently running traefik instance.
type Configuration struct {
Routers map[string]*RouterInfo `json:"routers,omitempty"` Routers map[string]*RouterInfo `json:"routers,omitempty"`
Middlewares map[string]*MiddlewareInfo `json:"middlewares,omitempty"` Middlewares map[string]*MiddlewareInfo `json:"middlewares,omitempty"`
Services map[string]*ServiceInfo `json:"services,omitempty"` Services map[string]*ServiceInfo `json:"services,omitempty"`
@ -18,20 +26,20 @@ type RuntimeConfiguration struct {
TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"` TCPServices map[string]*TCPServiceInfo `json:"tcpServices,omitempty"`
} }
// NewRuntimeConfig returns a RuntimeConfiguration initialized with the given conf. It never returns nil. // NewConfig returns a Configuration initialized with the given conf. It never returns nil.
func NewRuntimeConfig(conf Configuration) *RuntimeConfiguration { func NewConfig(conf dynamic.Configuration) *Configuration {
if conf.HTTP == nil && conf.TCP == nil { if conf.HTTP == nil && conf.TCP == nil {
return &RuntimeConfiguration{} return &Configuration{}
} }
runtimeConfig := &RuntimeConfiguration{} runtimeConfig := &Configuration{}
if conf.HTTP != nil { if conf.HTTP != nil {
routers := conf.HTTP.Routers routers := conf.HTTP.Routers
if len(routers) > 0 { if len(routers) > 0 {
runtimeConfig.Routers = make(map[string]*RouterInfo, len(routers)) runtimeConfig.Routers = make(map[string]*RouterInfo, len(routers))
for k, v := range routers { for k, v := range routers {
runtimeConfig.Routers[k] = &RouterInfo{Router: v} runtimeConfig.Routers[k] = &RouterInfo{Router: v, Status: StatusEnabled}
} }
} }
@ -39,7 +47,7 @@ func NewRuntimeConfig(conf Configuration) *RuntimeConfiguration {
if len(services) > 0 { if len(services) > 0 {
runtimeConfig.Services = make(map[string]*ServiceInfo, len(services)) runtimeConfig.Services = make(map[string]*ServiceInfo, len(services))
for k, v := range services { for k, v := range services {
runtimeConfig.Services[k] = &ServiceInfo{Service: v} runtimeConfig.Services[k] = &ServiceInfo{Service: v, Status: StatusEnabled}
} }
} }
@ -56,14 +64,14 @@ func NewRuntimeConfig(conf Configuration) *RuntimeConfiguration {
if len(conf.TCP.Routers) > 0 { if len(conf.TCP.Routers) > 0 {
runtimeConfig.TCPRouters = make(map[string]*TCPRouterInfo, len(conf.TCP.Routers)) runtimeConfig.TCPRouters = make(map[string]*TCPRouterInfo, len(conf.TCP.Routers))
for k, v := range conf.TCP.Routers { for k, v := range conf.TCP.Routers {
runtimeConfig.TCPRouters[k] = &TCPRouterInfo{TCPRouter: v} runtimeConfig.TCPRouters[k] = &TCPRouterInfo{TCPRouter: v, Status: StatusEnabled}
} }
} }
if len(conf.TCP.Services) > 0 { if len(conf.TCP.Services) > 0 {
runtimeConfig.TCPServices = make(map[string]*TCPServiceInfo, len(conf.TCP.Services)) runtimeConfig.TCPServices = make(map[string]*TCPServiceInfo, len(conf.TCP.Services))
for k, v := range conf.TCP.Services { for k, v := range conf.TCP.Services {
runtimeConfig.TCPServices[k] = &TCPServiceInfo{TCPService: v} runtimeConfig.TCPServices[k] = &TCPServiceInfo{TCPService: v, Status: StatusEnabled}
} }
} }
} }
@ -73,7 +81,7 @@ func NewRuntimeConfig(conf Configuration) *RuntimeConfiguration {
// PopulateUsedBy populates all the UsedBy lists of the underlying fields of r, // PopulateUsedBy populates all the UsedBy lists of the underlying fields of r,
// based on the relations between the included services, routers, and middlewares. // based on the relations between the included services, routers, and middlewares.
func (r *RuntimeConfiguration) PopulateUsedBy() { func (r *Configuration) PopulateUsedBy() {
if r == nil { if r == nil {
return return
} }
@ -81,6 +89,11 @@ func (r *RuntimeConfiguration) PopulateUsedBy() {
logger := log.WithoutContext() logger := log.WithoutContext()
for routerName, routerInfo := range r.Routers { for routerName, routerInfo := range r.Routers {
// lazily initialize Status in case caller forgot to do it
if routerInfo.Status == "" {
routerInfo.Status = StatusEnabled
}
providerName := getProviderName(routerName) providerName := getProviderName(routerName)
if providerName == "" { if providerName == "" {
logger.WithField(log.RouterName, routerName).Error("router name is not fully qualified") logger.WithField(log.RouterName, routerName).Error("router name is not fully qualified")
@ -102,7 +115,12 @@ func (r *RuntimeConfiguration) PopulateUsedBy() {
r.Services[serviceName].UsedBy = append(r.Services[serviceName].UsedBy, routerName) r.Services[serviceName].UsedBy = append(r.Services[serviceName].UsedBy, routerName)
} }
for k := range r.Services { for k, serviceInfo := range r.Services {
// lazily initialize Status in case caller forgot to do it
if serviceInfo.Status == "" {
serviceInfo.Status = StatusEnabled
}
sort.Strings(r.Services[k].UsedBy) sort.Strings(r.Services[k].UsedBy)
} }
@ -111,6 +129,11 @@ func (r *RuntimeConfiguration) PopulateUsedBy() {
} }
for routerName, routerInfo := range r.TCPRouters { for routerName, routerInfo := range r.TCPRouters {
// lazily initialize Status in case caller forgot to do it
if routerInfo.Status == "" {
routerInfo.Status = StatusEnabled
}
providerName := getProviderName(routerName) providerName := getProviderName(routerName)
if providerName == "" { if providerName == "" {
logger.WithField(log.RouterName, routerName).Error("tcp router name is not fully qualified") logger.WithField(log.RouterName, routerName).Error("tcp router name is not fully qualified")
@ -124,7 +147,12 @@ func (r *RuntimeConfiguration) PopulateUsedBy() {
r.TCPServices[serviceName].UsedBy = append(r.TCPServices[serviceName].UsedBy, routerName) r.TCPServices[serviceName].UsedBy = append(r.TCPServices[serviceName].UsedBy, routerName)
} }
for k := range r.TCPServices { for k, serviceInfo := range r.TCPServices {
// lazily initialize Status in case caller forgot to do it
if serviceInfo.Status == "" {
serviceInfo.Status = StatusEnabled
}
sort.Strings(r.TCPServices[k].UsedBy) sort.Strings(r.TCPServices[k].UsedBy)
} }
} }
@ -138,8 +166,8 @@ func contains(entryPoints []string, entryPointName string) bool {
return false return false
} }
// GetRoutersByEntrypoints returns all the http routers by entrypoints name and routers name // GetRoutersByEntryPoints returns all the http routers by entry points name and routers name
func (r *RuntimeConfiguration) GetRoutersByEntrypoints(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*RouterInfo { func (r *Configuration) GetRoutersByEntryPoints(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*RouterInfo {
entryPointsRouters := make(map[string]map[string]*RouterInfo) entryPointsRouters := make(map[string]map[string]*RouterInfo)
for rtName, rt := range r.Routers { for rtName, rt := range r.Routers {
@ -169,8 +197,8 @@ func (r *RuntimeConfiguration) GetRoutersByEntrypoints(ctx context.Context, entr
return entryPointsRouters return entryPointsRouters
} }
// GetTCPRoutersByEntrypoints returns all the tcp routers by entrypoints name and routers name // GetTCPRoutersByEntryPoints returns all the tcp routers by entry points name and routers name
func (r *RuntimeConfiguration) GetTCPRoutersByEntrypoints(ctx context.Context, entryPoints []string) map[string]map[string]*TCPRouterInfo { func (r *Configuration) GetTCPRoutersByEntryPoints(ctx context.Context, entryPoints []string) map[string]map[string]*TCPRouterInfo {
entryPointsRouters := make(map[string]map[string]*TCPRouterInfo) entryPointsRouters := make(map[string]map[string]*TCPRouterInfo)
for rtName, rt := range r.TCPRouters { for rtName, rt := range r.TCPRouters {
@ -199,57 +227,126 @@ func (r *RuntimeConfiguration) GetTCPRoutersByEntrypoints(ctx context.Context, e
// RouterInfo holds information about a currently running HTTP router // RouterInfo holds information about a currently running HTTP router
type RouterInfo struct { type RouterInfo struct {
*Router // dynamic configuration *dynamic.Router // dynamic configuration
Err string `json:"error,omitempty"` // initialization error // Err contains all the errors that occurred during router's creation.
Err []string `json:"error,omitempty"`
// Status reports whether the router is disabled, in a warning state, or all good (enabled).
// If not in "enabled" state, the reason for it should be in the list of Err.
// It is the caller's responsibility to set the initial status.
Status string `json:"status,omitempty"`
}
// AddError adds err to r.Err, if it does not already exist.
// If critical is set, r is marked as disabled.
func (r *RouterInfo) AddError(err error, critical bool) {
for _, value := range r.Err {
if value == err.Error() {
return
}
}
r.Err = append(r.Err, err.Error())
if critical {
r.Status = StatusDisabled
return
}
// only set it to "warning" if not already in a worse state
if r.Status != StatusDisabled {
r.Status = StatusWarning
}
} }
// TCPRouterInfo holds information about a currently running TCP router // TCPRouterInfo holds information about a currently running TCP router
type TCPRouterInfo struct { type TCPRouterInfo struct {
*TCPRouter // dynamic configuration *dynamic.TCPRouter // dynamic configuration
Err string `json:"error,omitempty"` // initialization error Err string `json:"error,omitempty"` // initialization error
// Status reports whether the router is disabled, in a warning state, or all good (enabled).
// If not in "enabled" state, the reason for it should be in the list of Err.
// It is the caller's responsibility to set the initial status.
Status string `json:"status,omitempty"`
} }
// MiddlewareInfo holds information about a currently running middleware // MiddlewareInfo holds information about a currently running middleware
type MiddlewareInfo struct { type MiddlewareInfo struct {
*Middleware // dynamic configuration *dynamic.Middleware // dynamic configuration
Err error `json:"error,omitempty"` // initialization error // Err contains all the errors that occurred during service creation.
UsedBy []string `json:"usedBy,omitempty"` // list of routers and services using that middleware Err []string `json:"error,omitempty"`
UsedBy []string `json:"usedBy,omitempty"` // list of routers and services using that middleware
}
// AddError adds err to s.Err, if it does not already exist.
// If critical is set, m is marked as disabled.
func (m *MiddlewareInfo) AddError(err error) {
for _, value := range m.Err {
if value == err.Error() {
return
}
}
m.Err = append(m.Err, err.Error())
} }
// ServiceInfo holds information about a currently running service // ServiceInfo holds information about a currently running service
type ServiceInfo struct { type ServiceInfo struct {
*Service // dynamic configuration *dynamic.Service // dynamic configuration
Err error `json:"error,omitempty"` // initialization error // Err contains all the errors that occurred during service creation.
UsedBy []string `json:"usedBy,omitempty"` // list of routers using that service Err []string `json:"error,omitempty"`
// Status reports whether the service is disabled, in a warning state, or all good (enabled).
// If not in "enabled" state, the reason for it should be in the list of Err.
// It is the caller's responsibility to set the initial status.
Status string `json:"status,omitempty"`
UsedBy []string `json:"usedBy,omitempty"` // list of routers using that service
statusMu sync.RWMutex serverStatusMu sync.RWMutex
status map[string]string // keyed by server URL serverStatus map[string]string // keyed by server URL
} }
// UpdateStatus sets the status of the server in the ServiceInfo. // AddError adds err to s.Err, if it does not already exist.
// It is the responsibility of the caller to check that s is not nil. // If critical is set, s is marked as disabled.
func (s *ServiceInfo) UpdateStatus(server string, status string) { func (s *ServiceInfo) AddError(err error, critical bool) {
s.statusMu.Lock() for _, value := range s.Err {
defer s.statusMu.Unlock() if value == err.Error() {
return
if s.status == nil { }
s.status = make(map[string]string)
} }
s.status[server] = status
s.Err = append(s.Err, err.Error())
if critical {
s.Status = StatusDisabled
return
}
// only set it to "warning" if not already in a worse state
if s.Status != StatusDisabled {
s.Status = StatusWarning
}
}
// UpdateServerStatus sets the status of the server in the ServiceInfo.
// It is the responsibility of the caller to check that s is not nil.
func (s *ServiceInfo) UpdateServerStatus(server string, status string) {
s.serverStatusMu.Lock()
defer s.serverStatusMu.Unlock()
if s.serverStatus == nil {
s.serverStatus = make(map[string]string)
}
s.serverStatus[server] = status
} }
// GetAllStatus returns all the statuses of all the servers in ServiceInfo. // GetAllStatus returns all the statuses of all the servers in ServiceInfo.
// It is the responsibility of the caller to check that s is not nil // It is the responsibility of the caller to check that s is not nil
func (s *ServiceInfo) GetAllStatus() map[string]string { func (s *ServiceInfo) GetAllStatus() map[string]string {
s.statusMu.RLock() s.serverStatusMu.RLock()
defer s.statusMu.RUnlock() defer s.serverStatusMu.RUnlock()
if len(s.status) == 0 { if len(s.serverStatus) == 0 {
return nil return nil
} }
allStatus := make(map[string]string, len(s.status)) allStatus := make(map[string]string, len(s.serverStatus))
for k, v := range s.status { for k, v := range s.serverStatus {
allStatus[k] = v allStatus[k] = v
} }
return allStatus return allStatus
@ -257,9 +354,13 @@ func (s *ServiceInfo) GetAllStatus() map[string]string {
// TCPServiceInfo holds information about a currently running TCP service // TCPServiceInfo holds information about a currently running TCP service
type TCPServiceInfo struct { type TCPServiceInfo struct {
*TCPService // dynamic configuration *dynamic.TCPService // dynamic configuration
Err error `json:"error,omitempty"` // initialization error Err error `json:"error,omitempty"` // initialization error
UsedBy []string `json:"usedBy,omitempty"` // list of routers using that service // Status reports whether the service is disabled, in a warning state, or all good (enabled).
// If not in "enabled" state, the reason for it should be in the list of Err.
// It is the caller's responsibility to set the initial status.
Status string `json:"status,omitempty"`
UsedBy []string `json:"usedBy,omitempty"` // list of routers using that service
} }
func getProviderName(elementName string) string { func getProviderName(elementName string) string {

View file

@ -1,30 +1,31 @@
package dynamic_test package runtime_test
import ( import (
"context" "context"
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
// all the Routers/Middlewares/Services are considered fully qualified // all the Routers/Middlewares/Services are considered fully qualified
func TestPopulateUsedby(t *testing.T) { func TestPopulateUsedBy(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
conf *dynamic.RuntimeConfiguration conf *runtime.Configuration
expected dynamic.RuntimeConfiguration expected runtime.Configuration
}{ }{
{ {
desc: "nil config", desc: "nil config",
conf: nil, conf: nil,
expected: dynamic.RuntimeConfiguration{}, expected: runtime.Configuration{},
}, },
{ {
desc: "One service used by two routers", desc: "One service used by two routers",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"foo@myprovider": { "foo@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -40,7 +41,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -57,12 +58,12 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"foo@myprovider": {}, "foo@myprovider": {},
"bar@myprovider": {}, "bar@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider", "foo@myprovider"}, UsedBy: []string{"bar@myprovider", "foo@myprovider"},
}, },
@ -71,8 +72,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "One service used by two routers, but one router with wrong rule", desc: "One service used by two routers, but one router with wrong rule",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -83,7 +84,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"foo@myprovider": { "foo@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -100,12 +101,12 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"foo@myprovider": {}, "foo@myprovider": {},
"bar@myprovider": {}, "bar@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider", "foo@myprovider"}, UsedBy: []string{"bar@myprovider", "foo@myprovider"},
}, },
@ -114,15 +115,15 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "Broken Service used by one Router", desc: "Broken Service used by one Router",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: nil, LoadBalancer: nil,
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -132,11 +133,11 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider"}, UsedBy: []string{"bar@myprovider"},
}, },
@ -145,8 +146,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "2 different Services each used by a disctinct router.", desc: "2 different Services each used by a disctinct router.",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -184,7 +185,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"foo@myprovider": { "foo@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -201,12 +202,12 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
"foo@myprovider": {}, "foo@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"foo@myprovider"}, UsedBy: []string{"foo@myprovider"},
}, },
@ -218,8 +219,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "2 middlewares both used by 2 Routers", desc: "2 middlewares both used by 2 Routers",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -232,7 +233,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -248,7 +249,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -267,17 +268,17 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
"test@myprovider": {}, "test@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider", "test@myprovider"}, UsedBy: []string{"bar@myprovider", "test@myprovider"},
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
UsedBy: []string{"bar@myprovider", "test@myprovider"}, UsedBy: []string{"bar@myprovider", "test@myprovider"},
}, },
@ -289,8 +290,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "Unknown middleware is not used by the Router", desc: "Unknown middleware is not used by the Router",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -303,7 +304,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -312,7 +313,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -323,8 +324,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider"}, UsedBy: []string{"bar@myprovider"},
}, },
@ -333,8 +334,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "Broken middleware is used by Router", desc: "Broken middleware is used by Router",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -347,7 +348,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -356,7 +357,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -367,16 +368,16 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider"}, UsedBy: []string{"bar@myprovider"},
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
UsedBy: []string{"bar@myprovider"}, UsedBy: []string{"bar@myprovider"},
}, },
@ -385,8 +386,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "2 middlewares from 2 disctinct providers both used by 2 Routers", desc: "2 middlewares from 2 disctinct providers both used by 2 Routers",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{ LoadBalancer: &dynamic.LoadBalancerService{
@ -399,7 +400,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
Middleware: &dynamic.Middleware{ Middleware: &dynamic.Middleware{
BasicAuth: &dynamic.BasicAuth{ BasicAuth: &dynamic.BasicAuth{
@ -422,7 +423,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": { "bar@myprovider": {
Router: &dynamic.Router{ Router: &dynamic.Router{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -441,17 +442,17 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
Routers: map[string]*dynamic.RouterInfo{ Routers: map[string]*runtime.RouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
"test@myprovider": {}, "test@myprovider": {},
}, },
Services: map[string]*dynamic.ServiceInfo{ Services: map[string]*runtime.ServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider", "test@myprovider"}, UsedBy: []string{"bar@myprovider", "test@myprovider"},
}, },
}, },
Middlewares: map[string]*dynamic.MiddlewareInfo{ Middlewares: map[string]*runtime.MiddlewareInfo{
"auth@myprovider": { "auth@myprovider": {
UsedBy: []string{"bar@myprovider", "test@myprovider"}, UsedBy: []string{"bar@myprovider", "test@myprovider"},
}, },
@ -468,8 +469,8 @@ func TestPopulateUsedby(t *testing.T) {
// TCP tests from hereon // TCP tests from hereon
{ {
desc: "TCP, One service used by two routers", desc: "TCP, One service used by two routers",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"foo@myprovider": { "foo@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -485,7 +486,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -504,12 +505,12 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"foo@myprovider": {}, "foo@myprovider": {},
"bar@myprovider": {}, "bar@myprovider": {},
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider", "foo@myprovider"}, UsedBy: []string{"bar@myprovider", "foo@myprovider"},
}, },
@ -518,8 +519,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "TCP, One service used by two routers, but one router with wrong rule", desc: "TCP, One service used by two routers, but one router with wrong rule",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -532,7 +533,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"foo@myprovider": { "foo@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -549,12 +550,12 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"foo@myprovider": {}, "foo@myprovider": {},
"bar@myprovider": {}, "bar@myprovider": {},
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider", "foo@myprovider"}, UsedBy: []string{"bar@myprovider", "foo@myprovider"},
}, },
@ -563,15 +564,15 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "TCP, Broken Service used by one Router", desc: "TCP, Broken Service used by one Router",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: nil, LoadBalancer: nil,
}, },
}, },
}, },
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"bar@myprovider": { "bar@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -581,11 +582,11 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"bar@myprovider"}, UsedBy: []string{"bar@myprovider"},
}, },
@ -594,8 +595,8 @@ func TestPopulateUsedby(t *testing.T) {
}, },
{ {
desc: "TCP, 2 different Services each used by a disctinct router.", desc: "TCP, 2 different Services each used by a disctinct router.",
conf: &dynamic.RuntimeConfiguration{ conf: &runtime.Configuration{
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -629,7 +630,7 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"foo@myprovider": { "foo@myprovider": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -646,12 +647,12 @@ func TestPopulateUsedby(t *testing.T) {
}, },
}, },
}, },
expected: dynamic.RuntimeConfiguration{ expected: runtime.Configuration{
TCPRouters: map[string]*dynamic.TCPRouterInfo{ TCPRouters: map[string]*runtime.TCPRouterInfo{
"bar@myprovider": {}, "bar@myprovider": {},
"foo@myprovider": {}, "foo@myprovider": {},
}, },
TCPServices: map[string]*dynamic.TCPServiceInfo{ TCPServices: map[string]*runtime.TCPServiceInfo{
"foo-service@myprovider": { "foo-service@myprovider": {
UsedBy: []string{"foo@myprovider"}, UsedBy: []string{"foo@myprovider"},
}, },
@ -690,24 +691,24 @@ func TestPopulateUsedby(t *testing.T) {
} }
func TestGetTCPRoutersByEntrypoints(t *testing.T) { func TestGetTCPRoutersByEntryPoints(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
conf dynamic.Configuration conf dynamic.Configuration
entryPoints []string entryPoints []string
expected map[string]map[string]*dynamic.TCPRouterInfo expected map[string]map[string]*runtime.TCPRouterInfo
}{ }{
{ {
desc: "Empty Configuration without entrypoint", desc: "Empty Configuration without entrypoint",
conf: dynamic.Configuration{}, conf: dynamic.Configuration{},
entryPoints: []string{""}, entryPoints: []string{""},
expected: map[string]map[string]*dynamic.TCPRouterInfo{}, expected: map[string]map[string]*runtime.TCPRouterInfo{},
}, },
{ {
desc: "Empty Configuration with unknown entrypoints", desc: "Empty Configuration with unknown entrypoints",
conf: dynamic.Configuration{}, conf: dynamic.Configuration{},
entryPoints: []string{"foo"}, entryPoints: []string{"foo"},
expected: map[string]map[string]*dynamic.TCPRouterInfo{}, expected: map[string]map[string]*runtime.TCPRouterInfo{},
}, },
{ {
desc: "Valid configuration with an unknown entrypoint", desc: "Valid configuration with an unknown entrypoint",
@ -732,7 +733,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
}, },
}, },
entryPoints: []string{"foo"}, entryPoints: []string{"foo"},
expected: map[string]map[string]*dynamic.TCPRouterInfo{}, expected: map[string]map[string]*runtime.TCPRouterInfo{},
}, },
{ {
desc: "Valid configuration with a known entrypoint", desc: "Valid configuration with a known entrypoint",
@ -777,7 +778,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
}, },
}, },
entryPoints: []string{"web"}, entryPoints: []string{"web"},
expected: map[string]map[string]*dynamic.TCPRouterInfo{ expected: map[string]map[string]*runtime.TCPRouterInfo{
"web": { "web": {
"foo": { "foo": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
@ -785,6 +786,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
Service: "foo-service@myprovider", Service: "foo-service@myprovider",
Rule: "HostSNI(`bar.foo`)", Rule: "HostSNI(`bar.foo`)",
}, },
Status: "enabled",
}, },
"foobar": { "foobar": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
@ -792,6 +794,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
Service: "foobar-service@myprovider", Service: "foobar-service@myprovider",
Rule: "HostSNI(`bar.foobar`)", Rule: "HostSNI(`bar.foobar`)",
}, },
Status: "enabled",
}, },
}, },
}, },
@ -839,7 +842,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
}, },
}, },
entryPoints: []string{"web", "webs"}, entryPoints: []string{"web", "webs"},
expected: map[string]map[string]*dynamic.TCPRouterInfo{ expected: map[string]map[string]*runtime.TCPRouterInfo{
"web": { "web": {
"foo": { "foo": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
@ -847,6 +850,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
Service: "foo-service@myprovider", Service: "foo-service@myprovider",
Rule: "HostSNI(`bar.foo`)", Rule: "HostSNI(`bar.foo`)",
}, },
Status: "enabled",
}, },
"foobar": { "foobar": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
@ -854,6 +858,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
Service: "foobar-service@myprovider", Service: "foobar-service@myprovider",
Rule: "HostSNI(`bar.foobar`)", Rule: "HostSNI(`bar.foobar`)",
}, },
Status: "enabled",
}, },
}, },
"webs": { "webs": {
@ -864,6 +869,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
Service: "bar-service@myprovider", Service: "bar-service@myprovider",
Rule: "HostSNI(`foo.bar`)", Rule: "HostSNI(`foo.bar`)",
}, },
Status: "enabled",
}, },
"foobar": { "foobar": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
@ -871,6 +877,7 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
Service: "foobar-service@myprovider", Service: "foobar-service@myprovider",
Rule: "HostSNI(`bar.foobar`)", Rule: "HostSNI(`bar.foobar`)",
}, },
Status: "enabled",
}, },
}, },
}, },
@ -881,31 +888,31 @@ func TestGetTCPRoutersByEntrypoints(t *testing.T) {
test := test test := test
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
runtimeConfig := dynamic.NewRuntimeConfig(test.conf) runtimeConfig := runtime.NewConfig(test.conf)
actual := runtimeConfig.GetTCPRoutersByEntrypoints(context.Background(), test.entryPoints) actual := runtimeConfig.GetTCPRoutersByEntryPoints(context.Background(), test.entryPoints)
assert.Equal(t, test.expected, actual) assert.Equal(t, test.expected, actual)
}) })
} }
} }
func TestGetRoutersByEntrypoints(t *testing.T) { func TestGetRoutersByEntryPoints(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
conf dynamic.Configuration conf dynamic.Configuration
entryPoints []string entryPoints []string
expected map[string]map[string]*dynamic.RouterInfo expected map[string]map[string]*runtime.RouterInfo
}{ }{
{ {
desc: "Empty Configuration without entrypoint", desc: "Empty Configuration without entrypoint",
conf: dynamic.Configuration{}, conf: dynamic.Configuration{},
entryPoints: []string{""}, entryPoints: []string{""},
expected: map[string]map[string]*dynamic.RouterInfo{}, expected: map[string]map[string]*runtime.RouterInfo{},
}, },
{ {
desc: "Empty Configuration with unknown entrypoints", desc: "Empty Configuration with unknown entrypoints",
conf: dynamic.Configuration{}, conf: dynamic.Configuration{},
entryPoints: []string{"foo"}, entryPoints: []string{"foo"},
expected: map[string]map[string]*dynamic.RouterInfo{}, expected: map[string]map[string]*runtime.RouterInfo{},
}, },
{ {
desc: "Valid configuration with an unknown entrypoint", desc: "Valid configuration with an unknown entrypoint",
@ -930,7 +937,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
}, },
}, },
entryPoints: []string{"foo"}, entryPoints: []string{"foo"},
expected: map[string]map[string]*dynamic.RouterInfo{}, expected: map[string]map[string]*runtime.RouterInfo{},
}, },
{ {
desc: "Valid configuration with a known entrypoint", desc: "Valid configuration with a known entrypoint",
@ -975,7 +982,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
}, },
}, },
entryPoints: []string{"web"}, entryPoints: []string{"web"},
expected: map[string]map[string]*dynamic.RouterInfo{ expected: map[string]map[string]*runtime.RouterInfo{
"web": { "web": {
"foo": { "foo": {
Router: &dynamic.Router{ Router: &dynamic.Router{
@ -983,6 +990,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
Service: "foo-service@myprovider", Service: "foo-service@myprovider",
Rule: "Host(`bar.foo`)", Rule: "Host(`bar.foo`)",
}, },
Status: "enabled",
}, },
"foobar": { "foobar": {
Router: &dynamic.Router{ Router: &dynamic.Router{
@ -990,6 +998,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
Service: "foobar-service@myprovider", Service: "foobar-service@myprovider",
Rule: "Host(`bar.foobar`)", Rule: "Host(`bar.foobar`)",
}, },
Status: "enabled",
}, },
}, },
}, },
@ -1037,7 +1046,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
}, },
}, },
entryPoints: []string{"web", "webs"}, entryPoints: []string{"web", "webs"},
expected: map[string]map[string]*dynamic.RouterInfo{ expected: map[string]map[string]*runtime.RouterInfo{
"web": { "web": {
"foo": { "foo": {
Router: &dynamic.Router{ Router: &dynamic.Router{
@ -1045,6 +1054,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
Service: "foo-service@myprovider", Service: "foo-service@myprovider",
Rule: "Host(`bar.foo`)", Rule: "Host(`bar.foo`)",
}, },
Status: "enabled",
}, },
"foobar": { "foobar": {
Router: &dynamic.Router{ Router: &dynamic.Router{
@ -1052,6 +1062,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
Service: "foobar-service@myprovider", Service: "foobar-service@myprovider",
Rule: "Host(`bar.foobar`)", Rule: "Host(`bar.foobar`)",
}, },
Status: "enabled",
}, },
}, },
"webs": { "webs": {
@ -1062,6 +1073,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
Service: "bar-service@myprovider", Service: "bar-service@myprovider",
Rule: "Host(`foo.bar`)", Rule: "Host(`foo.bar`)",
}, },
Status: "enabled",
}, },
"foobar": { "foobar": {
Router: &dynamic.Router{ Router: &dynamic.Router{
@ -1069,6 +1081,7 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
Service: "foobar-service@myprovider", Service: "foobar-service@myprovider",
Rule: "Host(`bar.foobar`)", Rule: "Host(`bar.foobar`)",
}, },
Status: "enabled",
}, },
}, },
}, },
@ -1079,8 +1092,8 @@ func TestGetRoutersByEntrypoints(t *testing.T) {
test := test test := test
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {
t.Parallel() t.Parallel()
runtimeConfig := dynamic.NewRuntimeConfig(test.conf) runtimeConfig := runtime.NewConfig(test.conf)
actual := runtimeConfig.GetRoutersByEntrypoints(context.Background(), test.entryPoints, false) actual := runtimeConfig.GetRoutersByEntryPoints(context.Background(), test.entryPoints, false)
assert.Equal(t, test.expected, actual) assert.Equal(t, test.expected, actual)
}) })
} }

View file

@ -10,7 +10,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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 *dynamic.ServiceInfo) *LbStatusUpdater { func NewLBStatusUpdater(bh BalancerHandler, svinfo *runtime.ServiceInfo) *LbStatusUpdater {
return &LbStatusUpdater{ return &LbStatusUpdater{
BalancerHandler: bh, BalancerHandler: bh,
serviceInfo: svinfo, serviceInfo: svinfo,
@ -240,7 +240,7 @@ func NewLBStatusUpdater(bh BalancerHandler, svinfo *dynamic.ServiceInfo) *LbStat
// 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 *dynamic.ServiceInfo // can be nil serviceInfo *runtime.ServiceInfo // can be nil
} }
// RemoveServer removes the given server from the BalancerHandler, // RemoveServer removes the given server from the BalancerHandler,
@ -248,7 +248,7 @@ type LbStatusUpdater struct {
func (lb *LbStatusUpdater) RemoveServer(u *url.URL) error { func (lb *LbStatusUpdater) RemoveServer(u *url.URL) error {
err := lb.BalancerHandler.RemoveServer(u) err := lb.BalancerHandler.RemoveServer(u)
if err == nil && lb.serviceInfo != nil { if err == nil && lb.serviceInfo != nil {
lb.serviceInfo.UpdateStatus(u.String(), serverDown) lb.serviceInfo.UpdateServerStatus(u.String(), serverDown)
} }
return err return err
} }
@ -258,7 +258,7 @@ func (lb *LbStatusUpdater) RemoveServer(u *url.URL) error {
func (lb *LbStatusUpdater) UpsertServer(u *url.URL, options ...roundrobin.ServerOption) error { func (lb *LbStatusUpdater) UpsertServer(u *url.URL, options ...roundrobin.ServerOption) error {
err := lb.BalancerHandler.UpsertServer(u, options...) err := lb.BalancerHandler.UpsertServer(u, options...)
if err == nil && lb.serviceInfo != nil { if err == nil && lb.serviceInfo != nil {
lb.serviceInfo.UpdateStatus(u.String(), serverUp) lb.serviceInfo.UpdateServerStatus(u.String(), serverUp)
} }
return err return err
} }

View file

@ -9,7 +9,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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 := &dynamic.ServiceInfo{} svInfo := &runtime.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)

View file

@ -4,17 +4,17 @@ import (
"context" "context"
"net/http" "net/http"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
) )
// NewBuilder creates a builder. // NewBuilder creates a builder.
func NewBuilder(configs map[string]*dynamic.MiddlewareInfo) *Builder { func NewBuilder(configs map[string]*runtime.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]*dynamic.MiddlewareInfo configs map[string]*runtime.MiddlewareInfo
} }
// Build Builds the response modifier. // Build Builds the response modifier.

View file

@ -7,6 +7,7 @@ import (
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -166,7 +167,7 @@ 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 := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Middlewares: test.conf, Middlewares: test.conf,
}, },

View file

@ -8,7 +8,7 @@ import (
"strings" "strings"
"github.com/containous/alice" "github.com/containous/alice"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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]*dynamic.MiddlewareInfo configs map[string]*runtime.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]*dynamic.MiddlewareInfo, serviceBuilder serviceBuilder) *Builder { func NewBuilder(configs map[string]*runtime.MiddlewareInfo, serviceBuilder serviceBuilder) *Builder {
return &Builder{configs: configs, serviceBuilder: serviceBuilder} return &Builder{configs: configs, serviceBuilder: serviceBuilder}
} }
@ -66,19 +66,19 @@ func (b *Builder) BuildChain(ctx context.Context, middlewares []string) *alice.C
var err error var err error
if constructorContext, err = checkRecursion(constructorContext, middlewareName); err != nil { if constructorContext, err = checkRecursion(constructorContext, middlewareName); err != nil {
b.configs[middlewareName].Err = err b.configs[middlewareName].AddError(err)
return nil, err return nil, err
} }
constructor, err := b.buildConstructor(constructorContext, middlewareName) constructor, err := b.buildConstructor(constructorContext, middlewareName)
if err != nil { if err != nil {
b.configs[middlewareName].Err = err b.configs[middlewareName].AddError(err)
return nil, err return nil, err
} }
handler, err := constructor(next) handler, err := constructor(next)
if err != nil { if err != nil {
b.configs[middlewareName].Err = err b.configs[middlewareName].AddError(err)
return nil, err return nil, err
} }

View file

@ -8,13 +8,14 @@ import (
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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]*dynamic.MiddlewareInfo{ testConfig := map[string]*runtime.MiddlewareInfo{
"empty": {}, "empty": {},
} }
middlewaresBuilder := NewBuilder(testConfig, nil) middlewaresBuilder := NewBuilder(testConfig, nil)
@ -25,7 +26,7 @@ func TestBuilder_BuildChainNilConfig(t *testing.T) {
} }
func TestBuilder_BuildChainNonExistentChain(t *testing.T) { func TestBuilder_BuildChainNonExistentChain(t *testing.T) {
testConfig := map[string]*dynamic.MiddlewareInfo{ testConfig := map[string]*runtime.MiddlewareInfo{
"foobar": {}, "foobar": {},
} }
middlewaresBuilder := NewBuilder(testConfig, nil) middlewaresBuilder := NewBuilder(testConfig, nil)
@ -264,7 +265,7 @@ func TestBuilder_BuildChainWithContext(t *testing.T) {
ctx = internal.AddProviderInContext(ctx, "foobar@"+test.contextProvider) ctx = internal.AddProviderInContext(ctx, "foobar@"+test.contextProvider)
} }
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Middlewares: test.configuration, Middlewares: test.configuration,
}, },
@ -315,7 +316,7 @@ func TestBuilder_buildConstructor(t *testing.T) {
}, },
} }
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Middlewares: testConfig, Middlewares: testConfig,
}, },

View file

@ -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/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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 *dynamic.RuntimeConfiguration) *RouteAppenderAggregator { entryPointName string, runtimeConfiguration *runtime.Configuration) *RouteAppenderAggregator {
aggregator := &RouteAppenderAggregator{} aggregator := &RouteAppenderAggregator{}
if conf.Providers != nil && conf.Providers.Rest != nil { if conf.Providers != nil && conf.Providers.Rest != nil {

View file

@ -3,7 +3,7 @@ package router
import ( import (
"context" "context"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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 *dynamic.RuntimeConfiguration) types.RouteAppender { func (r *RouteAppenderFactory) NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *runtime.Configuration) 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 {

View file

@ -5,7 +5,7 @@ import (
"net/http" "net/http"
"github.com/containous/alice" "github.com/containous/alice"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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 *dynamic.RuntimeConfiguration, func NewManager(conf *runtime.Configuration,
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 *dynamic.RuntimeConfiguration conf *runtime.Configuration
} }
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*dynamic.RouterInfo { func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*runtime.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]*dynamic.RouterInfo) return make(map[string]map[string]*runtime.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]*dynamic.RouterInfo) (http.Handler, error) { func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*runtime.RouterInfo) (http.Handler, error) {
router, err := rules.NewRouter() router, err := rules.NewRouter()
if err != nil { if err != nil {
return nil, err return nil, err
@ -95,14 +95,14 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
handler, err := m.buildRouterHandler(ctxRouter, routerName, routerConfig) handler, err := m.buildRouterHandler(ctxRouter, routerName, routerConfig)
if err != nil { if err != nil {
routerConfig.Err = err.Error() routerConfig.AddError(err, true)
logger.Error(err) logger.Error(err)
continue continue
} }
err = router.AddRoute(routerConfig.Rule, routerConfig.Priority, handler) err = router.AddRoute(routerConfig.Rule, routerConfig.Priority, handler)
if err != nil { if err != nil {
routerConfig.Err = err.Error() routerConfig.AddError(err, true)
logger.Error(err) logger.Error(err)
continue continue
} }
@ -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 *dynamic.RouterInfo) (http.Handler, error) { func (m *Manager) buildRouterHandler(ctx context.Context, routerName string, routerConfig *runtime.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 *dynamic.RouterInfo, routerName string) (http.Handler, error) { func (m *Manager) buildHTTPHandler(ctx context.Context, router *runtime.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)

View file

@ -9,6 +9,7 @@ import (
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -298,7 +299,7 @@ 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 := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Services: test.serviceConfig, Services: test.serviceConfig,
Routers: test.routersConfig, Routers: test.routersConfig,
@ -399,7 +400,7 @@ 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 := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Services: test.serviceConfig, Services: test.serviceConfig,
Routers: test.routersConfig, Routers: test.routersConfig,
@ -685,7 +686,7 @@ func TestRuntimeConfiguration(t *testing.T) {
entryPoints := []string{"web"} entryPoints := []string{"web"}
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Services: test.serviceConfig, Services: test.serviceConfig,
Routers: test.routerConfig, Routers: test.routerConfig,
@ -694,7 +695,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]*dynamic.MiddlewareInfo{}) responseModifierFactory := responsemodifiers.NewBuilder(map[string]*runtime.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)
@ -709,7 +710,7 @@ func TestRuntimeConfiguration(t *testing.T) {
} }
} }
for _, v := range rtConf.Routers { for _, v := range rtConf.Routers {
if v.Err != "" { if len(v.Err) > 0 {
allErrors++ allErrors++
} }
} }
@ -759,7 +760,7 @@ func BenchmarkRouterServe(b *testing.B) {
} }
entryPoints := []string{"web"} entryPoints := []string{"web"}
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Services: serviceConfig, Services: serviceConfig,
Routers: routersConfig, Routers: routersConfig,
@ -802,7 +803,7 @@ func BenchmarkService(b *testing.B) {
}, },
} }
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{ rtConf := runtime.NewConfig(dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Services: serviceConfig, Services: serviceConfig,
}, },

View file

@ -6,7 +6,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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 *dynamic.RuntimeConfiguration, func NewManager(conf *runtime.Configuration,
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 *dynamic.RuntimeConfiguration conf *runtime.Configuration
} }
func (m *Manager) getTCPRouters(ctx context.Context, entryPoints []string) map[string]map[string]*dynamic.TCPRouterInfo { func (m *Manager) getTCPRouters(ctx context.Context, entryPoints []string) map[string]map[string]*runtime.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]*dynamic.TCPRouterInfo) return make(map[string]map[string]*runtime.TCPRouterInfo)
} }
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*dynamic.RouterInfo { func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*runtime.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]*dynamic.RouterInfo) return make(map[string]map[string]*runtime.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]*dynamic.TCPRouterInfo, configsHTTP map[string]*dynamic.RouterInfo, handlerHTTP http.Handler, handlerHTTPS http.Handler) (*tcp.Router, error) { func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*runtime.TCPRouterInfo, configsHTTP map[string]*runtime.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"
@ -108,7 +108,7 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
domains, err := rules.ParseDomains(routerHTTPConfig.Rule) domains, err := rules.ParseDomains(routerHTTPConfig.Rule)
if err != nil { if err != nil {
routerErr := fmt.Errorf("invalid rule %s, error: %v", routerHTTPConfig.Rule, err) routerErr := fmt.Errorf("invalid rule %s, error: %v", routerHTTPConfig.Rule, err)
routerHTTPConfig.Err = routerErr.Error() routerHTTPConfig.AddError(routerErr, true)
logger.Debug(routerErr) logger.Debug(routerErr)
continue continue
} }
@ -126,7 +126,7 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
tlsConf, err := m.tlsManager.Get("default", tlsOptionsName) tlsConf, err := m.tlsManager.Get("default", tlsOptionsName)
if err != nil { if err != nil {
routerHTTPConfig.Err = err.Error() routerHTTPConfig.AddError(err, true)
logger.Debug(err) logger.Debug(err)
continue continue
} }
@ -156,11 +156,7 @@ func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string
} else { } else {
routers := make([]string, 0, len(tlsConfigs)) routers := make([]string, 0, len(tlsConfigs))
for _, v := range tlsConfigs { for _, v := range tlsConfigs {
// TODO: properly deal with critical errors VS non-critical errors configsHTTP[v.routerName].AddError(fmt.Errorf("found different TLS options for routers on the same host %v, so using the default TLS option instead", hostSNI), false)
if configsHTTP[v.routerName].Err != "" {
configsHTTP[v.routerName].Err += "\n"
}
configsHTTP[v.routerName].Err += fmt.Sprintf("found different TLS options for routers on the same host %v, so using the default TLS option instead", hostSNI)
routers = append(routers, v.routerName) routers = append(routers, v.routerName)
} }
logger.Warnf("Found different TLS options for routers on the same host %v, so using the default TLS options instead for these routers: %#v", hostSNI, routers) logger.Warnf("Found different TLS options for routers on the same host %v, so using the default TLS options instead for these routers: %#v", hostSNI, routers)

View file

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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,13 +14,13 @@ import (
func TestRuntimeConfiguration(t *testing.T) { func TestRuntimeConfiguration(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
serviceConfig map[string]*dynamic.TCPServiceInfo serviceConfig map[string]*runtime.TCPServiceInfo
routerConfig map[string]*dynamic.TCPRouterInfo routerConfig map[string]*runtime.TCPRouterInfo
expectedError int expectedError int
}{ }{
{ {
desc: "No error", desc: "No error",
serviceConfig: map[string]*dynamic.TCPServiceInfo{ serviceConfig: map[string]*runtime.TCPServiceInfo{
"foo-service": { "foo-service": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -37,7 +38,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
}, },
}, },
routerConfig: map[string]*dynamic.TCPRouterInfo{ routerConfig: map[string]*runtime.TCPRouterInfo{
"foo": { "foo": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -66,7 +67,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
{ {
desc: "One router with wrong rule", desc: "One router with wrong rule",
serviceConfig: map[string]*dynamic.TCPServiceInfo{ serviceConfig: map[string]*runtime.TCPServiceInfo{
"foo-service": { "foo-service": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -79,7 +80,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
}, },
}, },
routerConfig: map[string]*dynamic.TCPRouterInfo{ routerConfig: map[string]*runtime.TCPRouterInfo{
"foo": { "foo": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -100,7 +101,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
{ {
desc: "All router with wrong rule", desc: "All router with wrong rule",
serviceConfig: map[string]*dynamic.TCPServiceInfo{ serviceConfig: map[string]*runtime.TCPServiceInfo{
"foo-service": { "foo-service": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -113,7 +114,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
}, },
}, },
routerConfig: map[string]*dynamic.TCPRouterInfo{ routerConfig: map[string]*runtime.TCPRouterInfo{
"foo": { "foo": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -133,7 +134,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
{ {
desc: "Router with unknown service", desc: "Router with unknown service",
serviceConfig: map[string]*dynamic.TCPServiceInfo{ serviceConfig: map[string]*runtime.TCPServiceInfo{
"foo-service": { "foo-service": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -146,7 +147,7 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
}, },
}, },
routerConfig: map[string]*dynamic.TCPRouterInfo{ routerConfig: map[string]*runtime.TCPRouterInfo{
"foo": { "foo": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -167,14 +168,14 @@ func TestRuntimeConfiguration(t *testing.T) {
}, },
{ {
desc: "Router with broken service", desc: "Router with broken service",
serviceConfig: map[string]*dynamic.TCPServiceInfo{ serviceConfig: map[string]*runtime.TCPServiceInfo{
"foo-service": { "foo-service": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: nil, LoadBalancer: nil,
}, },
}, },
}, },
routerConfig: map[string]*dynamic.TCPRouterInfo{ routerConfig: map[string]*runtime.TCPRouterInfo{
"bar": { "bar": {
TCPRouter: &dynamic.TCPRouter{ TCPRouter: &dynamic.TCPRouter{
EntryPoints: []string{"web"}, EntryPoints: []string{"web"},
@ -195,7 +196,7 @@ func TestRuntimeConfiguration(t *testing.T) {
entryPoints := []string{"web"} entryPoints := []string{"web"}
conf := &dynamic.RuntimeConfiguration{ conf := &runtime.Configuration{
TCPServices: test.serviceConfig, TCPServices: test.serviceConfig,
TCPRouters: test.routerConfig, TCPRouters: test.routerConfig,
} }

View file

@ -10,6 +10,7 @@ import (
"time" "time"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -47,7 +48,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 *dynamic.RuntimeConfiguration) types.RouteAppender NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *runtime.Configuration) types.RouteAppender
} }
func setupTracing(conf *static.Tracing) tracing.Backend { func setupTracing(conf *static.Tracing) tracing.Backend {

View file

@ -10,6 +10,7 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
"github.com/containous/mux" "github.com/containous/mux"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -65,7 +66,7 @@ func (s *Server) loadConfigurationTCP(configurations dynamic.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 := dynamic.NewRuntimeConfig(conf) rtConf := runtime.NewConfig(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 +75,7 @@ func (s *Server) loadConfigurationTCP(configurations dynamic.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 *dynamic.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 *runtime.Configuration, 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 +88,7 @@ func (s *Server) createTCPRouters(ctx context.Context, configuration *dynamic.Ru
} }
// 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 *dynamic.RuntimeConfiguration, entryPoints []string) (map[string]http.Handler, map[string]http.Handler) { func (s *Server) createHTTPHandlers(ctx context.Context, configuration *runtime.Configuration, 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)

View file

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -46,7 +47,7 @@ func TestReuseService(t *testing.T) {
srv := NewServer(staticConfig, nil, entryPoints, nil) srv := NewServer(staticConfig, nil, entryPoints, nil)
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{HTTP: dynamicConfigs}) rtConf := runtime.NewConfig(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.

View file

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -253,7 +254,7 @@ func TestServerResponseEmptyBackend(t *testing.T) {
} }
srv := NewServer(globalConfig, nil, entryPointsConfig, nil) srv := NewServer(globalConfig, nil, entryPointsConfig, nil)
rtConf := dynamic.NewRuntimeConfig(dynamic.Configuration{HTTP: test.config(testServer.URL)}) rtConf := runtime.NewConfig(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{}

View file

@ -10,6 +10,7 @@ import (
"github.com/containous/alice" "github.com/containous/alice"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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 +27,7 @@ const (
) )
// NewManager creates a new Manager // NewManager creates a new Manager
func NewManager(configs map[string]*dynamic.ServiceInfo, defaultRoundTripper http.RoundTripper) *Manager { func NewManager(configs map[string]*runtime.ServiceInfo, defaultRoundTripper http.RoundTripper) *Manager {
return &Manager{ return &Manager{
bufferPool: newBufferPool(), bufferPool: newBufferPool(),
defaultRoundTripper: defaultRoundTripper, defaultRoundTripper: defaultRoundTripper,
@ -40,7 +41,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]*dynamic.ServiceInfo configs map[string]*runtime.ServiceInfo
} }
// BuildHTTP Creates a http.Handler for a service configuration. // BuildHTTP Creates a http.Handler for a service configuration.
@ -58,13 +59,14 @@ func (m *Manager) BuildHTTP(rootCtx context.Context, serviceName string, respons
// TODO Should handle multiple service types // TODO Should handle multiple service types
// FIXME Check if the service is declared multiple times with different types // FIXME Check if the service is declared multiple times with different types
if conf.LoadBalancer == nil { if conf.LoadBalancer == nil {
conf.Err = fmt.Errorf("the service %q doesn't have any load balancer", serviceName) sErr := fmt.Errorf("the service %q doesn't have any load balancer", serviceName)
return nil, conf.Err conf.AddError(sErr, true)
return nil, sErr
} }
lb, err := m.getLoadBalancerServiceHandler(ctx, serviceName, conf.LoadBalancer, responseModifier) lb, err := m.getLoadBalancerServiceHandler(ctx, serviceName, conf.LoadBalancer, responseModifier)
if err != nil { if err != nil {
conf.Err = err conf.AddError(err, true)
return nil, err return nil, err
} }

View file

@ -8,6 +8,7 @@ import (
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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"
@ -287,13 +288,13 @@ func TestManager_Build(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
serviceName string serviceName string
configs map[string]*dynamic.ServiceInfo configs map[string]*runtime.ServiceInfo
providerName string providerName string
}{ }{
{ {
desc: "Simple service name", desc: "Simple service name",
serviceName: "serviceName", serviceName: "serviceName",
configs: map[string]*dynamic.ServiceInfo{ configs: map[string]*runtime.ServiceInfo{
"serviceName": { "serviceName": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{}, LoadBalancer: &dynamic.LoadBalancerService{},
@ -304,7 +305,7 @@ 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]*dynamic.ServiceInfo{ configs: map[string]*runtime.ServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{}, LoadBalancer: &dynamic.LoadBalancerService{},
@ -315,7 +316,7 @@ 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]*dynamic.ServiceInfo{ configs: map[string]*runtime.ServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
Service: &dynamic.Service{ Service: &dynamic.Service{
LoadBalancer: &dynamic.LoadBalancerService{}, LoadBalancer: &dynamic.LoadBalancerService{},

View file

@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/runtime"
"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]*dynamic.TCPServiceInfo configs map[string]*runtime.TCPServiceInfo
} }
// NewManager creates a new manager // NewManager creates a new manager
func NewManager(conf *dynamic.RuntimeConfiguration) *Manager { func NewManager(conf *runtime.Configuration) *Manager {
return &Manager{ return &Manager{
configs: conf.TCPServices, configs: conf.TCPServices,
} }

View file

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/containous/traefik/pkg/config/dynamic" "github.com/containous/traefik/pkg/config/dynamic"
"github.com/containous/traefik/pkg/config/runtime"
"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 +15,7 @@ func TestManager_BuildTCP(t *testing.T) {
testCases := []struct { testCases := []struct {
desc string desc string
serviceName string serviceName string
configs map[string]*dynamic.TCPServiceInfo configs map[string]*runtime.TCPServiceInfo
providerName string providerName string
expectedError string expectedError string
}{ }{
@ -27,7 +28,7 @@ func TestManager_BuildTCP(t *testing.T) {
{ {
desc: "missing lb configuration", desc: "missing lb configuration",
serviceName: "test", serviceName: "test",
configs: map[string]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"test": { "test": {
TCPService: &dynamic.TCPService{}, TCPService: &dynamic.TCPService{},
}, },
@ -37,7 +38,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"test": { "test": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -52,7 +53,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"test": { "test": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -67,7 +68,7 @@ func TestManager_BuildTCP(t *testing.T) {
{ {
desc: "Simple service name", desc: "Simple service name",
serviceName: "serviceName", serviceName: "serviceName",
configs: map[string]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName": { "serviceName": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{}, LoadBalancer: &dynamic.TCPLoadBalancerService{},
@ -78,7 +79,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{}, LoadBalancer: &dynamic.TCPLoadBalancerService{},
@ -89,7 +90,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{}, LoadBalancer: &dynamic.TCPLoadBalancerService{},
@ -101,7 +102,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -119,7 +120,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -137,7 +138,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -155,7 +156,7 @@ 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]*dynamic.TCPServiceInfo{ configs: map[string]*runtime.TCPServiceInfo{
"serviceName@provider-1": { "serviceName@provider-1": {
TCPService: &dynamic.TCPService{ TCPService: &dynamic.TCPService{
LoadBalancer: &dynamic.TCPLoadBalancerService{ LoadBalancer: &dynamic.TCPLoadBalancerService{
@ -177,7 +178,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(&dynamic.RuntimeConfiguration{ manager := NewManager(&runtime.Configuration{
TCPServices: test.configs, TCPServices: test.configs,
}) })