Skip to content
Open
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
43 changes: 31 additions & 12 deletions pkg/reconciler/ingress/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ type RuleBuilder interface {
Build() gatewayapi.HTTPRouteRule
}

func appendRewriteHostFilter(filters []gatewayapi.HTTPRouteFilter, host string) []gatewayapi.HTTPRouteFilter {
if host == "" {
return filters
}

return append(filters, gatewayapi.HTTPRouteFilter{
Type: gatewayapi.HTTPRouteFilterURLRewrite,
URLRewrite: &gatewayapi.HTTPURLRewriteFilter{
Hostname: ptr.To(gatewayapi.PreciseHostname(host)),
},
})
}

type HTTPRoute struct {
Namespace string
Name string
Expand Down Expand Up @@ -116,12 +129,13 @@ func (r HTTPRoute) Build() *gatewayapi.HTTPRoute {
}

type EndpointProbeRule struct {
Namespace string
Name string
Hash string
Path string
Port int
Headers []string
Namespace string
Name string
Hash string
Path string
Port int
Headers []string
RewriteHost string
}

func (p EndpointProbeRule) Build() gatewayapi.HTTPRouteRule {
Expand Down Expand Up @@ -183,16 +197,19 @@ func (p EndpointProbeRule) Build() gatewayapi.HTTPRouteRule {
)
}

rule.Filters = appendRewriteHostFilter(rule.Filters, p.RewriteHost)

return rule
}

type NormalRule struct {
Namespace string
Name string
Path string
Port int
Headers []string
Weight int
Namespace string
Name string
Path string
Port int
Headers []string
Weight int
RewriteHost string
}

func (p NormalRule) Build() gatewayapi.HTTPRouteRule {
Expand Down Expand Up @@ -240,5 +257,7 @@ func (p NormalRule) Build() gatewayapi.HTTPRouteRule {
)
}

rule.Filters = appendRewriteHostFilter(rule.Filters, p.RewriteHost)

return rule
}
53 changes: 29 additions & 24 deletions pkg/reconciler/ingress/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,8 @@ func TestReconcileProbing(t *testing.T) {
Name: "updated ingress - new backends used for endpoint probing",
Key: "ns/name",
Objects: append([]runtime.Object{
ing(withBasicSpec, withSecondRevisionSpec, withGatewayAPIclass, withFinalizer, makeItReady),
httpRoute(t, ing(withBasicSpec, withGatewayAPIclass), httpRouteReady),
ing(withBasicSpec, withSecondRevisionSpec, withRewriteHost("current.default.svc.cluster.local"), withGatewayAPIclass, withFinalizer, makeItReady),
httpRoute(t, ing(withBasicSpec, withRewriteHost("previous.default.svc.cluster.local"), withGatewayAPIclass), httpRouteReady),
}, servicesAndEndpoints...),
Ctx: withStatusManager(&fakeStatusManager{
FakeIsProbeActive: func(types.NamespacedName) (status.ProbeState, bool) {
Expand All @@ -527,6 +527,7 @@ func TestReconcileProbing(t *testing.T) {
Object: ing(
withBasicSpec,
withSecondRevisionSpec,
withRewriteHost("current.default.svc.cluster.local"),
withGatewayAPIclass,
withFinalizer,
makeItReady,
Expand All @@ -540,30 +541,34 @@ func TestReconcileProbing(t *testing.T) {
Hostname: "example.com",
Rules: []RuleBuilder{
EndpointProbeRule{
Namespace: "ns",
Name: "goo",
Hash: "ep-9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2",
Port: 123,
Namespace: "ns",
Name: "goo",
Hash: "ep-f7a1d68d4686969231731f087164ec98c24f3f1aae43c79ba5218b15bf2f63bc",
Port: 123,
RewriteHost: "previous.default.svc.cluster.local",
},
NormalRule{
Namespace: "ns",
Name: "goo",
Port: 123,
Weight: 100,
},
EndpointProbeRule{
Namespace: "ns",
Name: "second-revision",
Path: "/.well-known/knative/revision/ns/second-revision",
Hash: "ep-9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2",
Port: 123,
},
EndpointProbeRule{
Namespace: "ns",
Name: "goo",
Path: "/.well-known/knative/revision/ns/goo",
Hash: "ep-9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2",
Port: 123,
Namespace: "ns",
Name: "goo",
Port: 123,
Weight: 100,
RewriteHost: "previous.default.svc.cluster.local",
},
EndpointProbeRule{
Namespace: "ns",
Name: "second-revision",
Path: "/.well-known/knative/revision/ns/second-revision",
Hash: "ep-f7a1d68d4686969231731f087164ec98c24f3f1aae43c79ba5218b15bf2f63bc",
Port: 123,
RewriteHost: "current.default.svc.cluster.local",
},
EndpointProbeRule{
Namespace: "ns",
Name: "goo",
Path: "/.well-known/knative/revision/ns/goo",
Hash: "ep-f7a1d68d4686969231731f087164ec98c24f3f1aae43c79ba5218b15bf2f63bc",
Port: 123,
RewriteHost: "previous.default.svc.cluster.local",
},
},
StatusConditions: []metav1.Condition{{
Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/ingress/lister_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,12 @@ func withBackendAppendHeaders(key, val string) IngressOption {
}
}

func withRewriteHost(host string) IngressOption {
return func(i *v1alpha1.Ingress) {
i.Spec.Rules[0].HTTP.Paths[0].RewriteHost = host
}
}

func withInternalSpec(i *v1alpha1.Ingress) {
i.Spec.Rules = append(i.Spec.Rules, v1alpha1.IngressRule{
Hosts: []string{"foo.svc", "foo.svc.cluster.local"},
Expand Down
Loading
Loading