-
Notifications
You must be signed in to change notification settings - Fork 139
Listener Isolation for hostnames occupied by other listeners #3061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3061 +/- ##
==========================================
+ Coverage 89.95% 90.00% +0.04%
==========================================
Files 111 111
Lines 11453 11510 +57
Branches 50 50
==========================================
+ Hits 10303 10360 +57
Misses 1089 1089
Partials 61 61 ☔ View full report in Codecov by Sentry. |
8907fe7
to
0aacc35
Compare
0aacc35
to
df7c72a
Compare
This branch should be named with |
} | ||
|
||
var routes []*L4Route | ||
l7routes := make([]*L7Route, 0, len(l7Routes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we name the l7routes map something different? Using the same name here is confusing at first glance.
|
||
rk := CreateRouteKey(route.Source) | ||
|
||
listenerHostnameMap := make(map[string]string, len(attachableListeners)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't used anywhere.
} | ||
} | ||
|
||
isolatedHostnames := removeHostnames(hostnames, hostnamesToRemoves) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to use slices.Delete()
instead, using the index of the h
entry in the hostnames
list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So when using slices.Delete(arr, i, j) --> we would have to specify the index which panics if out of bounds. And wouldn't deleting elements while looping the array lead to similar issues with indexing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you would be deleting while looping, you build the list first, then delete afterwards like you do now.
"tr1", | ||
helpers.GetPointer[gatewayv1.SectionName]("empty-hostname"), | ||
"test", | ||
[]gatewayv1.Hostname{"bar.com", "*.example.com", "*.foo.example.com", "abc.foo.example.com"}..., |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move these out into a variable.
} | ||
} | ||
|
||
acceptedHostnames1 := map[string][]string{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's name these better to reflect the listener name.
"no-match": {}, | ||
} | ||
|
||
tests := []struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't seem like we need a list of test cases here since you only have one.
|
||
for _, route := range tt.routes { | ||
for routeName, refs := range tt.expectedResult { | ||
if route.Source.GetName() == routeName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be an issue where a dev changes the name of one of the routes in the expectedResult, and then this condition never gets checked and the test passes.
} | ||
} | ||
|
||
func TestIsolateL7Listeners(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comments with this test as the last one.
isolateL4RouteListeners(l4routes, gw.Listeners) | ||
} | ||
|
||
// isolateL7RouteListeners ensures listener isolation for all L7Routes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both functions are almost identical. Combine them into a single generic function to improve maintainability. You can refactor the logic into a single function to reduce redundancy.
Proposed changes
Write a clear and concise description that helps reviewers understand the purpose and impact of your changes. Use the
following format:
Problem: Users want to be able to isolate listeners for routes.
Solution: Adds functionality to filter out listener hostnames from the accepted hostnames of a route which belong to another listener.
Testing:
Listeners that are configured with the gateway
HTTPRoutes
For listener isolation to work, we need
empty-hostname
to not get configured with listenerswildcard-example-com, wildcard-foo-example-com, abc-foo-example-com
. When collecting accepted hostnames, the routeattaches-to-empty-hostname-with-hostname-intersection
attaches to all hostnames since it is attached to catch-all listener (no hostname provided), but these hostnames are part of other listeners.So,
wildcard-example-com
to not get configured with listenerswildcard-foo-example-com, abc-foo-example-com
When collecting accepted hostnames, the route
attaches-to-wildcard-example-com-with-hostname-intersection
is associated to a*.example.com
so it attaches to these hostnames. But these listeners need to be isolated since the hostname associated with them is part of a listener attached to another route.Please focus on (optional): If you any specific areas where you would like reviewers to focus their attention or provide
specific feedback, add them here.
Closes #1175
Checklist
Before creating a PR, run through this checklist and mark each as complete.
Release notes
If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.