fix localport open - iptables part changes

This commit is contained in:
m1093782566 2018-04-02 11:53:12 +08:00
parent 04634cb198
commit b2f5c8e610

View File

@ -960,12 +960,34 @@ func (proxier *Proxier) syncProxyRules() {
if svcInfo.NodePort != 0 {
// Hold the local port open so no other process can open it
// (because the socket might open but it would never work).
addresses, err := utilproxy.GetNodeAddresses(proxier.nodePortAddresses, proxier.networkInterfacer)
if err != nil {
glog.Errorf("Failed to get node ip address matching nodeport cidr")
continue
}
lps := make([]utilproxy.LocalPort, 0)
for address := range addresses {
if utilproxy.IsZeroCIDR(address) {
lp := utilproxy.LocalPort{
Description: "nodePort for " + svcNameString,
IP: "",
Port: svcInfo.NodePort,
Protocol: protocol,
}
lps = append(lps, lp)
break
}
lp := utilproxy.LocalPort{
Description: "nodePort for " + svcNameString,
IP: address,
Port: svcInfo.NodePort,
Protocol: protocol,
}
lps = append(lps, lp)
}
for _, lp := range lps {
if proxier.portsMap[lp] != nil {
glog.V(4).Infof("Port %s was open before and is still needed", lp.String())
replacementPortsMap[lp] = proxier.portsMap[lp]
@ -987,6 +1009,7 @@ func (proxier *Proxier) syncProxyRules() {
}
replacementPortsMap[lp] = socket
}
}
if hasEndpoints {
args = append(args[:0],