Skip to content

Commit 53a2278

Browse files
committed
Preserve route behavior in endpoint probes
Signed-off-by: kahirokunn <okinakahiro@gmail.com>
1 parent b666272 commit 53a2278

7 files changed

Lines changed: 684 additions & 263 deletions

File tree

pkg/reconciler/ingress/fixtures_test.go

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ type RuleBuilder interface {
3030
Build() gatewayapi.HTTPRouteRule
3131
}
3232

33+
func appendRewriteHostFilter(filters []gatewayapi.HTTPRouteFilter, host string) []gatewayapi.HTTPRouteFilter {
34+
if host == "" {
35+
return filters
36+
}
37+
38+
return append(filters, gatewayapi.HTTPRouteFilter{
39+
Type: gatewayapi.HTTPRouteFilterURLRewrite,
40+
URLRewrite: &gatewayapi.HTTPURLRewriteFilter{
41+
Hostname: ptr.To(gatewayapi.PreciseHostname(host)),
42+
},
43+
})
44+
}
45+
3346
type HTTPRoute struct {
3447
Namespace string
3548
Name string
@@ -116,12 +129,13 @@ func (r HTTPRoute) Build() *gatewayapi.HTTPRoute {
116129
}
117130

118131
type EndpointProbeRule struct {
119-
Namespace string
120-
Name string
121-
Hash string
122-
Path string
123-
Port int
124-
Headers []string
132+
Namespace string
133+
Name string
134+
Hash string
135+
Path string
136+
Port int
137+
Headers []string
138+
RewriteHost string
125139
}
126140

127141
func (p EndpointProbeRule) Build() gatewayapi.HTTPRouteRule {
@@ -183,16 +197,19 @@ func (p EndpointProbeRule) Build() gatewayapi.HTTPRouteRule {
183197
)
184198
}
185199

200+
rule.Filters = appendRewriteHostFilter(rule.Filters, p.RewriteHost)
201+
186202
return rule
187203
}
188204

189205
type NormalRule struct {
190-
Namespace string
191-
Name string
192-
Path string
193-
Port int
194-
Headers []string
195-
Weight int
206+
Namespace string
207+
Name string
208+
Path string
209+
Port int
210+
Headers []string
211+
Weight int
212+
RewriteHost string
196213
}
197214

198215
func (p NormalRule) Build() gatewayapi.HTTPRouteRule {
@@ -240,5 +257,7 @@ func (p NormalRule) Build() gatewayapi.HTTPRouteRule {
240257
)
241258
}
242259

260+
rule.Filters = appendRewriteHostFilter(rule.Filters, p.RewriteHost)
261+
243262
return rule
244263
}

pkg/reconciler/ingress/ingress_test.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,8 @@ func TestReconcileProbing(t *testing.T) {
512512
Name: "updated ingress - new backends used for endpoint probing",
513513
Key: "ns/name",
514514
Objects: append([]runtime.Object{
515-
ing(withBasicSpec, withSecondRevisionSpec, withGatewayAPIclass, withFinalizer, makeItReady),
516-
httpRoute(t, ing(withBasicSpec, withGatewayAPIclass), httpRouteReady),
515+
ing(withBasicSpec, withSecondRevisionSpec, withRewriteHost("current.default.svc.cluster.local"), withGatewayAPIclass, withFinalizer, makeItReady),
516+
httpRoute(t, ing(withBasicSpec, withRewriteHost("previous.default.svc.cluster.local"), withGatewayAPIclass), httpRouteReady),
517517
}, servicesAndEndpoints...),
518518
Ctx: withStatusManager(&fakeStatusManager{
519519
FakeIsProbeActive: func(types.NamespacedName) (status.ProbeState, bool) {
@@ -527,6 +527,7 @@ func TestReconcileProbing(t *testing.T) {
527527
Object: ing(
528528
withBasicSpec,
529529
withSecondRevisionSpec,
530+
withRewriteHost("current.default.svc.cluster.local"),
530531
withGatewayAPIclass,
531532
withFinalizer,
532533
makeItReady,
@@ -540,30 +541,34 @@ func TestReconcileProbing(t *testing.T) {
540541
Hostname: "example.com",
541542
Rules: []RuleBuilder{
542543
EndpointProbeRule{
543-
Namespace: "ns",
544-
Name: "goo",
545-
Hash: "ep-9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2",
546-
Port: 123,
544+
Namespace: "ns",
545+
Name: "goo",
546+
Hash: "ep-f7a1d68d4686969231731f087164ec98c24f3f1aae43c79ba5218b15bf2f63bc",
547+
Port: 123,
548+
RewriteHost: "previous.default.svc.cluster.local",
547549
},
548550
NormalRule{
549-
Namespace: "ns",
550-
Name: "goo",
551-
Port: 123,
552-
Weight: 100,
553-
},
554-
EndpointProbeRule{
555-
Namespace: "ns",
556-
Name: "second-revision",
557-
Path: "/.well-known/knative/revision/ns/second-revision",
558-
Hash: "ep-9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2",
559-
Port: 123,
560-
},
561-
EndpointProbeRule{
562-
Namespace: "ns",
563-
Name: "goo",
564-
Path: "/.well-known/knative/revision/ns/goo",
565-
Hash: "ep-9333a9a68409bb44f2a5f538d2d7c617e5338b6b6c1ebc5e00a19612a5c962c2",
566-
Port: 123,
551+
Namespace: "ns",
552+
Name: "goo",
553+
Port: 123,
554+
Weight: 100,
555+
RewriteHost: "previous.default.svc.cluster.local",
556+
},
557+
EndpointProbeRule{
558+
Namespace: "ns",
559+
Name: "second-revision",
560+
Path: "/.well-known/knative/revision/ns/second-revision",
561+
Hash: "ep-f7a1d68d4686969231731f087164ec98c24f3f1aae43c79ba5218b15bf2f63bc",
562+
Port: 123,
563+
RewriteHost: "current.default.svc.cluster.local",
564+
},
565+
EndpointProbeRule{
566+
Namespace: "ns",
567+
Name: "goo",
568+
Path: "/.well-known/knative/revision/ns/goo",
569+
Hash: "ep-f7a1d68d4686969231731f087164ec98c24f3f1aae43c79ba5218b15bf2f63bc",
570+
Port: 123,
571+
RewriteHost: "previous.default.svc.cluster.local",
567572
},
568573
},
569574
StatusConditions: []metav1.Condition{{

pkg/reconciler/ingress/lister_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ func withBackendAppendHeaders(key, val string) IngressOption {
600600
}
601601
}
602602

603+
func withRewriteHost(host string) IngressOption {
604+
return func(i *v1alpha1.Ingress) {
605+
i.Spec.Rules[0].HTTP.Paths[0].RewriteHost = host
606+
}
607+
}
608+
603609
func withInternalSpec(i *v1alpha1.Ingress) {
604610
i.Spec.Rules = append(i.Spec.Rules, v1alpha1.IngressRule{
605611
Hosts: []string{"foo.svc", "foo.svc.cluster.local"},

0 commit comments

Comments
 (0)