Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/envoy: fix wrong check for filter/router #5864

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
izturn marked this conversation as resolved.
Show resolved Hide resolved
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