From 847deeac7969ccfafe86c7c9c7828a1f41867aac Mon Sep 17 00:00:00 2001 From: Roy van de Water Date: Fri, 19 Feb 2016 14:55:23 -0800 Subject: [PATCH] Deterministic frontend registration Conflicts: server.go --- server.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index 530df5107..ef920f7c6 100644 --- a/server.go +++ b/server.go @@ -7,6 +7,7 @@ import ( "crypto/tls" "encoding/json" "errors" + log "github.com/Sirupsen/logrus" "github.com/codegangsta/negroni" "github.com/emilevauge/traefik/middlewares" @@ -23,6 +24,7 @@ import ( "os/signal" "reflect" "regexp" + "sort" "sync" "syscall" "time" @@ -312,7 +314,10 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo backends := map[string]http.Handler{} for _, configuration := range configurations { - for frontendName, frontend := range configuration.Frontends { + frontendNames := sortedFrontendNamesForConfig(configuration) + for _, frontendName := range frontendNames { + frontend := configuration.Frontends[frontendName] + log.Debugf("Creating frontend %s", frontendName) fwd, _ := forward.New(forward.Logger(oxyLogger), forward.PassHostHeader(frontend.PassHostHeader)) // default endpoints if not defined in frontends @@ -437,3 +442,15 @@ func (server *Server) buildDefaultHTTPRouter() *mux.Router { router.NotFoundHandler = http.HandlerFunc(notFoundHandler) return router } + +func sortedFrontendNamesForConfig(configuration *types.Configuration) []string { + keys := []string{} + + for key := range configuration.Frontends { + keys = append(keys, key) + } + + sort.Strings(keys) + + return keys +}