Skip to content

fix: add OwnerReference for HTTPRouteFilter#888

Merged
mathetake merged 8 commits intoenvoyproxy:mainfrom
googs1025:defaultHTTPRouteFilters
Jul 15, 2025
Merged

fix: add OwnerReference for HTTPRouteFilter#888
mathetake merged 8 commits intoenvoyproxy:mainfrom
googs1025:defaultHTTPRouteFilters

Conversation

@googs1025
Copy link
Copy Markdown
Contributor

Description
This commit add OwnerReference for HTTPRouteFilter when creating

Related Issues/PRs (if applicable)

Fixes: #873

Special notes for reviewers (if applicable)
None

Signed-off-by: googs1025 <googs1025@gmail.com>
@googs1025 googs1025 requested a review from a team as a code owner July 14, 2025 14:50
Signed-off-by: googs1025 <googs1025@gmail.com>
Signed-off-by: googs1025 <googs1025@gmail.com>
@googs1025 googs1025 force-pushed the defaultHTTPRouteFilters branch from e74821a to 8228055 Compare July 14, 2025 14:55
Signed-off-by: googs1025 <googs1025@gmail.com>
@googs1025 googs1025 force-pushed the defaultHTTPRouteFilters branch from 5f52d75 to 7206728 Compare July 14, 2025 15:04
Signed-off-by: googs1025 <googs1025@gmail.com>
Signed-off-by: googs1025 <googs1025@gmail.com>
@googs1025 googs1025 marked this pull request as draft July 14, 2025 16:14
@googs1025 googs1025 force-pushed the defaultHTTPRouteFilters branch from fead319 to 1dea5c1 Compare July 14, 2025 16:22
Signed-off-by: googs1025 <googs1025@gmail.com>
@googs1025 googs1025 force-pushed the defaultHTTPRouteFilters branch from 1dea5c1 to 6449c97 Compare July 14, 2025 16:29
if err := c.client.Get(ctx, client.ObjectKey{Name: base.Name, Namespace: base.Namespace}, &f); err != nil {
if apierrors.IsNotFound(err) {
if err = ctrlutil.SetControllerReference(aiGatewayRoute, base, c.client.Scheme()); err != nil {
return fmt.Errorf("failed to set owner reference for HTTPRouteFilter %s: %w", base.Name, err)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a panic just like my comment in another pr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +311 to +322
var f egv1a1.HTTPRouteFilter
err = c.Get(t.Context(), hostRewriteKey, &f)
if err == nil {
return true
}
if !apierrors.IsNotFound(err) {
t.Logf("unexpected error when fetching filter %s: %v", hostRewriteKey, err)
return false
}
ok, _ := ctrlutil.HasOwnerReference(f.OwnerReferences, origin, c.Scheme())
require.True(t, ok, "expected hostRewriteFilter to have owner reference to AIGatewayRoute")
return false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very weird. you are checking if err == nil at the beginning and at the bottom you are checking ownerreference. you should check the owner reference on ok case

Suggested change
var f egv1a1.HTTPRouteFilter
err = c.Get(t.Context(), hostRewriteKey, &f)
if err == nil {
return true
}
if !apierrors.IsNotFound(err) {
t.Logf("unexpected error when fetching filter %s: %v", hostRewriteKey, err)
return false
}
ok, _ := ctrlutil.HasOwnerReference(f.OwnerReferences, origin, c.Scheme())
require.True(t, ok, "expected hostRewriteFilter to have owner reference to AIGatewayRoute")
return false
var f egv1a1.HTTPRouteFilter
err = c.Get(t.Context(), hostRewriteKey, &f)
if err != nil {
t.Logf("expected to get hostRewriteFilter %s, but got error: %v", hostRewriteHTTPFilterName, err)
return false
}
ok, _ := ctrlutil.HasOwnerReference(f.OwnerReferences, origin, c.Scheme())
require.True(t, ok, "expected hostRewriteFilter to have owner reference to AIGatewayRoute")
return true

Copy link
Copy Markdown
Contributor Author

@googs1025 googs1025 Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing out that. this was a logic error...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add the deletion check in t.Run("delete route", func(t *testing.T) { below?

Copy link
Copy Markdown
Contributor Author

@googs1025 googs1025 Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The envtest.Environment does not seem to have gc deletion. I actually tested it and it seems that does not work.

some issue: kubernetes-sigs/kubebuilder#1175

docs: https://github.com/kubernetes-sigs/kubebuilder/blob/master/docs/book/src/reference/envtest.md#testing-considerations

Signed-off-by: googs1025 <googs1025@gmail.com>
@googs1025 googs1025 marked this pull request as ready for review July 15, 2025 01:50
Copy link
Copy Markdown
Member

@mathetake mathetake left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contributing!

@mathetake mathetake merged commit 3718197 into envoyproxy:main Jul 15, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create default filters per AIGatewayRoute with ownerReference to it

2 participants