refactor: some minor changes.

This commit is contained in:
Fernandez Ludovic 2018-02-19 01:04:45 +01:00 committed by Traefiker Bot
parent 529e34d2ae
commit b9d8eff994
9 changed files with 24 additions and 76 deletions

View file

@ -67,6 +67,7 @@ func runStoreConfig(kv *staert.KvSource, traefikConfiguration *TraefikConfigurat
return err
}
}
if traefikConfiguration.GlobalConfiguration.ACME != nil {
var object cluster.Object
if len(traefikConfiguration.GlobalConfiguration.ACME.StorageFile) > 0 {
@ -76,11 +77,14 @@ func runStoreConfig(kv *staert.KvSource, traefikConfiguration *TraefikConfigurat
if err != nil {
return err
}
} else {
// Create an empty account to create all the keys into the KV store
account := &acme.Account{}
account.Init()
err = account.Init()
if err != nil {
return err
}
object = account
}

View file

@ -32,10 +32,11 @@ import (
)
func main() {
//traefik config inits
// traefik config inits
traefikConfiguration := NewTraefikConfiguration()
traefikPointersConfiguration := NewTraefikDefaultPointersConfiguration()
//traefik Command init
// traefik Command init
traefikCmd := &flaeg.Command{
Name: "traefik",
Description: `traefik is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease.
@ -48,12 +49,12 @@ Complete documentation is available at https://traefik.io`,
},
}
//storeconfig Command init
// storeconfig Command init
storeConfigCmd := newStoreConfigCmd(traefikConfiguration, traefikPointersConfiguration)
//init flaeg source
// init flaeg source
f := flaeg.New(traefikCmd, os.Args[1:])
//add custom parsers
// add custom parsers
f.AddParser(reflect.TypeOf(configuration.EntryPoints{}), &configuration.EntryPoints{})
f.AddParser(reflect.TypeOf(configuration.DefaultEntryPoints{}), &configuration.DefaultEntryPoints{})
f.AddParser(reflect.TypeOf(traefikTls.RootCAs{}), &traefikTls.RootCAs{})
@ -63,7 +64,7 @@ Complete documentation is available at https://traefik.io`,
f.AddParser(reflect.TypeOf([]acme.Domain{}), &acme.Domains{})
f.AddParser(reflect.TypeOf(types.Buckets{}), &types.Buckets{})
//add commands
// add commands
f.AddCommand(newVersionCmd())
f.AddCommand(newBugCmd(traefikConfiguration, traefikPointersConfiguration))
f.AddCommand(storeConfigCmd)
@ -83,12 +84,12 @@ Complete documentation is available at https://traefik.io`,
os.Exit(-1)
}
//staert init
// staert init
s := staert.NewStaert(traefikCmd)
//init toml source
// init TOML source
toml := staert.NewTomlSource("traefik", []string{traefikConfiguration.ConfigFile, "/etc/traefik/", "$HOME/.traefik/", "."})
//add sources to staert
// add sources to staert
s.AddSource(toml)
s.AddSource(f)
if _, err := s.LoadConfig(); err != nil {
@ -105,7 +106,7 @@ Complete documentation is available at https://traefik.io`,
}
storeConfigCmd.Run = runStoreConfig(kv, traefikConfiguration)
// IF a KV Store is enable and no sub-command called in args
// if a KV Store is enable and no sub-command called in args
if kv != nil && usedCmd == traefikCmd {
if traefikConfiguration.Cluster == nil {
traefikConfiguration.Cluster = &types.Cluster{Node: uuid.Get()}
@ -223,10 +224,7 @@ func configureLogging(globalConfiguration *configuration.GlobalConfiguration) {
if globalConfiguration.TraefikLog != nil && globalConfiguration.TraefikLog.Format == "json" {
formatter = &logrus.JSONFormatter{}
} else {
disableColors := false
if len(logFile) > 0 {
disableColors = true
}
disableColors := len(logFile) > 0
formatter = &logrus.TextFormatter{DisableColors: disableColors, FullTimestamp: true, DisableSorting: true}
}
log.SetFormatter(formatter)
@ -234,8 +232,7 @@ func configureLogging(globalConfiguration *configuration.GlobalConfiguration) {
if len(logFile) > 0 {
dir := filepath.Dir(logFile)
err := os.MkdirAll(dir, 0755)
if err != nil {
if err := os.MkdirAll(dir, 0755); err != nil {
log.Errorf("Failed to create log path %s: %s", dir, err)
}

View file

@ -289,41 +289,6 @@ func (s *ConsulSuite) TestGlobalConfiguration(c *check.C) {
c.Assert(err, checker.IsNil)
}
func (s *ConsulSuite) skipTestGlobalConfigurationWithClientTLS(c *check.C) {
c.Skip("wait for relative path issue in the composefile")
s.setupConsulTLS(c)
consulHost := s.composeProject.Container(c, "consul").NetworkSettings.IPAddress
err := s.kv.Put("traefik/api/entrypoint", []byte("api"), nil)
c.Assert(err, checker.IsNil)
err = s.kv.Put("traefik/entrypoints/api/address", []byte(":8081"), nil)
c.Assert(err, checker.IsNil)
// wait for consul
err = try.Do(60*time.Second, try.KVExists(s.kv, "traefik/web/address"))
c.Assert(err, checker.IsNil)
// start traefik
cmd, display := s.traefikCmd(
withConfigFile("fixtures/simple_web.toml"),
"--consul",
"--consul.endpoint="+consulHost+":8585",
"--consul.tls.ca=resources/tls/ca.cert",
"--consul.tls.cert=resources/tls/consul.cert",
"--consul.tls.key=resources/tls/consul.key",
"--consul.tls.insecureskipverify")
defer display(c)
err = cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()
// wait for traefik
err = try.GetRequest("http://127.0.0.1:8081/api/providers", 60*time.Second)
c.Assert(err, checker.IsNil)
}
func (s *ConsulSuite) TestCommandStoreConfig(c *check.C) {
s.setupConsul(c)
consulHost := s.composeProject.Container(c, "consul").NetworkSettings.IPAddress

View file

@ -282,7 +282,7 @@ func CustomWriterLevel(level logrus.Level, maxScanTokenSize int) *io.PipeWriter
// extract from github.com/Sirupsen/logrus/writer.go
// Hack the buffer size
func writerScanner(reader *io.PipeReader, scanTokenSize int, printFunc func(args ...interface{})) {
func writerScanner(reader io.ReadCloser, scanTokenSize int, printFunc func(args ...interface{})) {
scanner := bufio.NewScanner(reader)
if scanTokenSize > bufio.MaxScanTokenSize {

View file

@ -19,7 +19,7 @@ func TestMetricsRetryListener(t *testing.T) {
wantCounterValue := float64(2)
if retryMetrics.retriesCounter.CounterValue != wantCounterValue {
t.Errorf("got counter value of %d, want %d", retryMetrics.retriesCounter.CounterValue, wantCounterValue)
t.Errorf("got counter value of %f, want %f", retryMetrics.retriesCounter.CounterValue, wantCounterValue)
}
wantLabelValues := []string{"backend", "backendName"}

View file

@ -174,7 +174,7 @@ func TestNewRegexHandler(t *testing.T) {
assert.Equal(t, test.expectedStatus, recorder.Code)
location, err := recorder.Result().Location()
require.Error(t, err, "ghf %v", location)
require.Errorf(t, err, "Location %v", location)
}
}
})

View file

@ -125,7 +125,7 @@ type retryResponseWriterWithoutCloseNotify struct {
}
func (rr *retryResponseWriterWithoutCloseNotify) ShouldRetry() bool {
return *rr.netErrorOccured == true && !rr.attemptsExhausted
return *rr.netErrorOccured && !rr.attemptsExhausted
}
func (rr *retryResponseWriterWithoutCloseNotify) Header() http.Header {

View file

@ -61,14 +61,6 @@ func withServiceLabel(key, value string, serviceName string) func(*marathon.Appl
}
}
func healthChecks(checks ...*marathon.HealthCheck) func(*marathon.Application) {
return func(app *marathon.Application) {
for _, check := range checks {
app.AddHealthCheck(*check)
}
}
}
func portDefinition(port int) func(*marathon.Application) {
return func(app *marathon.Application) {
app.AddPortDefinition(marathon.PortDefinition{
@ -194,16 +186,6 @@ func state(s TaskState) func(*marathon.Task) {
}
}
func healthCheckResultLiveness(alive ...bool) func(*marathon.Task) {
return func(t *marathon.Task) {
for _, a := range alive {
t.HealthCheckResults = append(t.HealthCheckResults, &marathon.HealthCheckResult{
Alive: a,
})
}
}
}
func startedAt(timestamp string) func(*marathon.Task) {
return func(t *marathon.Task) {
t.StartedAt = timestamp

View file

@ -1315,7 +1315,7 @@ func TestGetSticky(t *testing.T) {
t.Parallel()
actual := getSticky(test.application)
if actual != test.expected {
t.Errorf("actual %q, expected %q", actual, test.expected)
t.Errorf("actual %v, expected %v", actual, test.expected)
}
})
}