Skip to content

Commit

Permalink
remove duplicate ip's to avoid patching error
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulait committed Nov 13, 2024
1 parent 1b046af commit 30163b6
Showing 1 changed file with 14 additions and 4 deletions.
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 @@ func (i *instances) InstanceMetadata(ctx context.Context, node *v1.Node) (*cloud
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

0 comments on commit 30163b6

Please sign in to comment.