From de821fc305b63e6a4a831a2a5a51ec285daf5560 Mon Sep 17 00:00:00 2001 From: Emile Vauge Date: Mon, 23 Oct 2017 14:48:03 +0100 Subject: [PATCH] fix healthcheck path --- cmd/traefik/traefik.go | 49 ++++----------------------------- configuration/configuration.go | 50 ++++++++++++++++++++++++++++++++++ provider/web/web.go | 8 ------ server/server.go | 2 +- 4 files changed, 57 insertions(+), 52 deletions(-) diff --git a/cmd/traefik/traefik.go b/cmd/traefik/traefik.go index 84fd5af06..f8cc39df1 100644 --- a/cmd/traefik/traefik.go +++ b/cmd/traefik/traefik.go @@ -24,7 +24,6 @@ import ( "github.com/containous/traefik/log" "github.com/containous/traefik/provider/ecs" "github.com/containous/traefik/provider/kubernetes" - "github.com/containous/traefik/provider/rancher" "github.com/containous/traefik/safe" "github.com/containous/traefik/server" "github.com/containous/traefik/server/uuid" @@ -121,6 +120,8 @@ Complete documentation is available at https://traefik.io`, Config: traefikConfiguration, DefaultPointersConfig: traefikPointersConfiguration, Run: func() error { + traefikConfiguration.GlobalConfiguration.SetEffectiveConfiguration() + if traefikConfiguration.Web == nil { fmt.Println("Please enable the web provider to use healtcheck.") os.Exit(1) @@ -134,7 +135,8 @@ Complete documentation is available at https://traefik.io`, } client.Transport = tr } - resp, err := client.Head(protocol + "://" + traefikConfiguration.Web.Address + "/ping") + + resp, err := client.Head(protocol + "://" + traefikConfiguration.Web.Address + traefikConfiguration.Web.Path + "ping") if err != nil { fmt.Printf("Error calling healthcheck: %s\n", err) os.Exit(1) @@ -238,47 +240,7 @@ func run(globalConfiguration *configuration.GlobalConfiguration) { http.DefaultTransport.(*http.Transport).Proxy = http.ProxyFromEnvironment - if len(globalConfiguration.EntryPoints) == 0 { - globalConfiguration.EntryPoints = map[string]*configuration.EntryPoint{"http": { - Address: ":80", - ForwardedHeaders: &configuration.ForwardedHeaders{Insecure: true}, - }} - globalConfiguration.DefaultEntryPoints = []string{"http"} - } - - if globalConfiguration.Rancher != nil { - // Ensure backwards compatibility for now - if len(globalConfiguration.Rancher.AccessKey) > 0 || - len(globalConfiguration.Rancher.Endpoint) > 0 || - len(globalConfiguration.Rancher.SecretKey) > 0 { - - if globalConfiguration.Rancher.API == nil { - globalConfiguration.Rancher.API = &rancher.APIConfiguration{ - AccessKey: globalConfiguration.Rancher.AccessKey, - SecretKey: globalConfiguration.Rancher.SecretKey, - Endpoint: globalConfiguration.Rancher.Endpoint, - } - } - log.Warn("Deprecated configuration found: rancher.[accesskey|secretkey|endpoint]. " + - "Please use rancher.api.[accesskey|secretkey|endpoint] instead.") - } - - if globalConfiguration.Rancher.Metadata != nil && len(globalConfiguration.Rancher.Metadata.Prefix) == 0 { - globalConfiguration.Rancher.Metadata.Prefix = "latest" - } - } - - if globalConfiguration.Debug { - globalConfiguration.LogLevel = "DEBUG" - } - - // ForwardedHeaders must be remove in the next breaking version - for entryPointName := range globalConfiguration.EntryPoints { - entryPoint := globalConfiguration.EntryPoints[entryPointName] - if entryPoint.ForwardedHeaders == nil { - entryPoint.ForwardedHeaders = &configuration.ForwardedHeaders{Insecure: true} - } - } + globalConfiguration.SetEffectiveConfiguration() // logging level, err := logrus.ParseLevel(strings.ToLower(globalConfiguration.LogLevel)) @@ -286,6 +248,7 @@ func run(globalConfiguration *configuration.GlobalConfiguration) { log.Error("Error getting level", err) } log.SetLevel(level) + if len(globalConfiguration.TraefikLogsFile) > 0 { dir := filepath.Dir(globalConfiguration.TraefikLogsFile) diff --git a/configuration/configuration.go b/configuration/configuration.go index 6d7732dbe..04fe3b26c 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -80,6 +80,56 @@ type GlobalConfiguration struct { DynamoDB *dynamodb.Provider `description:"Enable DynamoDB backend with default settings" export:"true"` } +// SetEffectiveConfiguration adds missing configuration parameters derived from existing ones. +// It also takes care of maintaining backwards compatibility. +func (gc *GlobalConfiguration) SetEffectiveConfiguration() { + if len(gc.EntryPoints) == 0 { + gc.EntryPoints = map[string]*EntryPoint{"http": { + Address: ":80", + ForwardedHeaders: &ForwardedHeaders{Insecure: true}, + }} + gc.DefaultEntryPoints = []string{"http"} + } + + // ForwardedHeaders must be remove in the next breaking version + for entryPointName := range gc.EntryPoints { + entryPoint := gc.EntryPoints[entryPointName] + if entryPoint.ForwardedHeaders == nil { + entryPoint.ForwardedHeaders = &ForwardedHeaders{Insecure: true} + } + } + + if gc.Rancher != nil { + // Ensure backwards compatibility for now + if len(gc.Rancher.AccessKey) > 0 || + len(gc.Rancher.Endpoint) > 0 || + len(gc.Rancher.SecretKey) > 0 { + + if gc.Rancher.API == nil { + gc.Rancher.API = &rancher.APIConfiguration{ + AccessKey: gc.Rancher.AccessKey, + SecretKey: gc.Rancher.SecretKey, + Endpoint: gc.Rancher.Endpoint, + } + } + log.Warn("Deprecated configuration found: rancher.[accesskey|secretkey|endpoint]. " + + "Please use rancher.api.[accesskey|secretkey|endpoint] instead.") + } + + if gc.Rancher.Metadata != nil && len(gc.Rancher.Metadata.Prefix) == 0 { + gc.Rancher.Metadata.Prefix = "latest" + } + } + + if gc.Debug { + gc.LogLevel = "DEBUG" + } + + if gc.Web != nil && (gc.Web.Path == "" || !strings.HasSuffix(gc.Web.Path, "/")) { + gc.Web.Path += "/" + } +} + // DefaultEntryPoints holds default entry points type DefaultEntryPoints []string diff --git a/provider/web/web.go b/provider/web/web.go index dcbf42ecf..93e00d3ef 100644 --- a/provider/web/web.go +++ b/provider/web/web.go @@ -56,17 +56,9 @@ func goroutines() interface{} { // Provide allows the provider to provide configurations to traefik // using the given configuration channel. func (provider *Provider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool, _ types.Constraints) error { - systemRouter := mux.NewRouter() - if provider.Path == "" { - provider.Path = "/" - } - if provider.Path != "/" { - if provider.Path[len(provider.Path)-1:] != "/" { - provider.Path += "/" - } systemRouter.Methods("GET").Path("/").HandlerFunc(func(response http.ResponseWriter, request *http.Request) { http.Redirect(response, request, provider.Path, 302) }) diff --git a/server/server.go b/server/server.go index 7a8893d06..a1c9c63ed 100644 --- a/server/server.go +++ b/server/server.go @@ -337,7 +337,7 @@ func (server *Server) listenProviders(stop chan bool) { lastReceivedConfigurationValue := lastReceivedConfiguration.Get().(time.Time) providersThrottleDuration := time.Duration(server.globalConfiguration.ProvidersThrottleDuration) if time.Now().After(lastReceivedConfigurationValue.Add(providersThrottleDuration)) { - log.Debugf("Last %s config received more than %s, OK", configMsg.ProviderName, server.globalConfiguration.ProvidersThrottleDuration) + log.Debugf("Last %s config received more than %s, OK", configMsg.ProviderName, server.globalConfiguration.ProvidersThrottleDuration.String()) // last config received more than n s ago server.configurationValidatedChan <- configMsg } else {