From b31756e8f3937d1a6cdbd9704c4b6eebed6ea9f9 Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Tue, 1 Oct 2024 16:44:14 -0400 Subject: [PATCH 1/2] handle cases where the internal-ip is already set (e.g. kubelet) --- cloud/linode/instances.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cloud/linode/instances.go b/cloud/linode/instances.go index 0a78e5d6..61e48b6d 100644 --- a/cloud/linode/instances.go +++ b/cloud/linode/instances.go @@ -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{ From ff4c10f5e6852d800704a26d00bd55af1b1b55ce Mon Sep 17 00:00:00 2001 From: Ashley Dumaine Date: Wed, 2 Oct 2024 12:25:48 -0400 Subject: [PATCH 2/2] add test for existing internal IP on node --- cloud/linode/instances_test.go | 42 ++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/cloud/linode/instances_test.go b/cloud/linode/instances_test.go index 775f288e..b85fc804 100644 --- a/cloud/linode/instances_test.go +++ b/cloud/linode/instances_test.go @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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, }, @@ -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 { @@ -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)