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

Support response header filter for GRPCRoute #1983

Merged
merged 1 commit into from
May 16, 2024
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
22 changes: 0 additions & 22 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,19 +650,16 @@ func TestCreateServers(t *testing.T) {
Path: "@rule0-route0",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule0-route1",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule0-route2",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/",
Expand All @@ -672,7 +669,6 @@ func TestCreateServers(t *testing.T) {
Path: "@rule1-route0",
ProxyPass: "http://$test__route1_rule1$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/test/",
Expand All @@ -682,13 +678,11 @@ func TestCreateServers(t *testing.T) {
Path: "/path-only/",
ProxyPass: "http://invalid-backend-ref$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /path-only",
ProxyPass: "http://invalid-backend-ref$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/backend-tls-policy/",
Expand Down Expand Up @@ -756,21 +750,18 @@ func TestCreateServers(t *testing.T) {
Rewrites: []string{"^ /replacement break"},
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /rewrite",
Rewrites: []string{"^ /replacement break"},
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule8-route0",
Rewrites: []string{"^/rewrite-with-headers(.*)$ /prefix-replacement$1 break"},
ProxyPass: "http://test_foo_80",
ProxySetHeaders: rewriteProxySetHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/rewrite-with-headers/",
Expand Down Expand Up @@ -810,13 +801,11 @@ func TestCreateServers(t *testing.T) {
Path: "= /exact",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "@rule12-route0",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /test",
Expand Down Expand Up @@ -1029,13 +1018,11 @@ func TestCreateServersConflicts(t *testing.T) {
Path: "/coffee/",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /coffee",
ProxyPass: "http://test_bar_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
createDefaultRootLocation(),
},
Expand Down Expand Up @@ -1069,13 +1056,11 @@ func TestCreateServersConflicts(t *testing.T) {
Path: "= /coffee",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/coffee/",
ProxyPass: "http://test_bar_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
createDefaultRootLocation(),
},
Expand Down Expand Up @@ -1119,13 +1104,11 @@ func TestCreateServersConflicts(t *testing.T) {
Path: "/coffee/",
ProxyPass: "http://test_bar_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "= /coffee",
ProxyPass: "http://test_baz_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
createDefaultRootLocation(),
},
Expand Down Expand Up @@ -1244,13 +1227,11 @@ func TestCreateLocationsRootPath(t *testing.T) {
Path: "/path-1",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/path-2",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/",
Expand Down Expand Up @@ -1297,19 +1278,16 @@ func TestCreateLocationsRootPath(t *testing.T) {
Path: "/path-1",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/path-2",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
{
Path: "/",
ProxyPass: "http://test_foo_80$request_uri",
ProxySetHeaders: httpBaseHeaders,
ResponseHeaders: http.ResponseHeaders{},
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions internal/mode/static/state/graph/grpcroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,15 @@ func validateGRPCFilter(
switch filter.Type {
case v1alpha2.GRPCRouteFilterRequestHeaderModifier:
return validateFilterHeaderModifier(validator, filter.RequestHeaderModifier, filterPath.Child(string(filter.Type)))
case v1alpha2.GRPCRouteFilterResponseHeaderModifier:
return validateFilterHeaderModifier(validator, filter.ResponseHeaderModifier, filterPath.Child(string(filter.Type)))
default:
valErr := field.NotSupported(
filterPath.Child("type"),
filter.Type,
[]string{
string(v1alpha2.GRPCRouteFilterRequestHeaderModifier),
string(v1alpha2.GRPCRouteFilterResponseHeaderModifier),
},
)
allErrs = append(allErrs, valErr)
Expand All @@ -286,6 +289,12 @@ func convertGRPCFilters(filters []v1alpha2.GRPCRouteFilter) []v1.HTTPRouteFilter
RequestHeaderModifier: filter.RequestHeaderModifier,
}
httpFilters = append(httpFilters, httpRequestHeaderFilter)
case v1alpha2.GRPCRouteFilterResponseHeaderModifier:
httpResponseHeaderFilter := v1.HTTPRouteFilter{
Type: v1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: filter.ResponseHeaderModifier,
}
httpFilters = append(httpFilters, httpResponseHeaderFilter)
default:
continue
}
Expand Down
30 changes: 29 additions & 1 deletion internal/mode/static/state/graph/grpcroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ func TestBuildGRPCRoute(t *testing.T) {
Remove: []string{"header"},
},
},
{
Type: "ResponseHeaderModifier",
ResponseHeaderModifier: &v1.HTTPHeaderFilter{
Add: []v1.HTTPHeader{
{Name: "Accept-Encoding", Value: "gzip"},
},
},
},
}

grValidFilter := createGRPCRoute(
Expand All @@ -272,6 +280,14 @@ func TestBuildGRPCRoute(t *testing.T) {
Remove: []string{"header"},
},
},
{
Type: v1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: &v1.HTTPHeaderFilter{
Add: []v1.HTTPHeader{
{Name: "Accept-Encoding", Value: "gzip"},
},
},
},
}

createAllValidValidator := func() *validationfakes.FakeHTTPFieldsValidator {
Expand Down Expand Up @@ -616,7 +632,7 @@ func TestBuildGRPCRoute(t *testing.T) {
Conditions: []conditions.Condition{
staticConds.NewRouteUnsupportedValue(
`All rules are invalid: spec.rules[0].filters[0].type: ` +
`Unsupported value: "RequestMirror": supported values: "RequestHeaderModifier"`,
`Unsupported value: "RequestMirror": supported values: "RequestHeaderModifier", "ResponseHeaderModifier"`,
),
},
Spec: L7RouteSpec{
Expand Down Expand Up @@ -755,6 +771,14 @@ func TestConvertGRPCFilters(t *testing.T) {
Remove: []string{"header"},
},
},
{
Type: "ResponseHeaderModifier",
ResponseHeaderModifier: &v1.HTTPHeaderFilter{
Add: []v1.HTTPHeader{
{Name: "Accept-Encoding", Value: "gzip"},
},
},
},
{
Type: "RequestMirror",
},
Expand All @@ -765,6 +789,10 @@ func TestConvertGRPCFilters(t *testing.T) {
Type: v1.HTTPRouteFilterRequestHeaderModifier,
RequestHeaderModifier: grFilters[0].RequestHeaderModifier,
},
{
Type: v1.HTTPRouteFilterResponseHeaderModifier,
ResponseHeaderModifier: grFilters[1].ResponseHeaderModifier,
},
}

g := NewWithT(t)
Expand Down
5 changes: 3 additions & 2 deletions site/content/overview/gateway-api-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ See the [static-mode]({{< relref "/reference/cli-help.md#static-mode">}}) comman
{{< bootstrap-table "table table-striped table-bordered" >}}
| Resource | Core Support Level | Extended Support Level | Implementation-Specific Support Level | API Version |
| --------- | ------------------- | ---------------------- | ------------------------------------- | ----------- |
| GRPCRoute | Partially Supported | Not supported | Not supported | v1alpha2 |
| GRPCRoute | Supported | Not supported | Not supported | v1alpha2 |
{{< /bootstrap-table >}}

**Fields**:
Expand All @@ -202,7 +202,8 @@ See the [static-mode]({{< relref "/reference/cli-help.md#static-mode">}}) comman
- `filters`
- `type`: Supported.
- `requestHeaderModifier`: Supported. If multiple filters are configured, NGINX Gateway Fabric will choose the first and ignore the rest.
- `responseHeaderModifier`, `requestMirror`, `extensionRef`: Not supported.
- `responseHeaderModifier`: Supported. If multiple filters are configured, NGINX Gateway Fabric will choose the first and ignore the rest.
- `requestMirror`, `extensionRef`: Not supported.
- `backendRefs`: Partially supported. Backend ref `filters` are not supported.
- `status`
- `parents`
Expand Down
Loading