Add provider in middleware chain
This commit is contained in:
parent
fcc1109e76
commit
34be181706
4 changed files with 70 additions and 12 deletions
24
integration/testdata/rawdata-crd.json
vendored
24
integration/testdata/rawdata-crd.json
vendored
|
@ -20,7 +20,7 @@
|
|||
"web"
|
||||
],
|
||||
"middlewares": [
|
||||
"default/mychain"
|
||||
"default/mychain@kubernetescrd"
|
||||
],
|
||||
"service": "default/test2.route-23c7f4c450289ee29016",
|
||||
"rule": "Host(`foo.com`) \u0026\u0026 PathPrefix(`/tobestripped`)",
|
||||
|
@ -34,7 +34,7 @@
|
|||
"default/mychain@kubernetescrd": {
|
||||
"chain": {
|
||||
"middlewares": [
|
||||
"default/stripprefix"
|
||||
"default/stripprefix@kubernetescrd"
|
||||
]
|
||||
},
|
||||
"status": "enabled",
|
||||
|
@ -56,10 +56,10 @@
|
|||
"loadBalancer": {
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://10.42.0.3:80"
|
||||
"url": "http://10.42.0.2:80"
|
||||
},
|
||||
{
|
||||
"url": "http://10.42.0.5:80"
|
||||
"url": "http://10.42.0.6:80"
|
||||
}
|
||||
],
|
||||
"passHostHeader": true
|
||||
|
@ -69,18 +69,18 @@
|
|||
"default/test.route-6b204d94623b3df4370c@kubernetescrd"
|
||||
],
|
||||
"serverStatus": {
|
||||
"http://10.42.0.3:80": "UP",
|
||||
"http://10.42.0.5:80": "UP"
|
||||
"http://10.42.0.2:80": "UP",
|
||||
"http://10.42.0.6:80": "UP"
|
||||
}
|
||||
},
|
||||
"default/test2.route-23c7f4c450289ee29016@kubernetescrd": {
|
||||
"loadBalancer": {
|
||||
"servers": [
|
||||
{
|
||||
"url": "http://10.42.0.3:80"
|
||||
"url": "http://10.42.0.2:80"
|
||||
},
|
||||
{
|
||||
"url": "http://10.42.0.5:80"
|
||||
"url": "http://10.42.0.6:80"
|
||||
}
|
||||
],
|
||||
"passHostHeader": true
|
||||
|
@ -90,8 +90,8 @@
|
|||
"default/test2.route-23c7f4c450289ee29016@kubernetescrd"
|
||||
],
|
||||
"serverStatus": {
|
||||
"http://10.42.0.3:80": "UP",
|
||||
"http://10.42.0.5:80": "UP"
|
||||
"http://10.42.0.2:80": "UP",
|
||||
"http://10.42.0.6:80": "UP"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -117,10 +117,10 @@
|
|||
"loadBalancer": {
|
||||
"servers": [
|
||||
{
|
||||
"address": "10.42.0.6:8080"
|
||||
"address": "10.42.0.4:8080"
|
||||
},
|
||||
{
|
||||
"address": "10.42.0.7:8080"
|
||||
"address": "10.42.0.5:8080"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
@ -141,6 +141,12 @@ func (b *Builder) buildConstructor(ctx context.Context, middlewareName string) (
|
|||
if middleware != nil {
|
||||
return nil, badConf
|
||||
}
|
||||
|
||||
qualifiedNames := make([]string, len(config.Chain.Middlewares))
|
||||
for i, name := range config.Chain.Middlewares {
|
||||
qualifiedNames[i] = internal.GetQualifiedName(ctx, name)
|
||||
}
|
||||
config.Chain.Middlewares = qualifiedNames
|
||||
middleware = func(next http.Handler) (http.Handler, error) {
|
||||
return chain.New(ctx, next, *config.Chain, b, middlewareName)
|
||||
}
|
||||
|
|
|
@ -147,6 +147,7 @@ func (m *Manager) buildHTTPHandler(ctx context.Context, router *runtime.RouterIn
|
|||
for i, name := range router.Middlewares {
|
||||
qualifiedNames[i] = internal.GetQualifiedName(ctx, name)
|
||||
}
|
||||
router.Middlewares = qualifiedNames
|
||||
rm := m.modifierBuilder.Build(ctx, qualifiedNames)
|
||||
|
||||
if router.Service == "" {
|
||||
|
|
|
@ -725,6 +725,57 @@ func TestRuntimeConfiguration(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestProviderOnMiddlewares(t *testing.T) {
|
||||
entryPoints := []string{"web"}
|
||||
|
||||
rtConf := runtime.NewConfig(dynamic.Configuration{
|
||||
HTTP: &dynamic.HTTPConfiguration{
|
||||
Services: map[string]*dynamic.Service{
|
||||
"test@file": {
|
||||
LoadBalancer: &dynamic.ServersLoadBalancer{
|
||||
Servers: []dynamic.Server{},
|
||||
},
|
||||
},
|
||||
},
|
||||
Routers: map[string]*dynamic.Router{
|
||||
"router@file": {
|
||||
Rule: "Host(`test`)",
|
||||
Service: "test@file",
|
||||
Middlewares: []string{"chain@file", "m1"},
|
||||
},
|
||||
"router@docker": {
|
||||
Rule: "Host(`test`)",
|
||||
Service: "test@file",
|
||||
Middlewares: []string{"chain", "m1@file"},
|
||||
},
|
||||
},
|
||||
Middlewares: map[string]*dynamic.Middleware{
|
||||
"chain@file": {
|
||||
Chain: &dynamic.Chain{Middlewares: []string{"m1", "m2", "m1@file"}},
|
||||
},
|
||||
"chain@docker": {
|
||||
Chain: &dynamic.Chain{Middlewares: []string{"m1", "m2", "m1@file"}},
|
||||
},
|
||||
"m1@file": {AddPrefix: &dynamic.AddPrefix{Prefix: "/m1"}},
|
||||
"m2@file": {AddPrefix: &dynamic.AddPrefix{Prefix: "/m2"}},
|
||||
"m1@docker": {AddPrefix: &dynamic.AddPrefix{Prefix: "/m1"}},
|
||||
"m2@docker": {AddPrefix: &dynamic.AddPrefix{Prefix: "/m2"}},
|
||||
},
|
||||
},
|
||||
})
|
||||
serviceManager := service.NewManager(rtConf.Services, http.DefaultTransport, nil, nil, nil, nil)
|
||||
middlewaresBuilder := middleware.NewBuilder(rtConf.Middlewares, serviceManager)
|
||||
responseModifierFactory := responsemodifiers.NewBuilder(map[string]*runtime.MiddlewareInfo{})
|
||||
routerManager := NewManager(rtConf, serviceManager, middlewaresBuilder, responseModifierFactory)
|
||||
|
||||
_ = routerManager.BuildHandlers(context.Background(), entryPoints, false)
|
||||
|
||||
assert.Equal(t, []string{"chain@file", "m1@file"}, rtConf.Routers["router@file"].Middlewares)
|
||||
assert.Equal(t, []string{"m1@file", "m2@file", "m1@file"}, rtConf.Middlewares["chain@file"].Chain.Middlewares)
|
||||
assert.Equal(t, []string{"chain@docker", "m1@file"}, rtConf.Routers["router@docker"].Middlewares)
|
||||
assert.Equal(t, []string{"m1@docker", "m2@docker", "m1@file"}, rtConf.Middlewares["chain@docker"].Chain.Middlewares)
|
||||
}
|
||||
|
||||
type staticTransport struct {
|
||||
res *http.Response
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue