Skip to content

Commit

Permalink
Propagate HostRewrite from Knative Ingress to HttpRoute (#552)
Browse files Browse the repository at this point in the history
* Propagate HostRewrite from Knative Ingress to HttpRoute

Signed-off-by: Andrew Su <suan@vmware.com>

* Enable host-rewrite test for istio

Signed-off-by: Andrew Su <suan@vmware.com>

---------

Signed-off-by: Andrew Su <suan@vmware.com>
  • Loading branch information
andrew-su authored Oct 6, 2023
1 parent a1e11ab commit 77ff5b5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/test-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ The following Gateway API version and Ingress were tested as part of the release

| Ingress | Tested version | Unavailable features |
| ------- | ----------------------- | ------------------------------ |
| Istio | v1.19.0 | retry,httpoption,host-rewrite |
| Istio | v1.19.0 | retry,httpoption |
| Contour | v1.24.0 | httpoption,basics/http2,websocket,websocket/split,grpc,grpc/split,update,host-rewrite |
2 changes: 1 addition & 1 deletion hack/test-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

export GATEWAY_API_VERSION="v0.8.1"
export ISTIO_VERSION="1.19.0"
export ISTIO_UNSUPPORTED_E2E_TESTS="retry,httpoption,host-rewrite"
export ISTIO_UNSUPPORTED_E2E_TESTS="retry,httpoption"
export CONTOUR_VERSION="v1.24.0"
export CONTOUR_UNSUPPORTED_E2E_TESTS="httpoption,basics/http2,websocket,websocket/split,grpc,grpc/split,update,host-rewrite"
9 changes: 9 additions & 0 deletions pkg/reconciler/ingress/resources/httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ func makeHTTPRouteRule(rule *netv1alpha1.IngressRule) []gatewayapi.HTTPRouteRule
}}}
}

if path.RewriteHost != "" {
preFilters = append(preFilters, gatewayapi.HTTPRouteFilter{
Type: gatewayapi.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayapi.HTTPURLRewriteFilter{
Hostname: (*gatewayapi.PreciseHostname)(&path.RewriteHost),
},
})
}

for _, split := range path.Splits {
headers := []gatewayapi.HTTPHeader{}
for k, v := range split.AppendHeaders {
Expand Down
57 changes: 57 additions & 0 deletions pkg/reconciler/ingress/resources/httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,63 @@ func TestMakeHTTPRoute(t *testing.T) {
},
},
}},
}, {
name: "path with host rewrites",
ing: &v1alpha1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: testIngressName,
Namespace: testNamespace,
Labels: map[string]string{
networking.IngressLabelKey: testIngressName,
},
},
Spec: v1alpha1.IngressSpec{Rules: []v1alpha1.IngressRule{{
Hosts: testHosts,
Visibility: v1alpha1.IngressVisibilityExternalIP,
HTTP: &v1alpha1.HTTPIngressRuleValue{
Paths: []v1alpha1.HTTPIngressPath{{
RewriteHost: "hello-example.example.com",
}},
},
}}},
},
expected: []*gatewayapi.HTTPRoute{{
ObjectMeta: metav1.ObjectMeta{
Name: LongestHost(testHosts),
Namespace: testNamespace,
Labels: map[string]string{
networking.IngressLabelKey: testIngressName,
"networking.knative.dev/visibility": "",
},
Annotations: map[string]string{},
},
Spec: gatewayapi.HTTPRouteSpec{
Hostnames: []gatewayapi.Hostname{externalHost},
Rules: []gatewayapi.HTTPRouteRule{{
Filters: []gatewayapi.HTTPRouteFilter{{
Type: gatewayapi.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayapi.HTTPURLRewriteFilter{
Hostname: (*gatewayapi.PreciseHostname)(ptr("hello-example.example.com")),
},
}},
BackendRefs: []gatewayapi.HTTPBackendRef{},
Matches: []gatewayapi.HTTPRouteMatch{{
Path: &gatewayapi.HTTPPathMatch{
Type: ptr(gatewayapi.PathMatchPathPrefix),
Value: pointer.String("/"),
},
}}},
},
CommonRouteSpec: gatewayapi.CommonRouteSpec{
ParentRefs: []gatewayapi.ParentReference{{
Group: (*gatewayapi.Group)(pointer.String("gateway.networking.k8s.io")),
Kind: (*gatewayapi.Kind)(pointer.String("Gateway")),
Namespace: ptr[gatewayapi.Namespace]("test-ns"),
Name: gatewayapi.ObjectName("foo"),
}},
},
},
}},
}} {
t.Run(tc.name, func(t *testing.T) {
for i, rule := range tc.ing.Spec.Rules {
Expand Down

0 comments on commit 77ff5b5

Please sign in to comment.