Dynamic Configuration Refactoring
This commit is contained in:
parent
d3ae88f108
commit
a09dfa3ce1
452 changed files with 21023 additions and 9419 deletions
|
@ -5,10 +5,10 @@ import (
|
|||
|
||||
"github.com/containous/traefik/anonymize"
|
||||
"github.com/containous/traefik/cmd"
|
||||
"github.com/containous/traefik/configuration"
|
||||
"github.com/containous/traefik/provider/file"
|
||||
"github.com/containous/traefik/old/configuration"
|
||||
"github.com/containous/traefik/old/provider/file"
|
||||
"github.com/containous/traefik/old/types"
|
||||
"github.com/containous/traefik/tls"
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -4,32 +4,30 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/containous/flaeg/parse"
|
||||
"github.com/containous/traefik-extra-service-fabric"
|
||||
"github.com/containous/traefik/api"
|
||||
"github.com/containous/traefik/configuration"
|
||||
"github.com/containous/traefik/middlewares/accesslog"
|
||||
"github.com/containous/traefik/middlewares/tracing"
|
||||
"github.com/containous/traefik/middlewares/tracing/datadog"
|
||||
"github.com/containous/traefik/middlewares/tracing/jaeger"
|
||||
"github.com/containous/traefik/middlewares/tracing/zipkin"
|
||||
"github.com/containous/traefik/ping"
|
||||
"github.com/containous/traefik/provider/boltdb"
|
||||
"github.com/containous/traefik/provider/consul"
|
||||
"github.com/containous/traefik/provider/consulcatalog"
|
||||
"github.com/containous/traefik/provider/docker"
|
||||
"github.com/containous/traefik/provider/dynamodb"
|
||||
"github.com/containous/traefik/provider/ecs"
|
||||
"github.com/containous/traefik/provider/etcd"
|
||||
"github.com/containous/traefik/provider/eureka"
|
||||
"github.com/containous/traefik/provider/file"
|
||||
"github.com/containous/traefik/provider/kubernetes"
|
||||
"github.com/containous/traefik/provider/marathon"
|
||||
"github.com/containous/traefik/provider/mesos"
|
||||
"github.com/containous/traefik/provider/rancher"
|
||||
"github.com/containous/traefik/provider/rest"
|
||||
"github.com/containous/traefik/provider/zk"
|
||||
"github.com/containous/traefik/types"
|
||||
sf "github.com/jjcollinge/servicefabric"
|
||||
"github.com/containous/traefik/old/api"
|
||||
"github.com/containous/traefik/old/configuration"
|
||||
"github.com/containous/traefik/old/middlewares/accesslog"
|
||||
"github.com/containous/traefik/old/middlewares/tracing"
|
||||
"github.com/containous/traefik/old/middlewares/tracing/datadog"
|
||||
"github.com/containous/traefik/old/middlewares/tracing/jaeger"
|
||||
"github.com/containous/traefik/old/middlewares/tracing/zipkin"
|
||||
"github.com/containous/traefik/old/ping"
|
||||
"github.com/containous/traefik/old/provider/boltdb"
|
||||
"github.com/containous/traefik/old/provider/consul"
|
||||
"github.com/containous/traefik/old/provider/consulcatalog"
|
||||
"github.com/containous/traefik/old/provider/docker"
|
||||
"github.com/containous/traefik/old/provider/dynamodb"
|
||||
"github.com/containous/traefik/old/provider/ecs"
|
||||
"github.com/containous/traefik/old/provider/etcd"
|
||||
"github.com/containous/traefik/old/provider/eureka"
|
||||
"github.com/containous/traefik/old/provider/file"
|
||||
"github.com/containous/traefik/old/provider/kubernetes"
|
||||
"github.com/containous/traefik/old/provider/marathon"
|
||||
"github.com/containous/traefik/old/provider/mesos"
|
||||
"github.com/containous/traefik/old/provider/rancher"
|
||||
"github.com/containous/traefik/old/provider/rest"
|
||||
"github.com/containous/traefik/old/provider/zk"
|
||||
"github.com/containous/traefik/old/types"
|
||||
)
|
||||
|
||||
// TraefikConfiguration holds GlobalConfiguration and other stuff
|
||||
|
@ -145,11 +143,6 @@ func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
|
|||
var defaultEureka eureka.Provider
|
||||
defaultEureka.RefreshSeconds = parse.Duration(30 * time.Second)
|
||||
|
||||
// default ServiceFabric
|
||||
var defaultServiceFabric servicefabric.Provider
|
||||
defaultServiceFabric.APIVersion = sf.DefaultAPIVersion
|
||||
defaultServiceFabric.RefreshSeconds = 10
|
||||
|
||||
// default Ping
|
||||
var defaultPing = ping.Handler{
|
||||
EntryPoint: "traefik",
|
||||
|
|
146
cmd/convert/convert.go
Normal file
146
cmd/convert/convert.go
Normal file
|
@ -0,0 +1,146 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/containous/traefik/config"
|
||||
"github.com/containous/traefik/old/log"
|
||||
"github.com/containous/traefik/old/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var oldvalue = `
|
||||
[backends]
|
||||
[backends.backend1]
|
||||
[backends.backend1.servers.server1]
|
||||
url = "http://127.0.0.1:9010"
|
||||
weight = 1
|
||||
[backends.backend2]
|
||||
[backends.backend2.servers.server1]
|
||||
url = "http://127.0.0.1:9020"
|
||||
weight = 1
|
||||
|
||||
[frontends]
|
||||
[frontends.frontend1]
|
||||
backend = "backend1"
|
||||
[frontends.frontend1.routes.test_1]
|
||||
rule = "Host:snitest.com"
|
||||
[frontends.frontend2]
|
||||
backend = "backend2"
|
||||
[frontends.frontend2.routes.test_2]
|
||||
rule = "Host:snitest.org"
|
||||
|
||||
`
|
||||
|
||||
// Temporary utility to convert dynamic conf v1 to v2
|
||||
func main() {
|
||||
log.SetOutput(os.Stdout)
|
||||
log.SetLevel(logrus.DebugLevel)
|
||||
|
||||
oldconfig := &types.Configuration{}
|
||||
toml.Decode(oldvalue, oldconfig)
|
||||
|
||||
newconfig := config.Configuration{
|
||||
Routers: make(map[string]*config.Router),
|
||||
Middlewares: make(map[string]*config.Middleware),
|
||||
Services: make(map[string]*config.Service),
|
||||
}
|
||||
|
||||
for frontendName, frontend := range oldconfig.Frontends {
|
||||
newconfig.Routers[replaceFrontend(frontendName)] = convertFrontend(frontend)
|
||||
if frontend.PassHostHeader {
|
||||
log.Warn("ignore PassHostHeader")
|
||||
}
|
||||
}
|
||||
|
||||
for backendName, backend := range oldconfig.Backends {
|
||||
newconfig.Services[replaceBackend(backendName)] = convertBackend(backend)
|
||||
}
|
||||
|
||||
encoder := toml.NewEncoder(os.Stdout)
|
||||
encoder.Encode(newconfig)
|
||||
}
|
||||
|
||||
func replaceBackend(name string) string {
|
||||
return strings.Replace(name, "backend", "service", -1)
|
||||
}
|
||||
|
||||
func replaceFrontend(name string) string {
|
||||
return strings.Replace(name, "frontend", "router", -1)
|
||||
}
|
||||
|
||||
func convertFrontend(frontend *types.Frontend) *config.Router {
|
||||
router := &config.Router{
|
||||
EntryPoints: frontend.EntryPoints,
|
||||
Middlewares: nil,
|
||||
Service: replaceBackend(frontend.Backend),
|
||||
Priority: frontend.Priority,
|
||||
}
|
||||
|
||||
if len(frontend.Routes) > 1 {
|
||||
log.Fatal("Multiple routes")
|
||||
}
|
||||
|
||||
for _, route := range frontend.Routes {
|
||||
router.Rule = route.Rule
|
||||
}
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
func convertBackend(backend *types.Backend) *config.Service {
|
||||
service := &config.Service{
|
||||
LoadBalancer: &config.LoadBalancerService{
|
||||
Stickiness: nil,
|
||||
Servers: nil,
|
||||
Method: "",
|
||||
HealthCheck: nil,
|
||||
PassHostHeader: false,
|
||||
},
|
||||
}
|
||||
|
||||
if backend.Buffering != nil {
|
||||
log.Warn("Buffering not implemented")
|
||||
}
|
||||
|
||||
if backend.CircuitBreaker != nil {
|
||||
log.Warn("CircuitBreaker not implemented")
|
||||
}
|
||||
|
||||
if backend.MaxConn != nil {
|
||||
log.Warn("MaxConn not implemented")
|
||||
}
|
||||
|
||||
for _, oldserver := range backend.Servers {
|
||||
service.LoadBalancer.Servers = append(service.LoadBalancer.Servers, config.Server{
|
||||
URL: oldserver.URL,
|
||||
Weight: oldserver.Weight,
|
||||
})
|
||||
}
|
||||
|
||||
if backend.LoadBalancer != nil {
|
||||
service.LoadBalancer.Method = backend.LoadBalancer.Method
|
||||
if backend.LoadBalancer.Stickiness != nil {
|
||||
service.LoadBalancer.Stickiness = &config.Stickiness{
|
||||
CookieName: backend.LoadBalancer.Stickiness.CookieName,
|
||||
}
|
||||
}
|
||||
|
||||
if backend.HealthCheck != nil {
|
||||
service.LoadBalancer.HealthCheck = &config.HealthCheck{
|
||||
Scheme: backend.HealthCheck.Scheme,
|
||||
Path: backend.HealthCheck.Path,
|
||||
Port: backend.HealthCheck.Port,
|
||||
Interval: backend.HealthCheck.Interval,
|
||||
Timeout: backend.HealthCheck.Timeout,
|
||||
Hostname: backend.HealthCheck.Hostname,
|
||||
Headers: backend.HealthCheck.Headers,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return service
|
||||
}
|
|
@ -10,7 +10,7 @@ import (
|
|||
|
||||
"github.com/containous/flaeg"
|
||||
"github.com/containous/traefik/cmd"
|
||||
"github.com/containous/traefik/configuration"
|
||||
"github.com/containous/traefik/old/configuration"
|
||||
)
|
||||
|
||||
// NewCmd builds a new HealthCheck command
|
||||
|
|
|
@ -21,17 +21,20 @@ import (
|
|||
"github.com/containous/traefik/cmd/storeconfig"
|
||||
cmdVersion "github.com/containous/traefik/cmd/version"
|
||||
"github.com/containous/traefik/collector"
|
||||
"github.com/containous/traefik/configuration"
|
||||
"github.com/containous/traefik/configuration/router"
|
||||
"github.com/containous/traefik/config"
|
||||
"github.com/containous/traefik/config/static"
|
||||
"github.com/containous/traefik/job"
|
||||
"github.com/containous/traefik/log"
|
||||
"github.com/containous/traefik/provider/ecs"
|
||||
"github.com/containous/traefik/provider/kubernetes"
|
||||
"github.com/containous/traefik/old/configuration"
|
||||
"github.com/containous/traefik/old/provider/ecs"
|
||||
"github.com/containous/traefik/old/provider/kubernetes"
|
||||
"github.com/containous/traefik/old/types"
|
||||
"github.com/containous/traefik/provider/aggregator"
|
||||
"github.com/containous/traefik/safe"
|
||||
"github.com/containous/traefik/server"
|
||||
"github.com/containous/traefik/server/router"
|
||||
"github.com/containous/traefik/server/uuid"
|
||||
traefiktls "github.com/containous/traefik/tls"
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/containous/traefik/version"
|
||||
"github.com/coreos/go-systemd/daemon"
|
||||
"github.com/elazarl/go-bindata-assetfs"
|
||||
|
@ -186,7 +189,7 @@ func runCmd(globalConfiguration *configuration.GlobalConfiguration, configFile s
|
|||
|
||||
stats(globalConfiguration)
|
||||
|
||||
providerAggregator := configuration.NewProviderAggregator(globalConfiguration)
|
||||
providerAggregator := aggregator.NewProviderAggregator(static.ConvertStaticConf(*globalConfiguration))
|
||||
|
||||
acmeProvider, err := globalConfiguration.InitACMEProvider()
|
||||
if err != nil {
|
||||
|
@ -199,18 +202,15 @@ func runCmd(globalConfiguration *configuration.GlobalConfiguration, configFile s
|
|||
}
|
||||
|
||||
entryPoints := map[string]server.EntryPoint{}
|
||||
staticConf := static.ConvertStaticConf(*globalConfiguration)
|
||||
for entryPointName, config := range globalConfiguration.EntryPoints {
|
||||
|
||||
factory := router.NewRouteAppenderFactory(staticConf, entryPointName, acmeProvider)
|
||||
entryPoint := server.EntryPoint{
|
||||
Configuration: config,
|
||||
RouteAppenderFactory: factory,
|
||||
Configuration: config,
|
||||
}
|
||||
|
||||
internalRouter := router.NewInternalRouterAggregator(*globalConfiguration, entryPointName)
|
||||
if acmeProvider != nil {
|
||||
if acmeProvider.HTTPChallenge != nil && entryPointName == acmeProvider.HTTPChallenge.EntryPoint {
|
||||
internalRouter.AddRouter(acmeProvider)
|
||||
}
|
||||
|
||||
// TLS ALPN 01
|
||||
if acmeProvider.TLSChallenge != nil && acmeProvider.HTTPChallenge == nil && acmeProvider.DNSChallenge == nil {
|
||||
entryPoint.TLSALPNGetter = acmeProvider.GetTLSALPNCertificate
|
||||
|
@ -227,19 +227,19 @@ func runCmd(globalConfiguration *configuration.GlobalConfiguration, configFile s
|
|||
}
|
||||
}
|
||||
|
||||
entryPoint.InternalRouter = internalRouter
|
||||
entryPoints[entryPointName] = entryPoint
|
||||
}
|
||||
|
||||
svr := server.NewServer(*globalConfiguration, providerAggregator, entryPoints)
|
||||
|
||||
if acmeProvider != nil && acmeProvider.OnHostRule {
|
||||
acmeProvider.SetConfigListenerChan(make(chan types.Configuration))
|
||||
acmeProvider.SetConfigListenerChan(make(chan config.Configuration))
|
||||
svr.AddListener(acmeProvider.ListenConfiguration)
|
||||
}
|
||||
ctx := cmd.ContextWithSignal(context.Background())
|
||||
|
||||
if globalConfiguration.Ping != nil {
|
||||
globalConfiguration.Ping.WithContext(ctx)
|
||||
if staticConf.Ping != nil {
|
||||
staticConf.Ping.WithContext(ctx)
|
||||
}
|
||||
|
||||
svr.StartWithContext(ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue