1
0
Fork 0

API: remove configuration of Entrypoint and Middlewares

Co-authored-by: Julien Salleyron <julien.salleyron@gmail.com>
This commit is contained in:
mpl 2019-07-19 12:28:07 +02:00 committed by Traefiker Bot
parent f75f73f3d2
commit 092aa8fa6d
17 changed files with 48 additions and 269 deletions

View file

@ -119,8 +119,7 @@ func TestDo_globalConfiguration(t *testing.T) {
}
config.API = &static.API{
EntryPoint: "traefik",
Dashboard: true,
Dashboard: true,
DashboardAssets: &assetfs.AssetFS{
Asset: func(path string) ([]byte, error) {
return nil, nil
@ -133,7 +132,6 @@ func TestDo_globalConfiguration(t *testing.T) {
},
Prefix: "fii",
},
Middlewares: []string{"first", "second"},
}
config.Providers.File = &file.Provider{
@ -186,9 +184,7 @@ func TestDo_globalConfiguration(t *testing.T) {
config.Metrics = &types.Metrics{
Prometheus: &types.Prometheus{
Buckets: []float64{0.1, 0.3, 1.2, 5},
EntryPoint: "MyEntryPoint",
Middlewares: []string{"m1", "m2"},
Buckets: []float64{0.1, 0.3, 1.2, 5},
},
DataDog: &types.DataDog{
Address: "localhost:8181",
@ -209,10 +205,7 @@ func TestDo_globalConfiguration(t *testing.T) {
},
}
config.Ping = &ping.Handler{
EntryPoint: "MyEntryPoint",
Middlewares: []string{"m1", "m2", "m3"},
}
config.Ping = &ping.Handler{}
config.Tracing = &static.Tracing{
ServiceName: "myServiceName",

View file

@ -11,7 +11,6 @@ import (
"github.com/containous/traefik/pkg/config/runtime"
"github.com/containous/traefik/pkg/config/static"
"github.com/containous/traefik/pkg/log"
"github.com/containous/traefik/pkg/types"
"github.com/containous/traefik/pkg/version"
assetfs "github.com/elazarl/go-bindata-assetfs"
)
@ -50,7 +49,7 @@ type Handler struct {
// runtimeConfiguration is the data set used to create all the data representations exposed by the API.
runtimeConfiguration *runtime.Configuration
staticConfig static.Configuration
statistics *types.Statistics
// statistics *types.Statistics
// stats *thoasstats.Stats // FIXME stats
// StatsRecorder *middlewares.StatsRecorder // FIXME stats
dashboardAssets *assetfs.AssetFS
@ -65,8 +64,8 @@ func New(staticConfig static.Configuration, runtimeConfig *runtime.Configuration
}
return &Handler{
dashboard: staticConfig.API.Dashboard,
statistics: staticConfig.API.Statistics,
dashboard: staticConfig.API.Dashboard,
// statistics: staticConfig.API.Statistics,
dashboardAssets: staticConfig.API.DashboardAssets,
runtimeConfiguration: rConfig,
staticConfig: staticConfig,

View file

@ -85,17 +85,15 @@ type ServersTransport struct {
// API holds the API configuration
type API struct {
EntryPoint string `description:"The entry point that the API handler will be bound to." json:"entryPoint,omitempty" toml:"entryPoint,omitempty" yaml:"entryPoint,omitempty" export:"true"`
Dashboard bool `description:"Activate dashboard." json:"dashboard,omitempty" toml:"dashboard,omitempty" yaml:"dashboard,omitempty" export:"true"`
Debug bool `description:"Enable additional endpoints for debugging and profiling." json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,omitempty" export:"true"`
Statistics *types.Statistics `description:"Enable more detailed statistics." json:"statistics,omitempty" toml:"statistics,omitempty" yaml:"statistics,omitempty" export:"true" label:"allowEmpty"`
Middlewares []string `description:"Middleware list." json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
DashboardAssets *assetfs.AssetFS `json:"-" toml:"-" yaml:"-" label:"-"`
Dashboard bool `description:"Activate dashboard." json:"dashboard,omitempty" toml:"dashboard,omitempty" yaml:"dashboard,omitempty" export:"true"`
Debug bool `description:"Enable additional endpoints for debugging and profiling." json:"debug,omitempty" toml:"debug,omitempty" yaml:"debug,omitempty" export:"true"`
// TODO: Re-enable statistics
// Statistics *types.Statistics `description:"Enable more detailed statistics." json:"statistics,omitempty" toml:"statistics,omitempty" yaml:"statistics,omitempty" export:"true" label:"allowEmpty"`
DashboardAssets *assetfs.AssetFS `json:"-" toml:"-" yaml:"-" label:"-"`
}
// SetDefaults sets the default values.
func (a *API) SetDefaults() {
a.EntryPoint = "traefik"
a.Dashboard = true
}
@ -175,10 +173,10 @@ func (c *Configuration) SetEffectiveConfiguration() {
}
}
if (c.API != nil && c.API.EntryPoint == DefaultInternalEntryPointName) ||
(c.Ping != nil && c.Ping.EntryPoint == DefaultInternalEntryPointName) ||
(c.Metrics != nil && c.Metrics.Prometheus != nil && c.Metrics.Prometheus.EntryPoint == DefaultInternalEntryPointName) ||
(c.Providers.Rest != nil && c.Providers.Rest.EntryPoint == DefaultInternalEntryPointName) {
if (c.API != nil) ||
(c.Ping != nil) ||
(c.Metrics != nil && c.Metrics.Prometheus != nil) ||
(c.Providers.Rest != nil) {
if _, ok := c.EntryPoints[DefaultInternalEntryPointName]; !ok {
ep := &EntryPoint{Address: ":8080"}
ep.SetDefaults()

View file

@ -10,14 +10,11 @@ import (
// Handler expose ping routes.
type Handler struct {
EntryPoint string `description:"Ping entryPoint." json:"entryPoint,omitempty" toml:"entryPoint,omitempty" yaml:"entryPoint,omitempty" export:"true"`
Middlewares []string `description:"Middleware list." json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
terminating bool
}
// SetDefaults sets the default values.
func (h *Handler) SetDefaults() {
h.EntryPoint = "traefik"
}
// WithContext causes the ping endpoint to serve non 200 responses.

View file

@ -19,12 +19,10 @@ var _ provider.Provider = (*Provider)(nil)
// Provider is a provider.Provider implementation that provides a Rest API.
type Provider struct {
configurationChan chan<- dynamic.Message
EntryPoint string `description:"EntryPoint." json:"entryPoint,omitempty" toml:"entryPoint,omitempty" yaml:"entryPoint,omitempty" export:"true"`
}
// SetDefaults sets the default values.
func (p *Provider) SetDefaults() {
p.EntryPoint = "traefik"
}
var templatesRenderer = render.New(render.Options{Directory: "nowhere"})

View file

@ -23,32 +23,24 @@ func NewRouteAppenderAggregator(ctx context.Context, chainBuilder chainBuilder,
entryPointName string, runtimeConfiguration *runtime.Configuration) *RouteAppenderAggregator {
aggregator := &RouteAppenderAggregator{}
if entryPointName != "traefik" {
return aggregator
}
if conf.Providers != nil && conf.Providers.Rest != nil {
aggregator.AddAppender(conf.Providers.Rest)
}
if conf.API != nil && conf.API.EntryPoint == entryPointName {
chain := chainBuilder.BuildChain(ctx, conf.API.Middlewares)
aggregator.AddAppender(&WithMiddleware{
appender: api.New(conf, runtimeConfiguration),
routerMiddlewares: chain,
})
if conf.API != nil {
aggregator.AddAppender(api.New(conf, runtimeConfiguration))
}
if conf.Ping != nil && conf.Ping.EntryPoint == entryPointName {
chain := chainBuilder.BuildChain(ctx, conf.Ping.Middlewares)
aggregator.AddAppender(&WithMiddleware{
appender: conf.Ping,
routerMiddlewares: chain,
})
if conf.Ping != nil {
aggregator.AddAppender(conf.Ping)
}
if conf.Metrics != nil && conf.Metrics.Prometheus != nil && conf.Metrics.Prometheus.EntryPoint == entryPointName {
chain := chainBuilder.BuildChain(ctx, conf.Metrics.Prometheus.Middlewares)
aggregator.AddAppender(&WithMiddleware{
appender: metrics.PrometheusHandler{},
routerMiddlewares: chain,
})
if conf.Metrics != nil && conf.Metrics.Prometheus != nil {
aggregator.AddAppender(metrics.PrometheusHandler{})
}
return aggregator

View file

@ -30,6 +30,7 @@ func (c *ChainBuilderMock) BuildChain(ctx context.Context, middles []string) *al
}
func TestNewRouteAppenderAggregator(t *testing.T) {
t.Skip("Waiting for new api handler implementation")
testCases := []struct {
desc string
staticConf static.Configuration
@ -40,12 +41,12 @@ func TestNewRouteAppenderAggregator(t *testing.T) {
desc: "API with auth, ping without auth",
staticConf: static.Configuration{
Global: &static.Global{},
API: &static.API{
EntryPoint: "traefik",
Middlewares: []string{"dumb"},
API: &static.API{
// EntryPoint: "traefik",
// Middlewares: []string{"dumb"},
},
Ping: &ping.Handler{
EntryPoint: "traefik",
// EntryPoint: "traefik",
},
EntryPoints: static.EntryPoints{
"traefik": {},
@ -69,8 +70,8 @@ func TestNewRouteAppenderAggregator(t *testing.T) {
desc: "Wrong entrypoint name",
staticConf: static.Configuration{
Global: &static.Global{},
API: &static.API{
EntryPoint: "no",
API: &static.API{
// EntryPoint: "no",
},
EntryPoints: static.EntryPoints{
"traefik": {},

View file

@ -15,8 +15,6 @@ type Metrics struct {
// Prometheus can contain specific configuration used by the Prometheus Metrics exporter.
type Prometheus struct {
Buckets []float64 `description:"Buckets for latency metrics." json:"buckets,omitempty" toml:"buckets,omitempty" yaml:"buckets,omitempty" export:"true"`
EntryPoint string `description:"EntryPoint." json:"entryPoint,omitempty" toml:"entryPoint,omitempty" yaml:"entryPoint,omitempty" export:"true"`
Middlewares []string `description:"Middlewares." json:"middlewares,omitempty" toml:"middlewares,omitempty" yaml:"middlewares,omitempty" export:"true"`
AddEntryPointsLabels bool `description:"Enable metrics on entry points." json:"addEntryPointsLabels,omitempty" toml:"addEntryPointsLabels,omitempty" yaml:"addEntryPointsLabels,omitempty" export:"true"`
AddServicesLabels bool `description:"Enable metrics on services." json:"addServicesLabels,omitempty" toml:"addServicesLabels,omitempty" yaml:"addServicesLabels,omitempty" export:"true"`
}
@ -24,7 +22,6 @@ type Prometheus struct {
// SetDefaults sets the default values.
func (p *Prometheus) SetDefaults() {
p.Buckets = []float64{0.1, 0.3, 1.2, 5}
p.EntryPoint = "traefik"
p.AddEntryPointsLabels = true
p.AddServicesLabels = true
}