-
Notifications
You must be signed in to change notification settings - Fork 618
Order the endpoint addresses for the ingress-use-waypoint #13085
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
Open
ymesika
wants to merge
2
commits into
kgateway-dev:main
Choose a base branch
from
ymesika:order-addr-in-waypoint-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+389
−18
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
pkg/kgateway/extensions2/plugins/waypoint/plugin_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package waypoint | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| apisettings "github.com/kgateway-dev/kgateway/v2/api/settings" | ||
| ) | ||
|
|
||
| func TestSortAddressesByDnsLookupFamily(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| addresses []string | ||
| settings *apisettings.Settings | ||
| want []string | ||
| }{ | ||
| { | ||
| name: "nil settings defaults to V4_PREFERRED", | ||
| addresses: []string{"10.0.0.1", "2001:db8::1"}, | ||
| settings: nil, | ||
| want: []string{"10.0.0.1", "2001:db8::1"}, | ||
| }, | ||
| { | ||
| name: "ALL mode returns all addresses unchanged", | ||
| addresses: []string{"2001:db8::1", "10.0.0.1", "10.0.0.2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyAll, | ||
| }, | ||
| want: []string{"2001:db8::1", "10.0.0.1", "10.0.0.2"}, | ||
| }, | ||
| { | ||
| name: "V4_ONLY returns only IPv4 addresses", | ||
| addresses: []string{"10.0.0.1", "2001:db8::1", "10.0.0.2", "2001:db8::2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV4Only, | ||
| }, | ||
| want: []string{"10.0.0.1", "10.0.0.2"}, | ||
| }, | ||
| { | ||
| name: "V4_ONLY with no IPv4 returns empty", | ||
| addresses: []string{"2001:db8::1", "2001:db8::2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV4Only, | ||
| }, | ||
| want: []string{}, | ||
| }, | ||
| { | ||
| name: "V6_ONLY returns only IPv6 addresses", | ||
| addresses: []string{"10.0.0.1", "2001:db8::1", "10.0.0.2", "2001:db8::2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV6Only, | ||
| }, | ||
| want: []string{"2001:db8::1", "2001:db8::2"}, | ||
| }, | ||
| { | ||
| name: "V6_ONLY with no IPv6 returns empty", | ||
| addresses: []string{"10.0.0.1", "10.0.0.2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV6Only, | ||
| }, | ||
| want: []string{}, | ||
| }, | ||
| { | ||
| name: "V4_PREFERRED returns IPv4 first, then IPv6", | ||
| addresses: []string{"2001:db8::1", "10.0.0.1", "2001:db8::2", "10.0.0.2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV4Preferred, | ||
| }, | ||
| want: []string{"10.0.0.1", "10.0.0.2", "2001:db8::1", "2001:db8::2"}, | ||
| }, | ||
| { | ||
| name: "V4_PREFERRED with no IPv4 returns IPv6 only", | ||
| addresses: []string{"2001:db8::1", "2001:db8::2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV4Preferred, | ||
| }, | ||
| want: []string{"2001:db8::1", "2001:db8::2"}, | ||
| }, | ||
| { | ||
| name: "AUTO returns IPv6 first, then IPv4", | ||
| addresses: []string{"10.0.0.1", "2001:db8::1", "10.0.0.2", "2001:db8::2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyAuto, | ||
| }, | ||
| want: []string{"2001:db8::1", "2001:db8::2", "10.0.0.1", "10.0.0.2"}, | ||
| }, | ||
| { | ||
| name: "AUTO with no IPv6 returns IPv4 only", | ||
| addresses: []string{"10.0.0.1", "10.0.0.2"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyAuto, | ||
| }, | ||
| want: []string{"10.0.0.1", "10.0.0.2"}, | ||
| }, | ||
| { | ||
| name: "invalid addresses are skipped", | ||
| addresses: []string{"10.0.0.1", "invalid-address", "2001:db8::1", "not-an-ip"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV4Preferred, | ||
| }, | ||
| want: []string{"10.0.0.1", "2001:db8::1"}, | ||
| }, | ||
| { | ||
| name: "empty addresses returns empty", | ||
| addresses: []string{}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamilyV4Preferred, | ||
| }, | ||
| want: []string{}, | ||
| }, | ||
| { | ||
| name: "unknown DNS lookup family defaults to V4_PREFERRED", | ||
| addresses: []string{"2001:db8::1", "10.0.0.1"}, | ||
| settings: &apisettings.Settings{ | ||
| DnsLookupFamily: apisettings.DnsLookupFamily("UNKNOWN"), | ||
| }, | ||
| want: []string{"10.0.0.1", "2001:db8::1"}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := sortAddressesByDnsLookupFamily(tt.addresses, tt.settings) | ||
| // Normalize nil and empty slices for comparison | ||
| if got == nil { | ||
| got = []string{} | ||
| } | ||
| if tt.want == nil { | ||
| tt.want = []string{} | ||
| } | ||
| assert.Equal(t, tt.want, got, "sortAddressesByDnsLookupFamily() = %v, want %v", got, tt.want) | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.