refactor: some minor changes.
This commit is contained in:
parent
529e34d2ae
commit
b9d8eff994
9 changed files with 24 additions and 76 deletions
|
@ -67,6 +67,7 @@ func runStoreConfig(kv *staert.KvSource, traefikConfiguration *TraefikConfigurat
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if traefikConfiguration.GlobalConfiguration.ACME != nil {
|
if traefikConfiguration.GlobalConfiguration.ACME != nil {
|
||||||
var object cluster.Object
|
var object cluster.Object
|
||||||
if len(traefikConfiguration.GlobalConfiguration.ACME.StorageFile) > 0 {
|
if len(traefikConfiguration.GlobalConfiguration.ACME.StorageFile) > 0 {
|
||||||
|
@ -76,11 +77,14 @@ func runStoreConfig(kv *staert.KvSource, traefikConfiguration *TraefikConfigurat
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Create an empty account to create all the keys into the KV store
|
// Create an empty account to create all the keys into the KV store
|
||||||
account := &acme.Account{}
|
account := &acme.Account{}
|
||||||
account.Init()
|
err = account.Init()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
object = account
|
object = account
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
//traefik config inits
|
// traefik config inits
|
||||||
traefikConfiguration := NewTraefikConfiguration()
|
traefikConfiguration := NewTraefikConfiguration()
|
||||||
traefikPointersConfiguration := NewTraefikDefaultPointersConfiguration()
|
traefikPointersConfiguration := NewTraefikDefaultPointersConfiguration()
|
||||||
//traefik Command init
|
|
||||||
|
// traefik Command init
|
||||||
traefikCmd := &flaeg.Command{
|
traefikCmd := &flaeg.Command{
|
||||||
Name: "traefik",
|
Name: "traefik",
|
||||||
Description: `traefik is a modern HTTP reverse proxy and load balancer made to deploy microservices with ease.
|
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)
|
storeConfigCmd := newStoreConfigCmd(traefikConfiguration, traefikPointersConfiguration)
|
||||||
|
|
||||||
//init flaeg source
|
// init flaeg source
|
||||||
f := flaeg.New(traefikCmd, os.Args[1:])
|
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.EntryPoints{}), &configuration.EntryPoints{})
|
||||||
f.AddParser(reflect.TypeOf(configuration.DefaultEntryPoints{}), &configuration.DefaultEntryPoints{})
|
f.AddParser(reflect.TypeOf(configuration.DefaultEntryPoints{}), &configuration.DefaultEntryPoints{})
|
||||||
f.AddParser(reflect.TypeOf(traefikTls.RootCAs{}), &traefikTls.RootCAs{})
|
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([]acme.Domain{}), &acme.Domains{})
|
||||||
f.AddParser(reflect.TypeOf(types.Buckets{}), &types.Buckets{})
|
f.AddParser(reflect.TypeOf(types.Buckets{}), &types.Buckets{})
|
||||||
|
|
||||||
//add commands
|
// add commands
|
||||||
f.AddCommand(newVersionCmd())
|
f.AddCommand(newVersionCmd())
|
||||||
f.AddCommand(newBugCmd(traefikConfiguration, traefikPointersConfiguration))
|
f.AddCommand(newBugCmd(traefikConfiguration, traefikPointersConfiguration))
|
||||||
f.AddCommand(storeConfigCmd)
|
f.AddCommand(storeConfigCmd)
|
||||||
|
@ -83,12 +84,12 @@ Complete documentation is available at https://traefik.io`,
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
//staert init
|
// staert init
|
||||||
s := staert.NewStaert(traefikCmd)
|
s := staert.NewStaert(traefikCmd)
|
||||||
//init toml source
|
// init TOML source
|
||||||
toml := staert.NewTomlSource("traefik", []string{traefikConfiguration.ConfigFile, "/etc/traefik/", "$HOME/.traefik/", "."})
|
toml := staert.NewTomlSource("traefik", []string{traefikConfiguration.ConfigFile, "/etc/traefik/", "$HOME/.traefik/", "."})
|
||||||
|
|
||||||
//add sources to staert
|
// add sources to staert
|
||||||
s.AddSource(toml)
|
s.AddSource(toml)
|
||||||
s.AddSource(f)
|
s.AddSource(f)
|
||||||
if _, err := s.LoadConfig(); err != nil {
|
if _, err := s.LoadConfig(); err != nil {
|
||||||
|
@ -105,7 +106,7 @@ Complete documentation is available at https://traefik.io`,
|
||||||
}
|
}
|
||||||
storeConfigCmd.Run = runStoreConfig(kv, traefikConfiguration)
|
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 kv != nil && usedCmd == traefikCmd {
|
||||||
if traefikConfiguration.Cluster == nil {
|
if traefikConfiguration.Cluster == nil {
|
||||||
traefikConfiguration.Cluster = &types.Cluster{Node: uuid.Get()}
|
traefikConfiguration.Cluster = &types.Cluster{Node: uuid.Get()}
|
||||||
|
@ -223,10 +224,7 @@ func configureLogging(globalConfiguration *configuration.GlobalConfiguration) {
|
||||||
if globalConfiguration.TraefikLog != nil && globalConfiguration.TraefikLog.Format == "json" {
|
if globalConfiguration.TraefikLog != nil && globalConfiguration.TraefikLog.Format == "json" {
|
||||||
formatter = &logrus.JSONFormatter{}
|
formatter = &logrus.JSONFormatter{}
|
||||||
} else {
|
} else {
|
||||||
disableColors := false
|
disableColors := len(logFile) > 0
|
||||||
if len(logFile) > 0 {
|
|
||||||
disableColors = true
|
|
||||||
}
|
|
||||||
formatter = &logrus.TextFormatter{DisableColors: disableColors, FullTimestamp: true, DisableSorting: true}
|
formatter = &logrus.TextFormatter{DisableColors: disableColors, FullTimestamp: true, DisableSorting: true}
|
||||||
}
|
}
|
||||||
log.SetFormatter(formatter)
|
log.SetFormatter(formatter)
|
||||||
|
@ -234,8 +232,7 @@ func configureLogging(globalConfiguration *configuration.GlobalConfiguration) {
|
||||||
if len(logFile) > 0 {
|
if len(logFile) > 0 {
|
||||||
dir := filepath.Dir(logFile)
|
dir := filepath.Dir(logFile)
|
||||||
|
|
||||||
err := os.MkdirAll(dir, 0755)
|
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to create log path %s: %s", dir, err)
|
log.Errorf("Failed to create log path %s: %s", dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -289,41 +289,6 @@ func (s *ConsulSuite) TestGlobalConfiguration(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
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) {
|
func (s *ConsulSuite) TestCommandStoreConfig(c *check.C) {
|
||||||
s.setupConsul(c)
|
s.setupConsul(c)
|
||||||
consulHost := s.composeProject.Container(c, "consul").NetworkSettings.IPAddress
|
consulHost := s.composeProject.Container(c, "consul").NetworkSettings.IPAddress
|
||||||
|
|
|
@ -282,7 +282,7 @@ func CustomWriterLevel(level logrus.Level, maxScanTokenSize int) *io.PipeWriter
|
||||||
|
|
||||||
// extract from github.com/Sirupsen/logrus/writer.go
|
// extract from github.com/Sirupsen/logrus/writer.go
|
||||||
// Hack the buffer size
|
// 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)
|
scanner := bufio.NewScanner(reader)
|
||||||
|
|
||||||
if scanTokenSize > bufio.MaxScanTokenSize {
|
if scanTokenSize > bufio.MaxScanTokenSize {
|
||||||
|
|
|
@ -19,7 +19,7 @@ func TestMetricsRetryListener(t *testing.T) {
|
||||||
|
|
||||||
wantCounterValue := float64(2)
|
wantCounterValue := float64(2)
|
||||||
if retryMetrics.retriesCounter.CounterValue != wantCounterValue {
|
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"}
|
wantLabelValues := []string{"backend", "backendName"}
|
||||||
|
|
|
@ -174,7 +174,7 @@ func TestNewRegexHandler(t *testing.T) {
|
||||||
assert.Equal(t, test.expectedStatus, recorder.Code)
|
assert.Equal(t, test.expectedStatus, recorder.Code)
|
||||||
|
|
||||||
location, err := recorder.Result().Location()
|
location, err := recorder.Result().Location()
|
||||||
require.Error(t, err, "ghf %v", location)
|
require.Errorf(t, err, "Location %v", location)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -125,7 +125,7 @@ type retryResponseWriterWithoutCloseNotify struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *retryResponseWriterWithoutCloseNotify) ShouldRetry() bool {
|
func (rr *retryResponseWriterWithoutCloseNotify) ShouldRetry() bool {
|
||||||
return *rr.netErrorOccured == true && !rr.attemptsExhausted
|
return *rr.netErrorOccured && !rr.attemptsExhausted
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *retryResponseWriterWithoutCloseNotify) Header() http.Header {
|
func (rr *retryResponseWriterWithoutCloseNotify) Header() http.Header {
|
||||||
|
|
|
@ -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) {
|
func portDefinition(port int) func(*marathon.Application) {
|
||||||
return func(app *marathon.Application) {
|
return func(app *marathon.Application) {
|
||||||
app.AddPortDefinition(marathon.PortDefinition{
|
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) {
|
func startedAt(timestamp string) func(*marathon.Task) {
|
||||||
return func(t *marathon.Task) {
|
return func(t *marathon.Task) {
|
||||||
t.StartedAt = timestamp
|
t.StartedAt = timestamp
|
||||||
|
|
|
@ -1315,7 +1315,7 @@ func TestGetSticky(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
actual := getSticky(test.application)
|
actual := getSticky(test.application)
|
||||||
if actual != test.expected {
|
if actual != test.expected {
|
||||||
t.Errorf("actual %q, expected %q", actual, test.expected)
|
t.Errorf("actual %v, expected %v", actual, test.expected)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue