Skip to content

Commit

Permalink
Use ::1 host of the IPv6 subnet as the instance address
Browse files Browse the repository at this point in the history
  • Loading branch information
tibordp authored and fhofherr committed Jun 7, 2021
1 parent f8d6673 commit 659f728
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion hcloud/instances.go
Expand Up @@ -161,9 +161,13 @@ func (i *instances) nodeAddresses(ctx context.Context, server *hcloud.Server) []
)

if i.addressFamily == AddressFamilyIPv6 || i.addressFamily == AddressFamilyDualStack {
// For a given IPv6 network of 2001:db8:1234::/64, the instance address is 2001:db8:1234::1
host_address := server.PublicNet.IPv6.IP
host_address[len(host_address)-1] |= 0x01

addresses = append(
addresses,
v1.NodeAddress{Type: v1.NodeExternalIP, Address: server.PublicNet.IPv6.IP.String()},
v1.NodeAddress{Type: v1.NodeExternalIP, Address: host_address.String()},
)
}

Expand Down
12 changes: 6 additions & 6 deletions hcloud/instances_test.go
Expand Up @@ -37,7 +37,7 @@ func TestNodeAddressesByProviderID(t *testing.T) {
Name: "node15",
PublicNet: schema.ServerPublicNet{
IPv6: schema.ServerPublicNetIPv6{
IP: "2001:db8::1/64",
IP: "2001:db8:1234::/64",
},
IPv4: schema.ServerPublicNetIPv4{
IP: "131.232.99.1",
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestNodeAddresses(t *testing.T) {
Name: "node15",
PublicNet: schema.ServerPublicNet{
IPv6: schema.ServerPublicNetIPv6{
IP: "2001:db8::1",
IP: "2001:db8:1234::",
},
IPv4: schema.ServerPublicNetIPv4{
IP: "131.232.99.1",
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestNodeAddressesIPv6(t *testing.T) {
Name: "node15",
PublicNet: schema.ServerPublicNet{
IPv6: schema.ServerPublicNetIPv6{
IP: "2001:db8::1/64",
IP: "2001:db8:1234::/64",
},
IPv4: schema.ServerPublicNetIPv4{
IP: "131.232.99.1",
Expand All @@ -128,7 +128,7 @@ func TestNodeAddressesIPv6(t *testing.T) {
}
if len(addr) != 2 ||
addr[0].Type != v1.NodeHostName || addr[0].Address != "node15" ||
addr[1].Type != v1.NodeExternalIP || addr[1].Address != "2001:db8::1" {
addr[1].Type != v1.NodeExternalIP || addr[1].Address != "2001:db8:1234::1" {
t.Errorf("Unexpected node addresses: %v", addr)
}
}
Expand All @@ -147,7 +147,7 @@ func TestNodeAddressesDualStack(t *testing.T) {
Name: "node15",
PublicNet: schema.ServerPublicNet{
IPv6: schema.ServerPublicNetIPv6{
IP: "2001:db8::1/64",
IP: "2001:db8:1234::/64",
},
IPv4: schema.ServerPublicNetIPv4{
IP: "131.232.99.1",
Expand All @@ -165,7 +165,7 @@ func TestNodeAddressesDualStack(t *testing.T) {
}
if len(addr) != 3 ||
addr[0].Type != v1.NodeHostName || addr[0].Address != "node15" ||
addr[1].Type != v1.NodeExternalIP || addr[1].Address != "2001:db8::1" ||
addr[1].Type != v1.NodeExternalIP || addr[1].Address != "2001:db8:1234::1" ||
addr[2].Type != v1.NodeExternalIP || addr[2].Address != "131.232.99.1" {
t.Errorf("Unexpected node addresses: %v", addr)
}
Expand Down

0 comments on commit 659f728

Please sign in to comment.