Fix spamming events in listenProviders
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
2a209c23c4
commit
606e667b88
2 changed files with 70 additions and 47 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
@ -53,6 +54,7 @@ type Kubernetes struct {
|
||||||
Endpoint string `description:"Kubernetes server endpoint"`
|
Endpoint string `description:"Kubernetes server endpoint"`
|
||||||
DisablePassHostHeaders bool `description:"Kubernetes disable PassHost Headers"`
|
DisablePassHostHeaders bool `description:"Kubernetes disable PassHost Headers"`
|
||||||
Namespaces Namespaces `description:"Kubernetes namespaces"`
|
Namespaces Namespaces `description:"Kubernetes namespaces"`
|
||||||
|
lastConfiguration safe.Safe
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Kubernetes) createClient() (k8s.Client, error) {
|
func (provider *Kubernetes) createClient() (k8s.Client, error) {
|
||||||
|
@ -124,6 +126,10 @@ func (provider *Kubernetes) Provide(configurationChan chan<- types.ConfigMessage
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if reflect.DeepEqual(provider.lastConfiguration.Get(), templateObjects) {
|
||||||
|
log.Debugf("Skipping event from kubernetes %+v", event)
|
||||||
|
} else {
|
||||||
|
provider.lastConfiguration.Set(templateObjects)
|
||||||
configurationChan <- types.ConfigMessage{
|
configurationChan <- types.ConfigMessage{
|
||||||
ProviderName: "kubernetes",
|
ProviderName: "kubernetes",
|
||||||
Configuration: provider.loadConfig(*templateObjects),
|
Configuration: provider.loadConfig(*templateObjects),
|
||||||
|
@ -132,6 +138,7 @@ func (provider *Kubernetes) Provide(configurationChan chan<- types.ConfigMessage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
notify := func(err error, time time.Duration) {
|
notify := func(err error, time time.Duration) {
|
||||||
log.Errorf("Kubernetes connection error %+v, retrying in %s", err, time)
|
log.Errorf("Kubernetes connection error %+v, retrying in %s", err, time)
|
||||||
|
@ -146,10 +153,15 @@ func (provider *Kubernetes) Provide(configurationChan chan<- types.ConfigMessage
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if reflect.DeepEqual(provider.lastConfiguration.Get(), templateObjects) {
|
||||||
|
log.Debugf("Skipping configuration from kubernetes %+v", templateObjects)
|
||||||
|
} else {
|
||||||
|
provider.lastConfiguration.Set(templateObjects)
|
||||||
configurationChan <- types.ConfigMessage{
|
configurationChan <- types.ConfigMessage{
|
||||||
ProviderName: "kubernetes",
|
ProviderName: "kubernetes",
|
||||||
Configuration: provider.loadConfig(*templateObjects),
|
Configuration: provider.loadConfig(*templateObjects),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
31
server.go
31
server.go
|
@ -137,8 +137,15 @@ func (server *Server) listenProviders(stop chan bool) {
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
server.defaultConfigurationValues(configMsg.Configuration)
|
||||||
|
currentConfigurations := server.currentConfigurations.Get().(configs)
|
||||||
jsonConf, _ := json.Marshal(configMsg.Configuration)
|
jsonConf, _ := json.Marshal(configMsg.Configuration)
|
||||||
log.Debugf("Configuration received from provider %s: %s", configMsg.ProviderName, string(jsonConf))
|
log.Debugf("Configuration received from provider %s: %s", configMsg.ProviderName, string(jsonConf))
|
||||||
|
if configMsg.Configuration == nil || configMsg.Configuration.Backends == nil && configMsg.Configuration.Frontends == nil {
|
||||||
|
log.Infof("Skipping empty Configuration for provider %s", configMsg.ProviderName)
|
||||||
|
} else if reflect.DeepEqual(currentConfigurations[configMsg.ProviderName], configMsg.Configuration) {
|
||||||
|
log.Infof("Skipping same configuration for provider %s", configMsg.ProviderName)
|
||||||
|
} else {
|
||||||
lastConfigs.Set(configMsg.ProviderName, &configMsg)
|
lastConfigs.Set(configMsg.ProviderName, &configMsg)
|
||||||
lastReceivedConfigurationValue := lastReceivedConfiguration.Get().(time.Time)
|
lastReceivedConfigurationValue := lastReceivedConfiguration.Get().(time.Time)
|
||||||
if time.Now().After(lastReceivedConfigurationValue.Add(time.Duration(server.globalConfiguration.ProvidersThrottleDuration))) {
|
if time.Now().After(lastReceivedConfigurationValue.Add(time.Duration(server.globalConfiguration.ProvidersThrottleDuration))) {
|
||||||
|
@ -161,6 +168,19 @@ func (server *Server) listenProviders(stop chan bool) {
|
||||||
lastReceivedConfiguration.Set(time.Now())
|
lastReceivedConfiguration.Set(time.Now())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) defaultConfigurationValues(configuration *types.Configuration) {
|
||||||
|
if configuration == nil || configuration.Frontends == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, frontend := range configuration.Frontends {
|
||||||
|
// default endpoints if not defined in frontends
|
||||||
|
if len(frontend.EntryPoints) == 0 {
|
||||||
|
frontend.EntryPoints = server.globalConfiguration.DefaultEntryPoints
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) listenConfigurations(stop chan bool) {
|
func (server *Server) listenConfigurations(stop chan bool) {
|
||||||
|
@ -173,11 +193,7 @@ func (server *Server) listenConfigurations(stop chan bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
currentConfigurations := server.currentConfigurations.Get().(configs)
|
currentConfigurations := server.currentConfigurations.Get().(configs)
|
||||||
if configMsg.Configuration == nil {
|
|
||||||
log.Infof("Skipping empty Configuration for provider %s", configMsg.ProviderName)
|
|
||||||
} else if reflect.DeepEqual(currentConfigurations[configMsg.ProviderName], configMsg.Configuration) {
|
|
||||||
log.Infof("Skipping same configuration for provider %s", configMsg.ProviderName)
|
|
||||||
} else {
|
|
||||||
// Copy configurations to new map so we don't change current if LoadConfig fails
|
// Copy configurations to new map so we don't change current if LoadConfig fails
|
||||||
newConfigurations := make(configs)
|
newConfigurations := make(configs)
|
||||||
for k, v := range currentConfigurations {
|
for k, v := range currentConfigurations {
|
||||||
|
@ -197,7 +213,6 @@ func (server *Server) listenConfigurations(stop chan bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (server *Server) configureProviders() {
|
func (server *Server) configureProviders() {
|
||||||
|
@ -376,10 +391,6 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
|
||||||
log.Debugf("Creating frontend %s", frontendName)
|
log.Debugf("Creating frontend %s", frontendName)
|
||||||
fwd, _ := forward.New(forward.Logger(oxyLogger), forward.PassHostHeader(frontend.PassHostHeader))
|
fwd, _ := forward.New(forward.Logger(oxyLogger), forward.PassHostHeader(frontend.PassHostHeader))
|
||||||
saveBackend := middlewares.NewSaveBackend(fwd)
|
saveBackend := middlewares.NewSaveBackend(fwd)
|
||||||
// default endpoints if not defined in frontends
|
|
||||||
if len(frontend.EntryPoints) == 0 {
|
|
||||||
frontend.EntryPoints = globalConfiguration.DefaultEntryPoints
|
|
||||||
}
|
|
||||||
if len(frontend.EntryPoints) == 0 {
|
if len(frontend.EntryPoints) == 0 {
|
||||||
log.Errorf("No entrypoint defined for frontend %s, defaultEntryPoints:%s", frontendName, globalConfiguration.DefaultEntryPoints)
|
log.Errorf("No entrypoint defined for frontend %s, defaultEntryPoints:%s", frontendName, globalConfiguration.DefaultEntryPoints)
|
||||||
log.Errorf("Skipping frontend %s...", frontendName)
|
log.Errorf("Skipping frontend %s...", frontendName)
|
||||||
|
|
Loading…
Reference in a new issue