pkg/proxy: Simplify LocalTrafficDetector

Now that we don't have to always append all of the iptables args into
a single array, there's no reason to have LocalTrafficDetector take in
a set of args to prepend to its own output, and also not much point in
having it write out the "-j CHAIN" by itself either.
This commit is contained in:
Dan Winship
2022-01-06 13:53:42 -05:00
parent 3a4064c5c8
commit e3549646ec
4 changed files with 65 additions and 79 deletions

View File

@@ -1117,7 +1117,9 @@ func (proxier *Proxier) syncProxyRules() {
// If/when we support "Local" policy for VIPs, we should update this.
proxier.natRules.Write(
"-A", string(svcChain),
proxier.localDetector.JumpIfNotLocal(args, string(KubeMarkMasqChain)))
args,
proxier.localDetector.IfNotLocal(),
"-j", string(KubeMarkMasqChain))
}
proxier.natRules.Write(
"-A", string(kubeServicesChain),
@@ -1157,7 +1159,9 @@ func (proxier *Proxier) syncProxyRules() {
if proxier.localDetector.IsImplemented() {
proxier.natRules.Write(
appendTo,
proxier.localDetector.JumpIfNotLocal(args, string(KubeMarkMasqChain)))
args,
proxier.localDetector.IfNotLocal(),
"-j", string(KubeMarkMasqChain))
} else {
proxier.natRules.Write(
appendTo,
@@ -1348,12 +1352,12 @@ func (proxier *Proxier) syncProxyRules() {
// Service's ClusterIP instead. This happens whether or not we have local
// endpoints; only if localDetector is implemented
if proxier.localDetector.IsImplemented() {
args = append(args[:0],
proxier.natRules.Write(
"-A", string(svcXlbChain),
"-m", "comment", "--comment",
`"Redirect pods trying to reach external loadbalancer VIP to clusterIP"`,
)
proxier.natRules.Write(proxier.localDetector.JumpIfLocal(args, string(svcChain)))
proxier.localDetector.IfLocal(),
"-j", string(svcChain))
}
// Next, redirect all src-type=LOCAL -> LB IP to the service chain for externalTrafficPolicy=Local