Skip to content

Commit

Permalink
Merge pull request #236 from linode/internal-ip
Browse files Browse the repository at this point in the history
[fix] handle cases where the internal-ip is already set (e.g. kubelet)
  • Loading branch information
AshleyDumaine authored Oct 2, 2024
2 parents 42e3341 + ff4c10f commit d37c425
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
7 changes: 7 additions & 0 deletions cloud/linode/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
addresses = append(addresses, v1.NodeAddress{Type: ip.ipType, Address: ip.ip})
}

// include IPs set by kubelet for internal node IP
for _, addr := range node.Status.Addresses {
if addr.Type == v1.NodeInternalIP {
addresses = append(addresses, v1.NodeAddress{Type: v1.NodeInternalIP, Address: addr.Address})
}
}

klog.Infof("Instance %s, assembled IP addresses: %v", node.Name, addresses)
// note that Zone is omitted as it's not a thing in Linode
meta := &cloudprovider.InstanceMetadata{
Expand Down
42 changes: 35 additions & 7 deletions cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,29 @@ func TestMetadataRetrieval(t *testing.T) {
})

ipTests := []struct {
name string
inputIPv4s []string
inputIPv6 string
externalNetwork string
outputAddresses []v1.NodeAddress
expectedErr error
name string
inputIPv4s []string
inputIPv6 string
externalNetwork string
existingAddresses []v1.NodeAddress
outputAddresses []v1.NodeAddress
expectedErr error
}{
{"no IPs", nil, "", "", nil, instanceNoIPAddressesError{192910}},
{
"no IPs",
nil,
"",
"",
nil,
nil,
instanceNoIPAddressesError{192910},
},
{
"one public, one private",
[]string{"32.74.121.25", "192.168.121.42"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
nil,
},
Expand All @@ -164,6 +174,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"32.74.121.25"},
"2600:3c06::f03c:94ff:fe1e:e072",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "2600:3c06::f03c:94ff:fe1e:e072"}},
nil,
},
Expand All @@ -172,6 +183,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"32.74.121.25"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}},
nil,
},
Expand All @@ -180,6 +192,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"192.168.121.42"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}},
nil,
},
Expand All @@ -188,6 +201,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"32.74.121.25", "32.74.121.22"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "32.74.121.25"}, {Type: v1.NodeExternalIP, Address: "32.74.121.22"}},
nil,
},
Expand All @@ -196,6 +210,7 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"192.168.121.42", "10.0.2.15"},
"",
"",
nil,
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.2.15"}},
nil,
},
Expand All @@ -204,9 +219,19 @@ func TestMetadataRetrieval(t *testing.T) {
[]string{"192.168.121.42", "10.0.2.15"},
"",
"10.0.2.0/16",
nil,
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeExternalIP, Address: "10.0.2.15"}},
nil,
},
{
"one private addresses, one existing internal IP set on the node",
[]string{"192.168.121.42"},
"",
"",
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "10.0.0.1"}},
[]v1.NodeAddress{{Type: v1.NodeInternalIP, Address: "192.168.121.42"}, {Type: v1.NodeInternalIP, Address: "10.0.0.1"}},
nil,
},
}

for _, test := range ipTests {
Expand All @@ -221,6 +246,9 @@ func TestMetadataRetrieval(t *testing.T) {
} else {
_, Options.LinodeExternalNetwork, _ = net.ParseCIDR(test.externalNetwork)
}
if test.existingAddresses != nil {
node.Status.Addresses = append(node.Status.Addresses, test.existingAddresses...)
}
ips := make([]*net.IP, 0, len(test.inputIPv4s))
for _, ip := range test.inputIPv4s {
parsed := net.ParseIP(ip)
Expand Down

0 comments on commit d37c425

Please sign in to comment.