Skip to content

Commit

Permalink
internal/envoy: fix wrong check for filter/router (#5864)
Browse files Browse the repository at this point in the history
a single Router can be added to an existing non-empty list of filters without failure

Signed-off-by: gang.liu <[email protected]>
  • Loading branch information
izturn authored Nov 3, 2023
1 parent f661786 commit 5578185
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/envoy/v3/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions internal/envoy/v3/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5578185

Please sign in to comment.