mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 15:05:27 +00:00
ipvs proxier: use util proxy methods for getting local addresses
Signed-off-by: Andrew Sy Kim <kiman@vmware.com>
This commit is contained in:
parent
313c3b81e3
commit
126bf5a231
@ -990,33 +990,6 @@ func (proxier *Proxier) OnNodeSynced() {
|
|||||||
// EntryInvalidErr indicates if an ipset entry is invalid or not
|
// EntryInvalidErr indicates if an ipset entry is invalid or not
|
||||||
const EntryInvalidErr = "error adding entry %s to ipset %s"
|
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.
|
// This is where all of the ipvs calls happen.
|
||||||
// assumes proxier.mu is held
|
// assumes proxier.mu is held
|
||||||
func (proxier *Proxier) syncProxyRules() {
|
func (proxier *Proxier) syncProxyRules() {
|
||||||
@ -1036,9 +1009,11 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
|
klog.V(4).Infof("syncProxyRules took %v", time.Since(start))
|
||||||
}()
|
}()
|
||||||
|
|
||||||
localAddrs, err := getLocalAddrs()
|
localAddrs, err := utilproxy.GetLocalAddrs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("Failed to get local addresses during proxy sync: %v", err)
|
klog.Errorf("Failed to get local addresses during proxy sync: %v, assuming external IPs are not local", err)
|
||||||
|
} else if len(localAddrs) == 0 {
|
||||||
|
klog.Warning("No local addresses found, assuming all external IPs are not local")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We assume that if this was called, we really want to sync them,
|
// We assume that if this was called, we really want to sync them,
|
||||||
@ -1222,9 +1197,10 @@ func (proxier *Proxier) syncProxyRules() {
|
|||||||
|
|
||||||
// Capture externalIPs.
|
// Capture externalIPs.
|
||||||
for _, externalIP := range svcInfo.ExternalIPStrings() {
|
for _, externalIP := range svcInfo.ExternalIPStrings() {
|
||||||
if len(localAddrs) == 0 {
|
// If the "external" IP happens to be an IP that is local to this
|
||||||
klog.Errorf("couldn't find any local IPs, assuming %s is not local", externalIP)
|
// machine, hold the local port open so no other process can open it
|
||||||
} else if (svcInfo.Protocol() != v1.ProtocolSCTP) && ipExists(net.ParseIP(externalIP), localAddrs) {
|
// (because the socket might open but it would never work).
|
||||||
|
if len(localAddrs) > 0 && (svcInfo.Protocol() != v1.ProtocolSCTP) && utilproxy.ContainsIP(localAddrs, net.ParseIP(externalIP)) {
|
||||||
// We do not start listening on SCTP ports, according to our agreement in the SCTP support KEP
|
// We do not start listening on SCTP ports, according to our agreement in the SCTP support KEP
|
||||||
lp := utilproxy.LocalPort{
|
lp := utilproxy.LocalPort{
|
||||||
Description: "externalIP for " + svcNameString,
|
Description: "externalIP for " + svcNameString,
|
||||||
|
Loading…
Reference in New Issue
Block a user