From 6ae194934d50db135d027f488da947f007a4a7e0 Mon Sep 17 00:00:00 2001 From: LandryBe Date: Tue, 11 May 2021 16:46:14 +0200 Subject: [PATCH] fix: use defaultEntryPoints when no entryPoint is defined in a TCPRouter --- pkg/config/runtime/runtime_tcp.go | 8 +------- pkg/server/aggregator.go | 6 ++++++ pkg/server/aggregator_test.go | 29 +++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/pkg/config/runtime/runtime_tcp.go b/pkg/config/runtime/runtime_tcp.go index 18a1a0911..47f583da4 100644 --- a/pkg/config/runtime/runtime_tcp.go +++ b/pkg/config/runtime/runtime_tcp.go @@ -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). diff --git a/pkg/server/aggregator.go b/pkg/server/aggregator.go index 856cce022..8234162df 100644 --- a/pkg/server/aggregator.go +++ b/pkg/server/aggregator.go @@ -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 { diff --git a/pkg/server/aggregator_test.go b/pkg/server/aggregator_test.go index 1e6c6e602..b0c1d34b2 100644 --- a/pkg/server/aggregator_test.go +++ b/pkg/server/aggregator_test.go @@ -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