Fix the rule syntax mechanism for TCP

This commit is contained in:
Landry Benguigui 2024-05-14 09:42:04 +02:00 committed by GitHub
parent d8a778b5cd
commit c2c1c3e09e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 87 additions and 40 deletions

View file

@ -84,6 +84,9 @@ func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoint
for serviceName, service := range configuration.TCP.Services { for serviceName, service := range configuration.TCP.Services {
conf.TCP.Services[provider.MakeQualifiedName(pvd, serviceName)] = service conf.TCP.Services[provider.MakeQualifiedName(pvd, serviceName)] = service
} }
for modelName, model := range configuration.TCP.Models {
conf.TCP.Models[provider.MakeQualifiedName(pvd, modelName)] = model
}
for serversTransportName, serversTransport := range configuration.TCP.ServersTransports { for serversTransportName, serversTransport := range configuration.TCP.ServersTransports {
conf.TCP.ServersTransports[provider.MakeQualifiedName(pvd, serversTransportName)] = serversTransport conf.TCP.ServersTransports[provider.MakeQualifiedName(pvd, serversTransportName)] = serversTransport
} }
@ -146,10 +149,7 @@ func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoint
} }
func applyModel(cfg dynamic.Configuration) dynamic.Configuration { func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
if cfg.HTTP == nil || len(cfg.HTTP.Models) == 0 { if cfg.HTTP != nil && len(cfg.HTTP.Models) > 0 {
return cfg
}
rts := make(map[string]*dynamic.Router) rts := make(map[string]*dynamic.Router)
for name, rt := range cfg.HTTP.Routers { for name, rt := range cfg.HTTP.Routers {
@ -192,6 +192,7 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
} }
cfg.HTTP.Routers = rts cfg.HTTP.Routers = rts
}
if cfg.TCP == nil || len(cfg.TCP.Models) == 0 { if cfg.TCP == nil || len(cfg.TCP.Models) == 0 {
return cfg return cfg
@ -199,7 +200,7 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
tcpRouters := make(map[string]*dynamic.TCPRouter) tcpRouters := make(map[string]*dynamic.TCPRouter)
for _, rt := range cfg.TCP.Routers { for name, rt := range cfg.TCP.Routers {
router := rt.DeepCopy() router := rt.DeepCopy()
if router.RuleSyntax == "" { if router.RuleSyntax == "" {
@ -208,6 +209,8 @@ func applyModel(cfg dynamic.Configuration) dynamic.Configuration {
break break
} }
} }
tcpRouters[name] = router
} }
cfg.TCP.Routers = tcpRouters cfg.TCP.Routers = tcpRouters

View file

@ -656,6 +656,50 @@ func Test_applyModel(t *testing.T) {
}, },
}, },
}, },
{
desc: "with TCP model, two entry points",
input: dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"test": {
EntryPoints: []string{"websecure", "web"},
},
"test2": {
EntryPoints: []string{"web"},
RuleSyntax: "barfoo",
},
},
Middlewares: make(map[string]*dynamic.TCPMiddleware),
Services: make(map[string]*dynamic.TCPService),
Models: map[string]*dynamic.TCPModel{
"websecure@internal": {
DefaultRuleSyntax: "foobar",
},
},
},
},
expected: dynamic.Configuration{
TCP: &dynamic.TCPConfiguration{
Routers: map[string]*dynamic.TCPRouter{
"test": {
EntryPoints: []string{"websecure", "web"},
RuleSyntax: "foobar",
},
"test2": {
EntryPoints: []string{"web"},
RuleSyntax: "barfoo",
},
},
Middlewares: make(map[string]*dynamic.TCPMiddleware),
Services: make(map[string]*dynamic.TCPService),
Models: map[string]*dynamic.TCPModel{
"websecure@internal": {
DefaultRuleSyntax: "foobar",
},
},
},
},
},
} }
for _, test := range testCases { for _, test := range testCases {