mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Simplification and cleanup
This commit is contained in:
parent
8d63750c35
commit
32f8066119
@ -298,35 +298,6 @@ type Proxier struct {
|
|||||||
serviceNoLocalEndpointsExternal sets.Set[string]
|
serviceNoLocalEndpointsExternal sets.Set[string]
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodeIPs returns all LOCAL type IP addresses from host which are
|
|
||||||
// taken as the Node IPs of NodePort service. Filtered addresses:
|
|
||||||
//
|
|
||||||
// - Loopback addresses
|
|
||||||
// - Addresses of the "other" family (not handled by this proxier instance)
|
|
||||||
// - Link-local IPv6 addresses
|
|
||||||
// - Addresses on the created dummy device `kube-ipvs0`
|
|
||||||
func (p *Proxier) ipGetterNodeIPs() (ips []net.IP, err error) {
|
|
||||||
|
|
||||||
nodeAddress, err := p.netlinkHandle.GetAllLocalAddresses()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error listing LOCAL type addresses from host, error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// We must exclude the addresses on the IPVS dummy interface
|
|
||||||
bindedAddress, err := p.netlinkHandle.GetLocalAddresses(defaultDummyDevice)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
ipset := nodeAddress.Difference(bindedAddress)
|
|
||||||
|
|
||||||
// translate ip string to IP
|
|
||||||
for _, ipStr := range ipset.UnsortedList() {
|
|
||||||
a := netutils.ParseIPSloppy(ipStr)
|
|
||||||
ips = append(ips, a)
|
|
||||||
}
|
|
||||||
return ips, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Proxier implements proxy.Provider
|
// Proxier implements proxy.Provider
|
||||||
var _ proxy.Provider = &Proxier{}
|
var _ proxy.Provider = &Proxier{}
|
||||||
|
|
||||||
@ -1068,28 +1039,19 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if utilproxy.IsZeroCIDR(address) {
|
if utilproxy.IsZeroCIDR(address) {
|
||||||
nodeIPs, err = proxier.ipGetterNodeIPs()
|
nodeIPs = nil
|
||||||
if err != nil {
|
for _, ipStr := range nodeAddressSet.UnsortedList() {
|
||||||
klog.ErrorS(err, "Failed to list all node IPs from host")
|
nodeIPs = append(nodeIPs, netutils.ParseIPSloppy(ipStr))
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
nodeIPs = append(nodeIPs, a)
|
if getIPFamily(a) == proxier.ipFamily {
|
||||||
|
nodeIPs = append(nodeIPs, a)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter node IPs by proxier ipfamily
|
|
||||||
idx := 0
|
|
||||||
for _, nodeIP := range nodeIPs {
|
|
||||||
if (proxier.ipFamily == v1.IPv6Protocol) == netutils.IsIPv6(nodeIP) {
|
|
||||||
nodeIPs[idx] = nodeIP
|
|
||||||
idx++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// reset slice to filtered entries
|
|
||||||
nodeIPs = nodeIPs[:idx]
|
|
||||||
|
|
||||||
// Build IPVS rules for each service.
|
// Build IPVS rules for each service.
|
||||||
for svcPortName, svcPort := range proxier.svcPortMap {
|
for svcPortName, svcPort := range proxier.svcPortMap {
|
||||||
svcInfo, ok := svcPort.(*servicePortInfo)
|
svcInfo, ok := svcPort.(*servicePortInfo)
|
||||||
|
Loading…
Reference in New Issue
Block a user