Skip to content

Commit b6860f7

Browse files
authored
Merge pull request kubernetes#77298 from JieJhih/iptables/endpoints
combine two logics avoid for range the same thing
2 parents 5bfa8f3 + 176d493 commit b6860f7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pkg/proxy/iptables/proxier.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,16 @@ func (proxier *Proxier) syncProxyRules() {
11521152

11531153
// Now write loadbalancing & DNAT rules.
11541154
n := len(endpointChains)
1155+
localEndpoints := make([]*endpointsInfo, 0)
1156+
localEndpointChains := make([]utiliptables.Chain, 0)
11551157
for i, endpointChain := range endpointChains {
1158+
// Write ingress loadbalancing & DNAT rules only for services that request OnlyLocal traffic.
1159+
if svcInfo.OnlyNodeLocalEndpoints && endpoints[i].IsLocal {
1160+
// These slices parallel each other; must be kept in sync
1161+
localEndpoints = append(localEndpoints, endpoints[i])
1162+
localEndpointChains = append(localEndpointChains, endpointChains[i])
1163+
}
1164+
11561165
epIP := endpoints[i].IP()
11571166
if epIP == "" {
11581167
// Error parsing this endpoint has been logged. Skip to next endpoint.
@@ -1193,17 +1202,6 @@ func (proxier *Proxier) syncProxyRules() {
11931202
continue
11941203
}
11951204

1196-
// Now write ingress loadbalancing & DNAT rules only for services that request OnlyLocal traffic.
1197-
// TODO - This logic may be combinable with the block above that creates the svc balancer chain
1198-
localEndpoints := make([]*endpointsInfo, 0)
1199-
localEndpointChains := make([]utiliptables.Chain, 0)
1200-
for i := range endpointChains {
1201-
if endpoints[i].IsLocal {
1202-
// These slices parallel each other; must be kept in sync
1203-
localEndpoints = append(localEndpoints, endpoints[i])
1204-
localEndpointChains = append(localEndpointChains, endpointChains[i])
1205-
}
1206-
}
12071205
// First rule in the chain redirects all pod -> external VIP traffic to the
12081206
// Service's ClusterIP instead. This happens whether or not we have local
12091207
// endpoints; only if clusterCIDR is specified

0 commit comments

Comments
 (0)