From 4b5250e64db7dc8d1500b7f7c3a19e60b6fab453 Mon Sep 17 00:00:00 2001 From: "gang.liu" Date: Wed, 18 Oct 2023 17:44:58 +0800 Subject: [PATCH 1/2] fix wrong check for filter: router Signed-off-by: gang.liu --- internal/envoy/v3/listener.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/envoy/v3/listener.go b/internal/envoy/v3/listener.go index 5ac6e971598..95ea0d8f977 100644 --- a/internal/envoy/v3/listener.go +++ b/internal/envoy/v3/listener.go @@ -418,7 +418,7 @@ func (b *httpConnectionManagerBuilder) AddFilter(f *http.HttpFilter) *httpConnec // If this happens, it has to be programmer error, so we panic to tell them // it needs to be fixed. Note that in hitting this case, it doesn't matter we added // the second one earlier, because we're panicking anyway. - if f.GetTypedConfig().MessageIs(&envoy_router_v3.Router{}) { + if f.GetTypedConfig().MessageIs(&envoy_router_v3.Router{}) && routerIndex != lastIndex { panic("Can't add more than one router to a filter chain") } if routerIndex != lastIndex { From d11a51bd1b05bebaea28d3573dfc7ebcf8b010bf Mon Sep 17 00:00:00 2001 From: "gang.liu" Date: Thu, 19 Oct 2023 15:02:05 +0800 Subject: [PATCH 2/2] add ut Signed-off-by: gang.liu --- internal/envoy/v3/listener_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/internal/envoy/v3/listener_test.go b/internal/envoy/v3/listener_test.go index 12bccde3262..aa2164284a2 100644 --- a/internal/envoy/v3/listener_test.go +++ b/internal/envoy/v3/listener_test.go @@ -1785,6 +1785,35 @@ func TestAddFilter(t *testing.T) { }, }, }, + "Add a single router filter to non-empty builder": { + builder: HTTPConnectionManagerBuilder().AddFilter(&http.HttpFilter{ + Name: "grpcweb", + ConfigType: &http.HttpFilter_TypedConfig{ + TypedConfig: protobuf.MustMarshalAny(&envoy_grpc_web_v3.GrpcWeb{}), + }, + }), + add: &http.HttpFilter{ + Name: "router", + ConfigType: &http.HttpFilter_TypedConfig{ + TypedConfig: protobuf.MustMarshalAny(&envoy_router_v3.Router{}), + }, + }, + want: []*http.HttpFilter{ + { + Name: "grpcweb", + ConfigType: &http.HttpFilter_TypedConfig{ + TypedConfig: protobuf.MustMarshalAny(&envoy_grpc_web_v3.GrpcWeb{}), + }, + }, + { + Name: "router", + ConfigType: &http.HttpFilter_TypedConfig{ + TypedConfig: protobuf.MustMarshalAny(&envoy_router_v3.Router{}), + }, + }, + }, + }, + "Add a filter to a builder with a router": { builder: HTTPConnectionManagerBuilder().AddFilter(&http.HttpFilter{ Name: "router",