Merge pull request #98297 from JornShen/replace_ipvs_proxier_protocal_str

use exist const to replace ipvs/proxier.go tcp,udp,sctp str
This commit is contained in:
Kubernetes Prow Robot 2021-01-28 14:41:52 -08:00 committed by GitHub
commit 97076f6647
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -181,23 +181,25 @@ var ipsetWithIptablesChain = []struct {
{kubeLoadBalancerSourceCIDRSet, string(KubeFireWallChain), "RETURN", "dst,dst,src", ""}, {kubeLoadBalancerSourceCIDRSet, string(KubeFireWallChain), "RETURN", "dst,dst,src", ""},
{kubeLoadBalancerSourceIPSet, string(KubeFireWallChain), "RETURN", "dst,dst,src", ""}, {kubeLoadBalancerSourceIPSet, string(KubeFireWallChain), "RETURN", "dst,dst,src", ""},
{kubeLoadBalancerLocalSet, string(KubeLoadBalancerChain), "RETURN", "dst,dst", ""}, {kubeLoadBalancerLocalSet, string(KubeLoadBalancerChain), "RETURN", "dst,dst", ""},
{kubeNodePortLocalSetTCP, string(KubeNodePortChain), "RETURN", "dst", "tcp"}, {kubeNodePortLocalSetTCP, string(KubeNodePortChain), "RETURN", "dst", utilipset.ProtocolTCP},
{kubeNodePortSetTCP, string(KubeNodePortChain), string(KubeMarkMasqChain), "dst", "tcp"}, {kubeNodePortSetTCP, string(KubeNodePortChain), string(KubeMarkMasqChain), "dst", utilipset.ProtocolTCP},
{kubeNodePortLocalSetUDP, string(KubeNodePortChain), "RETURN", "dst", "udp"}, {kubeNodePortLocalSetUDP, string(KubeNodePortChain), "RETURN", "dst", utilipset.ProtocolUDP},
{kubeNodePortSetUDP, string(KubeNodePortChain), string(KubeMarkMasqChain), "dst", "udp"}, {kubeNodePortSetUDP, string(KubeNodePortChain), string(KubeMarkMasqChain), "dst", utilipset.ProtocolUDP},
{kubeNodePortSetSCTP, string(KubeNodePortChain), string(KubeMarkMasqChain), "dst,dst", "sctp"}, {kubeNodePortSetSCTP, string(KubeNodePortChain), string(KubeMarkMasqChain), "dst,dst", utilipset.ProtocolSCTP},
{kubeNodePortLocalSetSCTP, string(KubeNodePortChain), "RETURN", "dst,dst", "sctp"}, {kubeNodePortLocalSetSCTP, string(KubeNodePortChain), "RETURN", "dst,dst", utilipset.ProtocolSCTP},
} }
// In IPVS proxy mode, the following flags need to be set // In IPVS proxy mode, the following flags need to be set
const sysctlBridgeCallIPTables = "net/bridge/bridge-nf-call-iptables" const (
const sysctlVSConnTrack = "net/ipv4/vs/conntrack" sysctlBridgeCallIPTables = "net/bridge/bridge-nf-call-iptables"
const sysctlConnReuse = "net/ipv4/vs/conn_reuse_mode" sysctlVSConnTrack = "net/ipv4/vs/conntrack"
const sysctlExpireNoDestConn = "net/ipv4/vs/expire_nodest_conn" sysctlConnReuse = "net/ipv4/vs/conn_reuse_mode"
const sysctlExpireQuiescentTemplate = "net/ipv4/vs/expire_quiescent_template" sysctlExpireNoDestConn = "net/ipv4/vs/expire_nodest_conn"
const sysctlForward = "net/ipv4/ip_forward" sysctlExpireQuiescentTemplate = "net/ipv4/vs/expire_quiescent_template"
const sysctlArpIgnore = "net/ipv4/conf/all/arp_ignore" sysctlForward = "net/ipv4/ip_forward"
const sysctlArpAnnounce = "net/ipv4/conf/all/arp_announce" sysctlArpIgnore = "net/ipv4/conf/all/arp_ignore"
sysctlArpAnnounce = "net/ipv4/conf/all/arp_announce"
)
// Proxier is an ipvs based proxy for connections between a localhost:lport // Proxier is an ipvs based proxy for connections between a localhost:lport
// and services that provide the actual backends. // and services that provide the actual backends.
@ -1480,7 +1482,7 @@ func (proxier *Proxier) syncProxyRules() {
) )
switch protocol { switch protocol {
case "tcp": case utilipset.ProtocolTCP:
nodePortSet = proxier.ipsetList[kubeNodePortSetTCP] nodePortSet = proxier.ipsetList[kubeNodePortSetTCP]
entries = []*utilipset.Entry{{ entries = []*utilipset.Entry{{
// No need to provide ip info // No need to provide ip info
@ -1488,7 +1490,7 @@ func (proxier *Proxier) syncProxyRules() {
Protocol: protocol, Protocol: protocol,
SetType: utilipset.BitmapPort, SetType: utilipset.BitmapPort,
}} }}
case "udp": case utilipset.ProtocolUDP:
nodePortSet = proxier.ipsetList[kubeNodePortSetUDP] nodePortSet = proxier.ipsetList[kubeNodePortSetUDP]
entries = []*utilipset.Entry{{ entries = []*utilipset.Entry{{
// No need to provide ip info // No need to provide ip info
@ -1496,7 +1498,7 @@ func (proxier *Proxier) syncProxyRules() {
Protocol: protocol, Protocol: protocol,
SetType: utilipset.BitmapPort, SetType: utilipset.BitmapPort,
}} }}
case "sctp": case utilipset.ProtocolSCTP:
nodePortSet = proxier.ipsetList[kubeNodePortSetSCTP] nodePortSet = proxier.ipsetList[kubeNodePortSetSCTP]
// Since hash ip:port is used for SCTP, all the nodeIPs to be used in the SCTP ipset entries. // Since hash ip:port is used for SCTP, all the nodeIPs to be used in the SCTP ipset entries.
entries = []*utilipset.Entry{} entries = []*utilipset.Entry{}
@ -1531,11 +1533,11 @@ func (proxier *Proxier) syncProxyRules() {
if svcInfo.OnlyNodeLocalEndpoints() { if svcInfo.OnlyNodeLocalEndpoints() {
var nodePortLocalSet *IPSet var nodePortLocalSet *IPSet
switch protocol { switch protocol {
case "tcp": case utilipset.ProtocolTCP:
nodePortLocalSet = proxier.ipsetList[kubeNodePortLocalSetTCP] nodePortLocalSet = proxier.ipsetList[kubeNodePortLocalSetTCP]
case "udp": case utilipset.ProtocolUDP:
nodePortLocalSet = proxier.ipsetList[kubeNodePortLocalSetUDP] nodePortLocalSet = proxier.ipsetList[kubeNodePortLocalSetUDP]
case "sctp": case utilipset.ProtocolSCTP:
nodePortLocalSet = proxier.ipsetList[kubeNodePortLocalSetSCTP] nodePortLocalSet = proxier.ipsetList[kubeNodePortLocalSetSCTP]
default: default:
// It should never hit // It should never hit