mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
Merge pull request #84924 from njuicsgz/master
proxy/ipvs: only get local addresses once per sync
This commit is contained in:
commit
f61fbca757
@ -899,6 +899,33 @@ func (proxier *Proxier) OnEndpointSlicesSynced() {
|
||||
// EntryInvalidErr indicates if an ipset entry is invalid or not
|
||||
const EntryInvalidErr = "error adding entry %s to ipset %s"
|
||||
|
||||
func getLocalAddrs() ([]net.IP, error) {
|
||||
var localAddrs []net.IP
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
ip, _, err := net.ParseCIDR(addr.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localAddrs = append(localAddrs, ip)
|
||||
}
|
||||
return localAddrs, nil
|
||||
}
|
||||
|
||||
func ipExists(ip net.IP, addrs []net.IP) bool {
|
||||
for _, addr := range addrs {
|
||||
if ip.Equal(addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// This is where all of the ipvs calls happen.
|
||||
// assumes proxier.mu is held
|
||||
func (proxier *Proxier) syncProxyRules() {
|
||||
@ -919,6 +946,11 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
|
||||
}()
|
||||
|
||||
localAddrs, err := getLocalAddrs()
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to get local addresses during proxy sync: %v", err)
|
||||
}
|
||||
|
||||
// We assume that if this was called, we really want to sync them,
|
||||
// even if nothing changed in the meantime. In other words, callers are
|
||||
// responsible for detecting no-op changes and not calling this function.
|
||||
@ -955,7 +987,7 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
proxier.createAndLinkeKubeChain()
|
||||
|
||||
// make sure dummy interface exists in the system where ipvs Proxier will bind service address on it
|
||||
_, err := proxier.netlinkHandle.EnsureDummyDevice(DefaultDummyDevice)
|
||||
_, err = proxier.netlinkHandle.EnsureDummyDevice(DefaultDummyDevice)
|
||||
if err != nil {
|
||||
klog.Errorf("Failed to create dummy interface: %s, error: %v", DefaultDummyDevice, err)
|
||||
return
|
||||
@ -1100,11 +1132,10 @@ func (proxier *Proxier) syncProxyRules() {
|
||||
|
||||
// Capture externalIPs.
|
||||
for _, externalIP := range svcInfo.ExternalIPStrings() {
|
||||
if local, err := utilproxy.IsLocalIP(externalIP); err != nil {
|
||||
klog.Errorf("can't determine if IP is local, assuming not: %v", err)
|
||||
// We do not start listening on SCTP ports, according to our agreement in the
|
||||
// SCTP support KEP
|
||||
} else if local && (svcInfo.Protocol() != v1.ProtocolSCTP) {
|
||||
if len(localAddrs) == 0 {
|
||||
klog.Errorf("couldn't find any local IPs, assuming %s is not local", externalIP)
|
||||
} else if (svcInfo.Protocol() != v1.ProtocolSCTP) && ipExists(net.ParseIP(externalIP), localAddrs) {
|
||||
// We do not start listening on SCTP ports, according to our agreement in the SCTP support KEP
|
||||
lp := utilproxy.LocalPort{
|
||||
Description: "externalIP for " + svcNameString,
|
||||
IP: externalIP,
|
||||
|
Loading…
Reference in New Issue
Block a user