Skip to content
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

[fix] handle cases where the internal-ip is already set (e.g. kubelet) #236

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make sure same ip is not already present in the slice? For example, if this InstanceMetadata() gets called again after 5-10 mins, then we'll end up adding all the existing ip's again into the slice. Not sure if k8s automatically handles such case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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
Loading