2018-03-01 07:10:04 +00:00
|
|
|
package cmd
|
2017-08-25 14:10:03 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2018-07-31 17:28:03 +00:00
|
|
|
"github.com/containous/flaeg/parse"
|
2019-03-15 08:42:03 +00:00
|
|
|
"github.com/containous/traefik/pkg/config/static"
|
2019-03-18 10:30:07 +00:00
|
|
|
"github.com/containous/traefik/pkg/middlewares/accesslog"
|
2019-03-15 08:42:03 +00:00
|
|
|
"github.com/containous/traefik/pkg/ping"
|
|
|
|
"github.com/containous/traefik/pkg/provider/docker"
|
|
|
|
"github.com/containous/traefik/pkg/provider/file"
|
|
|
|
"github.com/containous/traefik/pkg/provider/kubernetes/ingress"
|
|
|
|
"github.com/containous/traefik/pkg/provider/marathon"
|
|
|
|
"github.com/containous/traefik/pkg/provider/rest"
|
|
|
|
"github.com/containous/traefik/pkg/tracing/datadog"
|
|
|
|
"github.com/containous/traefik/pkg/tracing/instana"
|
|
|
|
"github.com/containous/traefik/pkg/tracing/jaeger"
|
|
|
|
"github.com/containous/traefik/pkg/tracing/zipkin"
|
|
|
|
"github.com/containous/traefik/pkg/types"
|
2019-02-05 17:20:03 +00:00
|
|
|
jaegercli "github.com/uber/jaeger-client-go"
|
2017-08-25 14:10:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TraefikConfiguration holds GlobalConfiguration and other stuff
|
|
|
|
type TraefikConfiguration struct {
|
2018-11-27 16:42:04 +00:00
|
|
|
static.Configuration `mapstructure:",squash" export:"true"`
|
|
|
|
ConfigFile string `short:"c" description:"Configuration file to use (TOML)." export:"true"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTraefikConfiguration creates a TraefikConfiguration with default values
|
|
|
|
func NewTraefikConfiguration() *TraefikConfiguration {
|
|
|
|
return &TraefikConfiguration{
|
|
|
|
Configuration: static.Configuration{
|
|
|
|
Global: &static.Global{
|
2019-03-14 18:32:03 +00:00
|
|
|
CheckNewVersion: true,
|
2018-11-27 16:42:04 +00:00
|
|
|
},
|
|
|
|
EntryPoints: make(static.EntryPoints),
|
|
|
|
Providers: &static.Providers{
|
|
|
|
ProvidersThrottleDuration: parse.Duration(2 * time.Second),
|
|
|
|
},
|
|
|
|
ServersTransport: &static.ServersTransport{
|
|
|
|
MaxIdleConnsPerHost: 200,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ConfigFile: "",
|
|
|
|
}
|
2017-08-25 14:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTraefikDefaultPointersConfiguration creates a TraefikConfiguration with pointers default values
|
|
|
|
func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
|
|
|
|
// default File
|
|
|
|
var defaultFile file.Provider
|
|
|
|
defaultFile.Watch = true
|
2018-03-23 12:30:03 +00:00
|
|
|
defaultFile.Filename = "" // needs equivalent to viper.ConfigFileUsed()
|
2017-08-25 14:10:03 +00:00
|
|
|
|
2017-11-09 15:12:04 +00:00
|
|
|
// default Ping
|
|
|
|
var defaultPing = ping.Handler{
|
|
|
|
EntryPoint: "traefik",
|
|
|
|
}
|
|
|
|
|
2017-09-21 08:42:02 +00:00
|
|
|
// default TraefikLog
|
|
|
|
defaultTraefikLog := types.TraefikLog{
|
|
|
|
Format: "common",
|
|
|
|
FilePath: "",
|
|
|
|
}
|
|
|
|
|
2017-08-25 14:10:03 +00:00
|
|
|
// default AccessLog
|
|
|
|
defaultAccessLog := types.AccessLog{
|
|
|
|
Format: accesslog.CommonFormat,
|
|
|
|
FilePath: "",
|
2018-03-14 13:12:04 +00:00
|
|
|
Filters: &types.AccessLogFilters{},
|
|
|
|
Fields: &types.AccessLogFields{
|
|
|
|
DefaultMode: types.AccessLogKeep,
|
|
|
|
Headers: &types.FieldHeaders{
|
|
|
|
DefaultMode: types.AccessLogKeep,
|
|
|
|
},
|
|
|
|
},
|
2017-08-25 14:10:03 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 16:48:04 +00:00
|
|
|
// default Tracing
|
2018-11-27 16:42:04 +00:00
|
|
|
defaultTracing := static.Tracing{
|
2018-07-31 22:16:03 +00:00
|
|
|
Backend: "jaeger",
|
|
|
|
ServiceName: "traefik",
|
|
|
|
SpanNameLimit: 0,
|
2018-01-10 16:48:04 +00:00
|
|
|
Jaeger: &jaeger.Config{
|
2019-02-05 17:20:03 +00:00
|
|
|
SamplingServerURL: "http://localhost:5778/sampling",
|
|
|
|
SamplingType: "const",
|
|
|
|
SamplingParam: 1.0,
|
|
|
|
LocalAgentHostPort: "127.0.0.1:6831",
|
|
|
|
Propagation: "jaeger",
|
|
|
|
Gen128Bit: false,
|
|
|
|
TraceContextHeaderName: jaegercli.TraceContextHeaderName,
|
2018-01-10 16:48:04 +00:00
|
|
|
},
|
|
|
|
Zipkin: &zipkin.Config{
|
|
|
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
|
|
|
SameSpan: false,
|
|
|
|
ID128Bit: true,
|
|
|
|
Debug: false,
|
2018-10-09 08:18:02 +00:00
|
|
|
SampleRate: 1.0,
|
2018-01-10 16:48:04 +00:00
|
|
|
},
|
2018-07-31 22:16:03 +00:00
|
|
|
DataDog: &datadog.Config{
|
|
|
|
LocalAgentHostPort: "localhost:8126",
|
|
|
|
GlobalTag: "",
|
|
|
|
Debug: false,
|
2019-01-16 16:08:06 +00:00
|
|
|
PrioritySampling: false,
|
2018-07-31 22:16:03 +00:00
|
|
|
},
|
2019-02-18 15:52:04 +00:00
|
|
|
Instana: &instana.Config{
|
|
|
|
LocalAgentHost: "localhost",
|
|
|
|
LocalAgentPort: 42699,
|
|
|
|
LogLevel: "info",
|
|
|
|
},
|
2018-01-10 16:48:04 +00:00
|
|
|
}
|
|
|
|
|
2017-11-09 15:12:04 +00:00
|
|
|
// default ApiConfiguration
|
2018-11-27 16:42:04 +00:00
|
|
|
defaultAPI := static.API{
|
2017-11-09 15:12:04 +00:00
|
|
|
EntryPoint: "traefik",
|
|
|
|
Dashboard: true,
|
|
|
|
}
|
|
|
|
defaultAPI.Statistics = &types.Statistics{
|
|
|
|
RecentErrors: 10,
|
|
|
|
}
|
|
|
|
|
|
|
|
// default Metrics
|
|
|
|
defaultMetrics := types.Metrics{
|
|
|
|
Prometheus: &types.Prometheus{
|
|
|
|
Buckets: types.Buckets{0.1, 0.3, 1.2, 5},
|
2019-03-18 10:30:07 +00:00
|
|
|
EntryPoint: static.DefaultInternalEntryPointName,
|
2017-11-09 15:12:04 +00:00
|
|
|
},
|
|
|
|
Datadog: &types.Datadog{
|
|
|
|
Address: "localhost:8125",
|
|
|
|
PushInterval: "10s",
|
|
|
|
},
|
|
|
|
StatsD: &types.Statsd{
|
|
|
|
Address: "localhost:8125",
|
|
|
|
PushInterval: "10s",
|
|
|
|
},
|
|
|
|
InfluxDB: &types.InfluxDB{
|
|
|
|
Address: "localhost:8089",
|
2018-05-29 20:58:03 +00:00
|
|
|
Protocol: "udp",
|
2017-11-09 15:12:04 +00:00
|
|
|
PushInterval: "10s",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-01-30 15:24:07 +00:00
|
|
|
defaultResolver := types.HostResolverConfig{
|
2018-07-03 14:44:05 +00:00
|
|
|
CnameFlattening: false,
|
|
|
|
ResolvConfig: "/etc/resolv.conf",
|
|
|
|
ResolvDepth: 5,
|
|
|
|
}
|
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
var defaultDocker docker.Provider
|
|
|
|
defaultDocker.Watch = true
|
|
|
|
defaultDocker.ExposedByDefault = true
|
|
|
|
defaultDocker.Endpoint = "unix:///var/run/docker.sock"
|
|
|
|
defaultDocker.SwarmMode = false
|
2018-11-27 16:44:04 +00:00
|
|
|
defaultDocker.SwarmModeRefreshSeconds = 15
|
2019-01-21 18:06:02 +00:00
|
|
|
defaultDocker.DefaultRule = docker.DefaultTemplateRule
|
2017-08-25 14:10:03 +00:00
|
|
|
|
2018-11-27 16:42:04 +00:00
|
|
|
// default Rest
|
|
|
|
var defaultRest rest.Provider
|
2019-03-18 10:30:07 +00:00
|
|
|
defaultRest.EntryPoint = static.DefaultInternalEntryPointName
|
2018-11-27 16:42:04 +00:00
|
|
|
|
|
|
|
// default Marathon
|
|
|
|
var defaultMarathon marathon.Provider
|
|
|
|
defaultMarathon.Watch = true
|
|
|
|
defaultMarathon.Endpoint = "http://127.0.0.1:8080"
|
|
|
|
defaultMarathon.ExposedByDefault = true
|
|
|
|
defaultMarathon.DialerTimeout = parse.Duration(5 * time.Second)
|
|
|
|
defaultMarathon.ResponseHeaderTimeout = parse.Duration(60 * time.Second)
|
|
|
|
defaultMarathon.TLSHandshakeTimeout = parse.Duration(5 * time.Second)
|
|
|
|
defaultMarathon.KeepAlive = parse.Duration(10 * time.Second)
|
2019-01-29 16:54:05 +00:00
|
|
|
defaultMarathon.DefaultRule = marathon.DefaultTemplateRule
|
2018-11-27 16:42:04 +00:00
|
|
|
|
|
|
|
// default Kubernetes
|
2019-03-14 14:56:06 +00:00
|
|
|
var defaultKubernetes ingress.Provider
|
2018-11-27 16:42:04 +00:00
|
|
|
defaultKubernetes.Watch = true
|
|
|
|
|
|
|
|
defaultProviders := static.Providers{
|
2019-03-18 10:30:07 +00:00
|
|
|
File: &defaultFile,
|
|
|
|
Docker: &defaultDocker,
|
|
|
|
Rest: &defaultRest,
|
|
|
|
Marathon: &defaultMarathon,
|
|
|
|
Kubernetes: &defaultKubernetes,
|
2017-08-25 14:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &TraefikConfiguration{
|
2018-11-27 16:42:04 +00:00
|
|
|
Configuration: static.Configuration{
|
|
|
|
Providers: &defaultProviders,
|
|
|
|
Log: &defaultTraefikLog,
|
|
|
|
AccessLog: &defaultAccessLog,
|
|
|
|
Ping: &defaultPing,
|
|
|
|
API: &defaultAPI,
|
|
|
|
Metrics: &defaultMetrics,
|
|
|
|
Tracing: &defaultTracing,
|
|
|
|
HostResolver: &defaultResolver,
|
2017-08-25 14:10:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|