@@ -1070,8 +1070,13 @@ func (proxier *Proxier) syncProxyRules() {
1070
1070
"-d" , utilproxy .ToCIDR (net .ParseIP (externalIP )),
1071
1071
"--dport" , strconv .Itoa (svcInfo .Port ()),
1072
1072
)
1073
- // We have to SNAT packets to external IPs.
1074
- writeLine (proxier .natRules , append (args , "-j" , string (KubeMarkMasqChain ))... )
1073
+
1074
+ destChain := svcXlbChain
1075
+ // We have to SNAT packets to external IPs if externalTrafficPolicy is cluster.
1076
+ if ! (utilfeature .DefaultFeatureGate .Enabled (features .ExternalPolicyForExternalIP ) && svcInfo .OnlyNodeLocalEndpoints ()) {
1077
+ destChain = svcChain
1078
+ writeLine (proxier .natRules , append (args , "-j" , string (KubeMarkMasqChain ))... )
1079
+ }
1075
1080
1076
1081
// Allow traffic for external IPs that does not come from a bridge (i.e. not from a container)
1077
1082
// nor from a local process to be forwarded to the service.
@@ -1080,11 +1085,11 @@ func (proxier *Proxier) syncProxyRules() {
1080
1085
externalTrafficOnlyArgs := append (args ,
1081
1086
"-m" , "physdev" , "!" , "--physdev-is-in" ,
1082
1087
"-m" , "addrtype" , "!" , "--src-type" , "LOCAL" )
1083
- writeLine (proxier .natRules , append (externalTrafficOnlyArgs , "-j" , string (svcChain ))... )
1088
+ writeLine (proxier .natRules , append (externalTrafficOnlyArgs , "-j" , string (destChain ))... )
1084
1089
dstLocalOnlyArgs := append (args , "-m" , "addrtype" , "--dst-type" , "LOCAL" )
1085
1090
// Allow traffic bound for external IPs that happen to be recognized as local IPs to stay local.
1086
1091
// This covers cases like GCE load-balancers which get added to the local routing table.
1087
- writeLine (proxier .natRules , append (dstLocalOnlyArgs , "-j" , string (svcChain ))... )
1092
+ writeLine (proxier .natRules , append (dstLocalOnlyArgs , "-j" , string (destChain ))... )
1088
1093
} else {
1089
1094
// No endpoints.
1090
1095
writeLine (proxier .filterRules ,
0 commit comments