Move dynamic config into a dedicated package.
This commit is contained in:
parent
09cc1161c9
commit
c8bf8e896a
102 changed files with 3170 additions and 3166 deletions
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/log"
|
||||
"github.com/containous/traefik/pkg/rules"
|
||||
"github.com/containous/traefik/pkg/server/internal"
|
||||
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
// NewManager Creates a new Manager
|
||||
func NewManager(conf *config.RuntimeConfiguration,
|
||||
func NewManager(conf *dynamic.RuntimeConfiguration,
|
||||
serviceManager *tcpservice.Manager,
|
||||
httpHandlers map[string]http.Handler,
|
||||
httpsHandlers map[string]http.Handler,
|
||||
|
@ -37,23 +37,23 @@ type Manager struct {
|
|||
httpHandlers map[string]http.Handler
|
||||
httpsHandlers map[string]http.Handler
|
||||
tlsManager *traefiktls.Manager
|
||||
conf *config.RuntimeConfiguration
|
||||
conf *dynamic.RuntimeConfiguration
|
||||
}
|
||||
|
||||
func (m *Manager) getTCPRouters(ctx context.Context, entryPoints []string) map[string]map[string]*config.TCPRouterInfo {
|
||||
func (m *Manager) getTCPRouters(ctx context.Context, entryPoints []string) map[string]map[string]*dynamic.TCPRouterInfo {
|
||||
if m.conf != nil {
|
||||
return m.conf.GetTCPRoutersByEntrypoints(ctx, entryPoints)
|
||||
}
|
||||
|
||||
return make(map[string]map[string]*config.TCPRouterInfo)
|
||||
return make(map[string]map[string]*dynamic.TCPRouterInfo)
|
||||
}
|
||||
|
||||
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*config.RouterInfo {
|
||||
func (m *Manager) getHTTPRouters(ctx context.Context, entryPoints []string, tls bool) map[string]map[string]*dynamic.RouterInfo {
|
||||
if m.conf != nil {
|
||||
return m.conf.GetRoutersByEntrypoints(ctx, entryPoints, tls)
|
||||
}
|
||||
|
||||
return make(map[string]map[string]*config.RouterInfo)
|
||||
return make(map[string]map[string]*dynamic.RouterInfo)
|
||||
}
|
||||
|
||||
// BuildHandlers builds the handlers for the given entrypoints
|
||||
|
@ -79,7 +79,7 @@ func (m *Manager) BuildHandlers(rootCtx context.Context, entryPoints []string) m
|
|||
return entryPointHandlers
|
||||
}
|
||||
|
||||
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*config.TCPRouterInfo, configsHTTP map[string]*config.RouterInfo, handlerHTTP http.Handler, handlerHTTPS http.Handler) (*tcp.Router, error) {
|
||||
func (m *Manager) buildEntryPointHandler(ctx context.Context, configs map[string]*dynamic.TCPRouterInfo, configsHTTP map[string]*dynamic.RouterInfo, handlerHTTP http.Handler, handlerHTTPS http.Handler) (*tcp.Router, error) {
|
||||
router := &tcp.Router{}
|
||||
router.HTTPHandler(handlerHTTP)
|
||||
const defaultTLSConfigName = "default"
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/containous/traefik/pkg/config"
|
||||
"github.com/containous/traefik/pkg/config/dynamic"
|
||||
"github.com/containous/traefik/pkg/server/service/tcp"
|
||||
"github.com/containous/traefik/pkg/tls"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
@ -13,17 +13,17 @@ import (
|
|||
func TestRuntimeConfiguration(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
serviceConfig map[string]*config.TCPServiceInfo
|
||||
routerConfig map[string]*config.TCPRouterInfo
|
||||
serviceConfig map[string]*dynamic.TCPServiceInfo
|
||||
routerConfig map[string]*dynamic.TCPRouterInfo
|
||||
expectedError int
|
||||
}{
|
||||
{
|
||||
desc: "No error",
|
||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
||||
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||
"foo-service": {
|
||||
TCPService: &config.TCPService{
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
TCPService: &dynamic.TCPService{
|
||||
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||
Servers: []dynamic.TCPServer{
|
||||
{
|
||||
Port: "8085",
|
||||
Address: "127.0.0.1:8085",
|
||||
|
@ -37,25 +37,25 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
routerConfig: map[string]*config.TCPRouterInfo{
|
||||
routerConfig: map[string]*dynamic.TCPRouterInfo{
|
||||
"foo": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "HostSNI(`bar.foo`)",
|
||||
TLS: &config.RouterTCPTLSConfig{
|
||||
TLS: &dynamic.RouterTCPTLSConfig{
|
||||
Passthrough: false,
|
||||
Options: "foo",
|
||||
},
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "HostSNI(`foo.bar`)",
|
||||
TLS: &config.RouterTCPTLSConfig{
|
||||
TLS: &dynamic.RouterTCPTLSConfig{
|
||||
Passthrough: false,
|
||||
Options: "bar",
|
||||
},
|
||||
|
@ -66,11 +66,11 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "One router with wrong rule",
|
||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
||||
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||
"foo-service": {
|
||||
TCPService: &config.TCPService{
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
TCPService: &dynamic.TCPService{
|
||||
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||
Servers: []dynamic.TCPServer{
|
||||
{
|
||||
Address: "127.0.0.1:80",
|
||||
},
|
||||
|
@ -79,9 +79,9 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
routerConfig: map[string]*config.TCPRouterInfo{
|
||||
routerConfig: map[string]*dynamic.TCPRouterInfo{
|
||||
"foo": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "WrongRule(`bar.foo`)",
|
||||
|
@ -89,7 +89,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
|
||||
"bar": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "HostSNI(`foo.bar`)",
|
||||
|
@ -100,11 +100,11 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "All router with wrong rule",
|
||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
||||
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||
"foo-service": {
|
||||
TCPService: &config.TCPService{
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
TCPService: &dynamic.TCPService{
|
||||
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||
Servers: []dynamic.TCPServer{
|
||||
{
|
||||
Address: "127.0.0.1:80",
|
||||
},
|
||||
|
@ -113,16 +113,16 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
routerConfig: map[string]*config.TCPRouterInfo{
|
||||
routerConfig: map[string]*dynamic.TCPRouterInfo{
|
||||
"foo": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "WrongRule(`bar.foo`)",
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "WrongRule(`foo.bar`)",
|
||||
|
@ -133,11 +133,11 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Router with unknown service",
|
||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
||||
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||
"foo-service": {
|
||||
TCPService: &config.TCPService{
|
||||
LoadBalancer: &config.TCPLoadBalancerService{
|
||||
Servers: []config.TCPServer{
|
||||
TCPService: &dynamic.TCPService{
|
||||
LoadBalancer: &dynamic.TCPLoadBalancerService{
|
||||
Servers: []dynamic.TCPServer{
|
||||
{
|
||||
Address: "127.0.0.1:80",
|
||||
},
|
||||
|
@ -146,16 +146,16 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
routerConfig: map[string]*config.TCPRouterInfo{
|
||||
routerConfig: map[string]*dynamic.TCPRouterInfo{
|
||||
"foo": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "wrong-service",
|
||||
Rule: "HostSNI(`bar.foo`)",
|
||||
},
|
||||
},
|
||||
"bar": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
|
@ -167,16 +167,16 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
},
|
||||
{
|
||||
desc: "Router with broken service",
|
||||
serviceConfig: map[string]*config.TCPServiceInfo{
|
||||
serviceConfig: map[string]*dynamic.TCPServiceInfo{
|
||||
"foo-service": {
|
||||
TCPService: &config.TCPService{
|
||||
TCPService: &dynamic.TCPService{
|
||||
LoadBalancer: nil,
|
||||
},
|
||||
},
|
||||
},
|
||||
routerConfig: map[string]*config.TCPRouterInfo{
|
||||
routerConfig: map[string]*dynamic.TCPRouterInfo{
|
||||
"bar": {
|
||||
TCPRouter: &config.TCPRouter{
|
||||
TCPRouter: &dynamic.TCPRouter{
|
||||
EntryPoints: []string{"web"},
|
||||
Service: "foo-service",
|
||||
Rule: "HostSNI(`foo.bar`)",
|
||||
|
@ -195,7 +195,7 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
|
||||
entryPoints := []string{"web"}
|
||||
|
||||
conf := &config.RuntimeConfiguration{
|
||||
conf := &dynamic.RuntimeConfiguration{
|
||||
TCPServices: test.serviceConfig,
|
||||
TCPRouters: test.routerConfig,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue