2018-03-01 07:10:04 +00:00
|
|
|
package cmd
|
2017-08-25 14:10:03 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/containous/flaeg"
|
2017-11-27 13:26:04 +00:00
|
|
|
"github.com/containous/traefik-extra-service-fabric"
|
2017-11-09 15:12:04 +00:00
|
|
|
"github.com/containous/traefik/api"
|
2017-08-25 14:10:03 +00:00
|
|
|
"github.com/containous/traefik/configuration"
|
|
|
|
"github.com/containous/traefik/middlewares/accesslog"
|
2018-01-10 16:48:04 +00:00
|
|
|
"github.com/containous/traefik/middlewares/tracing"
|
|
|
|
"github.com/containous/traefik/middlewares/tracing/jaeger"
|
|
|
|
"github.com/containous/traefik/middlewares/tracing/zipkin"
|
2017-11-09 15:12:04 +00:00
|
|
|
"github.com/containous/traefik/ping"
|
2017-08-25 14:10:03 +00:00
|
|
|
"github.com/containous/traefik/provider/boltdb"
|
|
|
|
"github.com/containous/traefik/provider/consul"
|
2018-01-04 14:56:03 +00:00
|
|
|
"github.com/containous/traefik/provider/consulcatalog"
|
2017-08-25 14:10:03 +00:00
|
|
|
"github.com/containous/traefik/provider/docker"
|
|
|
|
"github.com/containous/traefik/provider/dynamodb"
|
|
|
|
"github.com/containous/traefik/provider/ecs"
|
|
|
|
"github.com/containous/traefik/provider/etcd"
|
2017-09-11 17:10:04 +00:00
|
|
|
"github.com/containous/traefik/provider/eureka"
|
2017-08-25 14:10:03 +00:00
|
|
|
"github.com/containous/traefik/provider/file"
|
|
|
|
"github.com/containous/traefik/provider/kubernetes"
|
|
|
|
"github.com/containous/traefik/provider/marathon"
|
|
|
|
"github.com/containous/traefik/provider/mesos"
|
|
|
|
"github.com/containous/traefik/provider/rancher"
|
2017-11-09 15:12:04 +00:00
|
|
|
"github.com/containous/traefik/provider/rest"
|
2017-08-25 14:10:03 +00:00
|
|
|
"github.com/containous/traefik/provider/zk"
|
|
|
|
"github.com/containous/traefik/types"
|
2017-11-27 13:26:04 +00:00
|
|
|
sf "github.com/jjcollinge/servicefabric"
|
2017-08-25 14:10:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TraefikConfiguration holds GlobalConfiguration and other stuff
|
|
|
|
type TraefikConfiguration struct {
|
2017-10-02 08:32:02 +00:00
|
|
|
configuration.GlobalConfiguration `mapstructure:",squash" export:"true"`
|
|
|
|
ConfigFile string `short:"c" description:"Configuration file to use (TOML)." export:"true"`
|
2017-08-25 14:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewTraefikDefaultPointersConfiguration creates a TraefikConfiguration with pointers default values
|
|
|
|
func NewTraefikDefaultPointersConfiguration() *TraefikConfiguration {
|
2018-03-23 12:30:03 +00:00
|
|
|
// default Docker
|
2017-08-25 14:10:03 +00:00
|
|
|
var defaultDocker docker.Provider
|
|
|
|
defaultDocker.Watch = true
|
|
|
|
defaultDocker.ExposedByDefault = true
|
|
|
|
defaultDocker.Endpoint = "unix:///var/run/docker.sock"
|
|
|
|
defaultDocker.SwarmMode = false
|
|
|
|
|
|
|
|
// 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 Rest
|
|
|
|
var defaultRest rest.Provider
|
|
|
|
defaultRest.EntryPoint = configuration.DefaultInternalEntryPointName
|
|
|
|
|
|
|
|
// TODO: Deprecated - Web provider, use REST provider instead
|
|
|
|
var defaultWeb configuration.WebCompatibility
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultWeb.Address = ":8080"
|
|
|
|
defaultWeb.Statistics = &types.Statistics{
|
|
|
|
RecentErrors: 10,
|
|
|
|
}
|
|
|
|
|
2017-11-09 15:12:04 +00:00
|
|
|
// TODO: Deprecated - default Metrics
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultWeb.Metrics = &types.Metrics{
|
|
|
|
Prometheus: &types.Prometheus{
|
2018-01-19 13:30:04 +00:00
|
|
|
Buckets: types.Buckets{0.1, 0.3, 1.2, 5},
|
|
|
|
EntryPoint: configuration.DefaultInternalEntryPointName,
|
2017-08-25 14:10:03 +00:00
|
|
|
},
|
|
|
|
Datadog: &types.Datadog{
|
|
|
|
Address: "localhost:8125",
|
|
|
|
PushInterval: "10s",
|
|
|
|
},
|
|
|
|
StatsD: &types.Statsd{
|
|
|
|
Address: "localhost:8125",
|
|
|
|
PushInterval: "10s",
|
|
|
|
},
|
2017-11-08 14:14:03 +00:00
|
|
|
InfluxDB: &types.InfluxDB{
|
|
|
|
Address: "localhost:8089",
|
2018-05-29 20:58:03 +00:00
|
|
|
Protocol: "udp",
|
2017-11-08 14:14:03 +00:00
|
|
|
PushInterval: "10s",
|
|
|
|
},
|
2017-08-25 14:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// default Marathon
|
|
|
|
var defaultMarathon marathon.Provider
|
|
|
|
defaultMarathon.Watch = true
|
|
|
|
defaultMarathon.Endpoint = "http://127.0.0.1:8080"
|
|
|
|
defaultMarathon.ExposedByDefault = true
|
|
|
|
defaultMarathon.Constraints = types.Constraints{}
|
2018-05-22 20:38:03 +00:00
|
|
|
defaultMarathon.DialerTimeout = flaeg.Duration(5 * time.Second)
|
|
|
|
defaultMarathon.ResponseHeaderTimeout = flaeg.Duration(60 * time.Second)
|
|
|
|
defaultMarathon.TLSHandshakeTimeout = flaeg.Duration(5 * time.Second)
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultMarathon.KeepAlive = flaeg.Duration(10 * time.Second)
|
|
|
|
|
|
|
|
// default Consul
|
|
|
|
var defaultConsul consul.Provider
|
|
|
|
defaultConsul.Watch = true
|
|
|
|
defaultConsul.Endpoint = "127.0.0.1:8500"
|
|
|
|
defaultConsul.Prefix = "traefik"
|
|
|
|
defaultConsul.Constraints = types.Constraints{}
|
|
|
|
|
|
|
|
// default CatalogProvider
|
2018-01-04 14:56:03 +00:00
|
|
|
var defaultConsulCatalog consulcatalog.Provider
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultConsulCatalog.Endpoint = "127.0.0.1:8500"
|
2017-08-25 15:32:03 +00:00
|
|
|
defaultConsulCatalog.ExposedByDefault = true
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultConsulCatalog.Constraints = types.Constraints{}
|
|
|
|
defaultConsulCatalog.Prefix = "traefik"
|
|
|
|
defaultConsulCatalog.FrontEndRule = "Host:{{.ServiceName}}.{{.Domain}}"
|
|
|
|
|
|
|
|
// default Etcd
|
|
|
|
var defaultEtcd etcd.Provider
|
|
|
|
defaultEtcd.Watch = true
|
|
|
|
defaultEtcd.Endpoint = "127.0.0.1:2379"
|
|
|
|
defaultEtcd.Prefix = "/traefik"
|
|
|
|
defaultEtcd.Constraints = types.Constraints{}
|
|
|
|
|
2018-03-23 12:30:03 +00:00
|
|
|
// default Zookeeper
|
2017-08-25 14:10:03 +00:00
|
|
|
var defaultZookeeper zk.Provider
|
|
|
|
defaultZookeeper.Watch = true
|
|
|
|
defaultZookeeper.Endpoint = "127.0.0.1:2181"
|
2017-12-18 08:22:03 +00:00
|
|
|
defaultZookeeper.Prefix = "traefik"
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultZookeeper.Constraints = types.Constraints{}
|
|
|
|
|
2018-03-23 12:30:03 +00:00
|
|
|
// default Boltdb
|
2017-08-25 14:10:03 +00:00
|
|
|
var defaultBoltDb boltdb.Provider
|
|
|
|
defaultBoltDb.Watch = true
|
|
|
|
defaultBoltDb.Endpoint = "127.0.0.1:4001"
|
|
|
|
defaultBoltDb.Prefix = "/traefik"
|
|
|
|
defaultBoltDb.Constraints = types.Constraints{}
|
|
|
|
|
2018-03-23 12:30:03 +00:00
|
|
|
// default Kubernetes
|
2017-08-25 14:10:03 +00:00
|
|
|
var defaultKubernetes kubernetes.Provider
|
|
|
|
defaultKubernetes.Watch = true
|
|
|
|
defaultKubernetes.Constraints = types.Constraints{}
|
|
|
|
|
|
|
|
// default Mesos
|
|
|
|
var defaultMesos mesos.Provider
|
|
|
|
defaultMesos.Watch = true
|
|
|
|
defaultMesos.Endpoint = "http://127.0.0.1:5050"
|
|
|
|
defaultMesos.ExposedByDefault = true
|
|
|
|
defaultMesos.Constraints = types.Constraints{}
|
|
|
|
defaultMesos.RefreshSeconds = 30
|
|
|
|
defaultMesos.ZkDetectionTimeout = 30
|
|
|
|
defaultMesos.StateTimeoutSecond = 30
|
|
|
|
|
2018-03-23 12:30:03 +00:00
|
|
|
// default ECS
|
2017-08-25 14:10:03 +00:00
|
|
|
var defaultECS ecs.Provider
|
|
|
|
defaultECS.Watch = true
|
|
|
|
defaultECS.ExposedByDefault = true
|
|
|
|
defaultECS.AutoDiscoverClusters = false
|
|
|
|
defaultECS.Clusters = ecs.Clusters{"default"}
|
|
|
|
defaultECS.RefreshSeconds = 15
|
|
|
|
defaultECS.Constraints = types.Constraints{}
|
|
|
|
|
2018-03-23 12:30:03 +00:00
|
|
|
// default Rancher
|
2017-08-25 14:10:03 +00:00
|
|
|
var defaultRancher rancher.Provider
|
|
|
|
defaultRancher.Watch = true
|
|
|
|
defaultRancher.ExposedByDefault = true
|
|
|
|
defaultRancher.RefreshSeconds = 15
|
|
|
|
|
|
|
|
// default DynamoDB
|
|
|
|
var defaultDynamoDB dynamodb.Provider
|
|
|
|
defaultDynamoDB.Constraints = types.Constraints{}
|
|
|
|
defaultDynamoDB.RefreshSeconds = 15
|
|
|
|
defaultDynamoDB.TableName = "traefik"
|
|
|
|
defaultDynamoDB.Watch = true
|
|
|
|
|
2017-09-11 17:10:04 +00:00
|
|
|
// default Eureka
|
|
|
|
var defaultEureka eureka.Provider
|
2018-03-07 09:46:04 +00:00
|
|
|
defaultEureka.RefreshSeconds = flaeg.Duration(30 * time.Second)
|
2017-09-11 17:10:04 +00:00
|
|
|
|
2017-11-27 13:26:04 +00:00
|
|
|
// default ServiceFabric
|
|
|
|
var defaultServiceFabric servicefabric.Provider
|
|
|
|
defaultServiceFabric.APIVersion = sf.DefaultAPIVersion
|
|
|
|
defaultServiceFabric.RefreshSeconds = 10
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-09-20 16:14:03 +00:00
|
|
|
// default HealthCheckConfig
|
|
|
|
healthCheck := configuration.HealthCheckConfig{
|
|
|
|
Interval: flaeg.Duration(configuration.DefaultHealthCheckInterval),
|
|
|
|
}
|
|
|
|
|
|
|
|
// default RespondingTimeouts
|
|
|
|
respondingTimeouts := configuration.RespondingTimeouts{
|
|
|
|
IdleTimeout: flaeg.Duration(configuration.DefaultIdleTimeout),
|
|
|
|
}
|
|
|
|
|
|
|
|
// default ForwardingTimeouts
|
|
|
|
forwardingTimeouts := configuration.ForwardingTimeouts{
|
|
|
|
DialTimeout: flaeg.Duration(configuration.DefaultDialTimeout),
|
|
|
|
}
|
|
|
|
|
2018-01-10 16:48:04 +00:00
|
|
|
// default Tracing
|
|
|
|
defaultTracing := tracing.Tracing{
|
|
|
|
Backend: "jaeger",
|
|
|
|
ServiceName: "traefik",
|
|
|
|
Jaeger: &jaeger.Config{
|
2018-01-18 16:24:03 +00:00
|
|
|
SamplingServerURL: "http://localhost:5778/sampling",
|
|
|
|
SamplingType: "const",
|
|
|
|
SamplingParam: 1.0,
|
2018-04-24 17:22:03 +00:00
|
|
|
LocalAgentHostPort: "127.0.0.1:6831",
|
2018-01-10 16:48:04 +00:00
|
|
|
},
|
|
|
|
Zipkin: &zipkin.Config{
|
|
|
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
|
|
|
SameSpan: false,
|
|
|
|
ID128Bit: true,
|
|
|
|
Debug: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-09-26 08:22:03 +00:00
|
|
|
// default LifeCycle
|
2017-11-27 13:26:04 +00:00
|
|
|
defaultLifeCycle := configuration.LifeCycle{
|
2017-09-26 08:22:03 +00:00
|
|
|
GraceTimeOut: flaeg.Duration(configuration.DefaultGraceTimeout),
|
|
|
|
}
|
|
|
|
|
2017-11-09 15:12:04 +00:00
|
|
|
// default ApiConfiguration
|
|
|
|
defaultAPI := api.Handler{
|
|
|
|
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},
|
2018-01-19 13:30:04 +00:00
|
|
|
EntryPoint: configuration.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",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-08-25 14:10:03 +00:00
|
|
|
defaultConfiguration := configuration.GlobalConfiguration{
|
2017-09-20 16:14:03 +00:00
|
|
|
Docker: &defaultDocker,
|
|
|
|
File: &defaultFile,
|
|
|
|
Web: &defaultWeb,
|
2017-11-09 15:12:04 +00:00
|
|
|
Rest: &defaultRest,
|
2017-09-20 16:14:03 +00:00
|
|
|
Marathon: &defaultMarathon,
|
|
|
|
Consul: &defaultConsul,
|
|
|
|
ConsulCatalog: &defaultConsulCatalog,
|
|
|
|
Etcd: &defaultEtcd,
|
|
|
|
Zookeeper: &defaultZookeeper,
|
|
|
|
Boltdb: &defaultBoltDb,
|
|
|
|
Kubernetes: &defaultKubernetes,
|
|
|
|
Mesos: &defaultMesos,
|
|
|
|
ECS: &defaultECS,
|
|
|
|
Rancher: &defaultRancher,
|
|
|
|
Eureka: &defaultEureka,
|
|
|
|
DynamoDB: &defaultDynamoDB,
|
|
|
|
Retry: &configuration.Retry{},
|
|
|
|
HealthCheck: &healthCheck,
|
|
|
|
RespondingTimeouts: &respondingTimeouts,
|
|
|
|
ForwardingTimeouts: &forwardingTimeouts,
|
2017-09-21 09:12:39 +00:00
|
|
|
TraefikLog: &defaultTraefikLog,
|
|
|
|
AccessLog: &defaultAccessLog,
|
2017-11-27 13:26:04 +00:00
|
|
|
LifeCycle: &defaultLifeCycle,
|
2017-11-09 15:12:04 +00:00
|
|
|
Ping: &defaultPing,
|
|
|
|
API: &defaultAPI,
|
|
|
|
Metrics: &defaultMetrics,
|
2018-01-10 16:48:04 +00:00
|
|
|
Tracing: &defaultTracing,
|
2017-08-25 14:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return &TraefikConfiguration{
|
|
|
|
GlobalConfiguration: defaultConfiguration,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTraefikConfiguration creates a TraefikConfiguration with default values
|
|
|
|
func NewTraefikConfiguration() *TraefikConfiguration {
|
|
|
|
return &TraefikConfiguration{
|
|
|
|
GlobalConfiguration: configuration.GlobalConfiguration{
|
|
|
|
AccessLogsFile: "",
|
|
|
|
TraefikLogsFile: "",
|
|
|
|
EntryPoints: map[string]*configuration.EntryPoint{},
|
|
|
|
Constraints: types.Constraints{},
|
2017-11-30 15:10:02 +00:00
|
|
|
DefaultEntryPoints: []string{"http"},
|
2017-08-25 14:10:03 +00:00
|
|
|
ProvidersThrottleDuration: flaeg.Duration(2 * time.Second),
|
|
|
|
MaxIdleConnsPerHost: 200,
|
|
|
|
IdleTimeout: flaeg.Duration(0),
|
|
|
|
HealthCheck: &configuration.HealthCheckConfig{
|
|
|
|
Interval: flaeg.Duration(configuration.DefaultHealthCheckInterval),
|
|
|
|
},
|
2018-02-27 09:24:03 +00:00
|
|
|
LifeCycle: &configuration.LifeCycle{
|
|
|
|
GraceTimeOut: flaeg.Duration(configuration.DefaultGraceTimeout),
|
|
|
|
},
|
2017-08-25 14:10:03 +00:00
|
|
|
CheckNewVersion: true,
|
|
|
|
},
|
|
|
|
ConfigFile: "",
|
|
|
|
}
|
|
|
|
}
|