fix: use defaultEntryPoints when no entryPoint is defined in a TCPRouter
This commit is contained in:
parent
40f21f41e1
commit
6ae194934d
3 changed files with 36 additions and 7 deletions
|
@ -15,14 +15,8 @@ func (c *Configuration) GetTCPRoutersByEntryPoints(ctx context.Context, entryPoi
|
|||
for rtName, rt := range c.TCPRouters {
|
||||
logger := log.FromContext(log.With(ctx, log.Str(log.RouterName, rtName)))
|
||||
|
||||
eps := rt.EntryPoints
|
||||
if len(eps) == 0 {
|
||||
logger.Debugf("No entryPoint defined for this router, using the default one(s) instead: %+v", entryPoints)
|
||||
eps = entryPoints
|
||||
}
|
||||
|
||||
entryPointsCount := 0
|
||||
for _, entryPointName := range eps {
|
||||
for _, entryPointName := range rt.EntryPoints {
|
||||
if !contains(entryPoints, entryPointName) {
|
||||
rt.AddError(fmt.Errorf("entryPoint %q doesn't exist", entryPointName), false)
|
||||
logger.WithField(log.EntryPointName, entryPointName).
|
||||
|
|
|
@ -61,6 +61,12 @@ func mergeConfiguration(configurations dynamic.Configurations, defaultEntryPoint
|
|||
|
||||
if configuration.TCP != nil {
|
||||
for routerName, router := range configuration.TCP.Routers {
|
||||
if len(router.EntryPoints) == 0 {
|
||||
log.WithoutContext().
|
||||
WithField(log.RouterName, routerName).
|
||||
Debugf("No entryPoint defined for this TCP router, using the default one(s) instead: %+v", defaultEntryPoints)
|
||||
router.EntryPoints = defaultEntryPoints
|
||||
}
|
||||
conf.TCP.Routers[provider.MakeQualifiedName(pvd, routerName)] = router
|
||||
}
|
||||
for serviceName, service := range configuration.TCP.Services {
|
||||
|
|
|
@ -449,6 +449,35 @@ func Test_mergeConfiguration_tlsStore(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_mergeConfiguration_defaultTCPEntryPoint(t *testing.T) {
|
||||
given := dynamic.Configurations{
|
||||
"provider-1": &dynamic.Configuration{
|
||||
TCP: &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{
|
||||
"router-1": {},
|
||||
},
|
||||
Services: map[string]*dynamic.TCPService{
|
||||
"service-1": {},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := &dynamic.TCPConfiguration{
|
||||
Routers: map[string]*dynamic.TCPRouter{
|
||||
"router-1@provider-1": {
|
||||
EntryPoints: []string{"defaultEP"},
|
||||
},
|
||||
},
|
||||
Services: map[string]*dynamic.TCPService{
|
||||
"service-1@provider-1": {},
|
||||
},
|
||||
}
|
||||
|
||||
actual := mergeConfiguration(given, []string{"defaultEP"})
|
||||
assert.Equal(t, expected, actual.TCP)
|
||||
}
|
||||
|
||||
func Test_applyModel(t *testing.T) {
|
||||
testCases := []struct {
|
||||
desc string
|
||||
|
|
Loading…
Reference in a new issue