forked from hetznercloud/hcloud-cloud-controller-manager
-
Notifications
You must be signed in to change notification settings - Fork 8
✨ lb: pick the address family for dedicated server targets #87
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
Merged
Merged
Changes from all commits
Commits
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
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
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
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,47 @@ | ||
| // Package addressfamily selects which IP addresses of a server are used. It is | ||
| // shared by the node address code and the load balancer target code. | ||
| package addressfamily | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strings" | ||
| ) | ||
|
|
||
| // Family selects which IP addresses of a server are used. | ||
| type Family int | ||
|
|
||
| const ( | ||
| // DualStack uses both the IPv4 and the IPv6 address. | ||
| DualStack Family = iota | ||
| // IPv6 uses the IPv6 address only. | ||
| IPv6 | ||
| // IPv4 uses the IPv4 address only. | ||
| IPv4 | ||
| ) | ||
|
|
||
| // ErrInvalid is returned by Parse for a value that names no address family. | ||
| var ErrInvalid = errors.New("invalid value, expected one of: ipv4,ipv6,dualstack") | ||
|
|
||
| // Parse reads the value used in environment variables and service annotations. | ||
| func Parse(v string) (Family, error) { | ||
| switch strings.ToLower(v) { | ||
| case "ipv6": | ||
| return IPv6, nil | ||
| case "ipv4": | ||
| return IPv4, nil | ||
| case "dualstack": | ||
| return DualStack, nil | ||
| default: | ||
| return -1, ErrInvalid | ||
| } | ||
| } | ||
|
|
||
| // UsesIPv4 reports whether f covers the IPv4 address. | ||
| func (f Family) UsesIPv4() bool { | ||
| return f == IPv4 || f == DualStack | ||
| } | ||
|
|
||
| // UsesIPv6 reports whether f covers the IPv6 address. | ||
| func (f Family) UsesIPv6() bool { | ||
| return f == IPv6 || f == DualStack | ||
| } |
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,56 @@ | ||
| package addressfamily_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/syself/hetzner-cloud-controller-manager/internal/addressfamily" | ||
| ) | ||
|
|
||
| func TestParse(t *testing.T) { | ||
| tests := []struct { | ||
| in string | ||
| want addressfamily.Family | ||
| wantErr bool | ||
| }{ | ||
| {in: "ipv4", want: addressfamily.IPv4}, | ||
| {in: "ipv6", want: addressfamily.IPv6}, | ||
| {in: "dualstack", want: addressfamily.DualStack}, | ||
| {in: "IPv4", want: addressfamily.IPv4}, | ||
| {in: "DualStack", want: addressfamily.DualStack}, | ||
| {in: "", wantErr: true}, | ||
| {in: "both", wantErr: true}, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.in, func(t *testing.T) { | ||
| got, err := addressfamily.Parse(test.in) | ||
| if test.wantErr { | ||
| assert.ErrorIs(t, err, addressfamily.ErrInvalid) | ||
| return | ||
| } | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, test.want, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestFamilyUses(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| family addressfamily.Family | ||
| wantIPv4 bool | ||
| wantIPv6 bool | ||
| }{ | ||
| {name: "ipv4", family: addressfamily.IPv4, wantIPv4: true}, | ||
| {name: "ipv6", family: addressfamily.IPv6, wantIPv6: true}, | ||
| {name: "dualstack", family: addressfamily.DualStack, wantIPv4: true, wantIPv6: true}, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.name, func(t *testing.T) { | ||
| assert.Equal(t, test.wantIPv4, test.family.UsesIPv4()) | ||
| assert.Equal(t, test.wantIPv6, test.family.UsesIPv6()) | ||
| }) | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
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.
why not HCLOUD_ADDRESS_FAMILY_ROBOT? This would align with the existing HCLOUD_INSTANCES_ADDRESS_FAMILY which seems to be the equivalent for hcloud. This weird naming pattern that everything starts with "HCLOUD" makes "ROBOT_ADDRESS_FAMILY" impossible
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.
HCLOUD_INSTANCES_ADDRESS_FAMILY sets node addresses and already covers robot nodes, so it is not really the equivalent, this one only picks LB targets. I would keep the HCLOUD_LOAD_BALANCERS_ prefix, HCLOUD_ROBOT_ADDRESS_FAMILY would clash with that node meaning. if it is just length, drop TARGET
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.
okay!
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.
then whatever you suggest