mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
reuse iptablesContainerPortalArgs
This commit is contained in:
parent
afcc156806
commit
8608901e24
@ -708,7 +708,7 @@ func (proxier *Proxier) openNodePort(nodePort int, protocol api.Protocol, proxyI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle traffic from containers.
|
// Handle traffic from containers.
|
||||||
args := proxier.iptablesContainerNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name)
|
args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name)
|
||||||
existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerNodePortChain, args...)
|
existed, err := proxier.iptables.EnsureRule(iptables.Append, iptables.TableNAT, iptablesContainerNodePortChain, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Errorf("Failed to install iptables %s rule for service %q", iptablesContainerNodePortChain, name)
|
glog.Errorf("Failed to install iptables %s rule for service %q", iptablesContainerNodePortChain, name)
|
||||||
@ -811,7 +811,7 @@ func (proxier *Proxier) closeNodePort(nodePort int, protocol api.Protocol, proxy
|
|||||||
el := []error{}
|
el := []error{}
|
||||||
|
|
||||||
// Handle traffic from containers.
|
// Handle traffic from containers.
|
||||||
args := proxier.iptablesContainerNodePortArgs(nodePort, protocol, proxyIP, proxyPort, name)
|
args := proxier.iptablesContainerPortalArgs(nil, false, false, nodePort, protocol, proxyIP, proxyPort, name)
|
||||||
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerNodePortChain, args...); err != nil {
|
if err := proxier.iptables.DeleteRule(iptables.TableNAT, iptablesContainerNodePortChain, args...); err != nil {
|
||||||
glog.Errorf("Failed to delete iptables %s rule for service %q", iptablesContainerNodePortChain, name)
|
glog.Errorf("Failed to delete iptables %s rule for service %q", iptablesContainerNodePortChain, name)
|
||||||
el = append(el, err)
|
el = append(el, err)
|
||||||
@ -1061,23 +1061,6 @@ func (proxier *Proxier) iptablesHostPortalArgs(destIP net.IP, addDstLocalMatch b
|
|||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build a slice of iptables args for a from-container public-port rule.
|
|
||||||
// See iptablesContainerPortalArgs
|
|
||||||
// TODO: Should we just reuse iptablesContainerPortalArgs?
|
|
||||||
func (proxier *Proxier) iptablesContainerNodePortArgs(nodePort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service proxy.ServicePortName) []string {
|
|
||||||
args := iptablesCommonPortalArgs(nil, false, false, nodePort, protocol, service)
|
|
||||||
|
|
||||||
if proxyIP.Equal(zeroIPv4) || proxyIP.Equal(zeroIPv6) {
|
|
||||||
// TODO: Can we REDIRECT with IPv6?
|
|
||||||
args = append(args, "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", proxyPort))
|
|
||||||
} else {
|
|
||||||
// TODO: Can we DNAT with IPv6?
|
|
||||||
args = append(args, "-j", "DNAT", "--to-destination", net.JoinHostPort(proxyIP.String(), strconv.Itoa(proxyPort)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return args
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build a slice of iptables args for a from-host public-port rule.
|
// Build a slice of iptables args for a from-host public-port rule.
|
||||||
// See iptablesHostPortalArgs
|
// See iptablesHostPortalArgs
|
||||||
// TODO: Should we just reuse iptablesHostPortalArgs?
|
// TODO: Should we just reuse iptablesHostPortalArgs?
|
||||||
|
Loading…
Reference in New Issue
Block a user