Router entry points on reload.

This commit is contained in:
Ludovic Fernandez 2020-03-09 11:12:05 +01:00 committed by GitHub
parent 99861ac808
commit d02bb28920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 15 deletions

View file

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"time" "time"
@ -191,7 +192,7 @@ func setupServer(staticConfiguration *static.Configuration) (*server.Server, err
managerFactory := service.NewManagerFactory(*staticConfiguration, routinesPool, metricsRegistry) managerFactory := service.NewManagerFactory(*staticConfiguration, routinesPool, metricsRegistry)
routerFactory := server.NewRouterFactory(*staticConfiguration, managerFactory, tlsManager, chainBuilder) routerFactory := server.NewRouterFactory(*staticConfiguration, managerFactory, tlsManager, chainBuilder)
var eps []string var defaultEntryPoints []string
for name, cfg := range staticConfiguration.EntryPoints { for name, cfg := range staticConfiguration.EntryPoints {
protocol, err := cfg.GetProtocol() protocol, err := cfg.GetProtocol()
if err != nil { if err != nil {
@ -200,15 +201,17 @@ func setupServer(staticConfiguration *static.Configuration) (*server.Server, err
} }
if protocol != "udp" { if protocol != "udp" {
eps = append(eps, name) defaultEntryPoints = append(defaultEntryPoints, name)
} }
} }
sort.Strings(defaultEntryPoints)
watcher := server.NewConfigurationWatcher( watcher := server.NewConfigurationWatcher(
routinesPool, routinesPool,
providerAggregator, providerAggregator,
time.Duration(staticConfiguration.Providers.ProvidersThrottleDuration), time.Duration(staticConfiguration.Providers.ProvidersThrottleDuration),
eps, defaultEntryPoints,
) )
watcher.AddListener(func(conf dynamic.Configuration) { watcher.AddListener(func(conf dynamic.Configuration) {

View file

@ -30,8 +30,8 @@
}, },
"test-ingress-default-whoami-test-whoami@kubernetes": { "test-ingress-default-whoami-test-whoami@kubernetes": {
"entryPoints": [ "entryPoints": [
"web", "traefik",
"traefik" "web"
], ],
"service": "default-whoami-http", "service": "default-whoami-http",
"rule": "Host(`whoami.test`) \u0026\u0026 PathPrefix(`/whoami`)", "rule": "Host(`whoami.test`) \u0026\u0026 PathPrefix(`/whoami`)",
@ -43,8 +43,8 @@
}, },
"test-ingress-https-default-whoami-test-https-whoami@kubernetes": { "test-ingress-https-default-whoami-test-https-whoami@kubernetes": {
"entryPoints": [ "entryPoints": [
"web", "traefik",
"traefik" "web"
], ],
"service": "default-whoami-http", "service": "default-whoami-http",
"rule": "Host(`whoami.test.https`) \u0026\u0026 PathPrefix(`/whoami`)", "rule": "Host(`whoami.test.https`) \u0026\u0026 PathPrefix(`/whoami`)",

View file

@ -7,7 +7,7 @@ import (
"github.com/containous/traefik/v2/pkg/tls" "github.com/containous/traefik/v2/pkg/tls"
) )
func mergeConfiguration(configurations dynamic.Configurations, entryPoints []string) dynamic.Configuration { func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoints []string) dynamic.Configuration {
conf := dynamic.Configuration{ conf := dynamic.Configuration{
HTTP: &dynamic.HTTPConfiguration{ HTTP: &dynamic.HTTPConfiguration{
Routers: make(map[string]*dynamic.Router), Routers: make(map[string]*dynamic.Router),
@ -37,8 +37,8 @@ func mergeConfiguration(configurations dynamic.Configurations, entryPoints []str
if len(router.EntryPoints) == 0 { if len(router.EntryPoints) == 0 {
log.WithoutContext(). log.WithoutContext().
WithField(log.RouterName, routerName). WithField(log.RouterName, routerName).
Debugf("No entryPoint defined for this router, using the default one(s) instead: %+v", entryPoints) Debugf("No entryPoint defined for this router, using the default one(s) instead: %+v", defaultEntryPoints)
router.EntryPoints = entryPoints router.EntryPoints = defaultEntryPoints
} }
conf.HTTP.Routers[provider.MakeQualifiedName(pvd, routerName)] = router conf.HTTP.Routers[provider.MakeQualifiedName(pvd, routerName)] = router
@ -120,7 +120,9 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
rts := make(map[string]*dynamic.Router) rts := make(map[string]*dynamic.Router)
for name, router := range cfg.HTTP.Routers { for name, rt := range cfg.HTTP.Routers {
router := rt.DeepCopy()
eps := router.EntryPoints eps := router.EntryPoints
router.EntryPoints = nil router.EntryPoints = nil

View file

@ -18,7 +18,7 @@ import (
type ConfigurationWatcher struct { type ConfigurationWatcher struct {
provider provider.Provider provider provider.Provider
entryPoints []string defaultEntryPoints []string
providersThrottleDuration time.Duration providersThrottleDuration time.Duration
@ -38,7 +38,7 @@ func NewConfigurationWatcher(
routinesPool *safe.Pool, routinesPool *safe.Pool,
pvd provider.Provider, pvd provider.Provider,
providersThrottleDuration time.Duration, providersThrottleDuration time.Duration,
entryPoints []string, defaultEntryPoints []string,
) *ConfigurationWatcher { ) *ConfigurationWatcher {
watcher := &ConfigurationWatcher{ watcher := &ConfigurationWatcher{
provider: pvd, provider: pvd,
@ -47,7 +47,7 @@ func NewConfigurationWatcher(
providerConfigUpdateMap: make(map[string]chan dynamic.Message), providerConfigUpdateMap: make(map[string]chan dynamic.Message),
providersThrottleDuration: providersThrottleDuration, providersThrottleDuration: providersThrottleDuration,
routinesPool: routinesPool, routinesPool: routinesPool,
entryPoints: entryPoints, defaultEntryPoints: defaultEntryPoints,
} }
currentConfigurations := make(dynamic.Configurations) currentConfigurations := make(dynamic.Configurations)
@ -143,7 +143,7 @@ func (c *ConfigurationWatcher) loadMessage(configMsg dynamic.Message) {
c.currentConfigurations.Set(newConfigurations) c.currentConfigurations.Set(newConfigurations)
conf := mergeConfiguration(newConfigurations, c.entryPoints) conf := mergeConfiguration(newConfigurations, c.defaultEntryPoints)
conf = applyModel(conf) conf = applyModel(conf)
for _, listener := range c.configurationListeners { for _, listener := range c.configurationListeners {