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] : remove duplicate ip's to avoid patching error #243

Merged
merged 1 commit into from
Nov 13, 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
18 changes: 14 additions & 4 deletions cloud/linode/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,19 +279,29 @@
return nil, err
}

addresses := []v1.NodeAddress{{Type: v1.NodeHostName, Address: linode.Label}}

uniqueAddrs := make(map[string]v1.NodeAddressType, len(node.Status.Addresses)+len(ips))
for _, ip := range ips {
addresses = append(addresses, v1.NodeAddress{Type: ip.ipType, Address: ip.ip})
if _, ok := uniqueAddrs[ip.ip]; ok {
continue

Check warning on line 285 in cloud/linode/instances.go

View check run for this annotation

Codecov / codecov/patch

cloud/linode/instances.go#L285

Added line #L285 was not covered by tests
}
uniqueAddrs[ip.ip] = ip.ipType
}

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

addresses := []v1.NodeAddress{{Type: v1.NodeHostName, Address: linode.Label}}
for k, v := range uniqueAddrs {
addresses = append(addresses, v1.NodeAddress{Type: v, Address: k})
}

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
8 changes: 8 additions & 0 deletions cloud/linode/instances_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"fmt"
"net"
"slices"
"strconv"
"strings"
"testing"

"github.com/golang/mock/gomock"
Expand Down Expand Up @@ -273,6 +275,12 @@ func TestMetadataRetrieval(t *testing.T) {
addresses := append([]v1.NodeAddress{
{Type: v1.NodeHostName, Address: name},
}, test.outputAddresses...)
slices.SortFunc(meta.NodeAddresses, func(a v1.NodeAddress, b v1.NodeAddress) int {
return strings.Compare(a.Address, b.Address)
})
slices.SortFunc(addresses, func(a, b v1.NodeAddress) int {
return strings.Compare(a.Address, b.Address)
})
assert.Equal(t, meta.NodeAddresses, addresses)
}
})
Expand Down
Loading