talos/pkg/machinery/nethelpers/std_netaddr.go
Andrey Smirnov 20a5640857
fix: introduce 'routed' NodeAddresses and use them in kubelet
Same change will be done for the etcd in a separate PR.

The idea is to introduce a subset of `current` addresses: `routed`
addresses don't include external IPs (like AWS), as they are not on the
node, and excludes SideroLink IPs (as these are not routeable).

Reimplement `kubelet` nodeIP selection based on the new resources
removing the reliance on `net.IPAddrs`.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-08-11 21:11:47 +04:00

30 lines
785 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package nethelpers
import (
"net"
"inet.af/netaddr"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
)
// MapStdToNetAddr converts a slice of net.IP to a slice of netaddr.Addr.
func MapStdToNetAddr(in []net.IP) []netaddr.IP {
return slices.Map(in, func(std net.IP) netaddr.IP {
addr, _ := netaddr.FromStdIP(std)
return addr.Unmap()
})
}
// MapNetAddrToStd converts a slice of netaddr.Addr to a slice of net.IP.
func MapNetAddrToStd(in []netaddr.IP) []net.IP {
return slices.Map(in, func(addr netaddr.IP) net.IP {
return addr.Unmap().IPAddr().IP
})
}