Merge pull request #214 from octoblu/add-frontend-determinism

Deterministic frontend registration
This commit is contained in:
Vincent Demeester 2016-02-24 00:05:03 +01:00
commit 7acc2beae0

View file

@ -7,6 +7,7 @@ import (
"crypto/tls" "crypto/tls"
"encoding/json" "encoding/json"
"errors" "errors"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/codegangsta/negroni" "github.com/codegangsta/negroni"
"github.com/emilevauge/traefik/middlewares" "github.com/emilevauge/traefik/middlewares"
@ -23,6 +24,7 @@ import (
"os/signal" "os/signal"
"reflect" "reflect"
"regexp" "regexp"
"sort"
"sync" "sync"
"syscall" "syscall"
"time" "time"
@ -312,7 +314,10 @@ func (server *Server) loadConfig(configurations configs, globalConfiguration Glo
backends := map[string]http.Handler{} backends := map[string]http.Handler{}
for _, configuration := range configurations { 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) 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))
// default endpoints if not defined in frontends // default endpoints if not defined in frontends
@ -437,3 +442,15 @@ func (server *Server) buildDefaultHTTPRouter() *mux.Router {
router.NotFoundHandler = http.HandlerFunc(notFoundHandler) router.NotFoundHandler = http.HandlerFunc(notFoundHandler)
return router return router
} }
func sortedFrontendNamesForConfig(configuration *types.Configuration) []string {
keys := []string{}
for key := range configuration.Frontends {
keys = append(keys, key)
}
sort.Strings(keys)
return keys
}