Skip to content

Commit

Permalink
Propagate HostRewrite from Knative Ingress to HttpRoute
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Su <[email protected]>
  • Loading branch information
andrew-su committed Oct 3, 2023
1 parent a1e11ab commit 6b26300
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
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 6b26300

Please sign in to comment.