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"
"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
}