Skip to content

Commit a89f8c1

Browse files
authored
Merge pull request kubernetes#76885 from feiskyer/revert-76529
Revert cherry-pick PR kubernetes#76529
2 parents efb991f + f605caa commit a89f8c1

File tree

5 files changed

+181
-412
lines changed

5 files changed

+181
-412
lines changed

pkg/proxy/iptables/proxier.go

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -356,36 +356,39 @@ func NewProxier(ipt utiliptables.Interface,
356356
}
357357

358358
type iptablesJumpChain struct {
359-
table utiliptables.Table
360-
dstChain utiliptables.Chain
361-
srcChain utiliptables.Chain
362-
comment string
363-
extraArgs []string
359+
table utiliptables.Table
360+
chain utiliptables.Chain
361+
sourceChain utiliptables.Chain
362+
comment string
363+
extraArgs []string
364364
}
365365

366366
var iptablesJumpChains = []iptablesJumpChain{
367367
{utiliptables.TableFilter, kubeExternalServicesChain, utiliptables.ChainInput, "kubernetes externally-visible service portals", []string{"-m", "conntrack", "--ctstate", "NEW"}},
368-
{utiliptables.TableFilter, kubeServicesChain, utiliptables.ChainForward, "kubernetes service portals", []string{"-m", "conntrack", "--ctstate", "NEW"}},
369368
{utiliptables.TableFilter, kubeServicesChain, utiliptables.ChainOutput, "kubernetes service portals", []string{"-m", "conntrack", "--ctstate", "NEW"}},
370-
{utiliptables.TableFilter, kubeServicesChain, utiliptables.ChainInput, "kubernetes service portals", []string{"-m", "conntrack", "--ctstate", "NEW"}},
371-
{utiliptables.TableFilter, kubeForwardChain, utiliptables.ChainForward, "kubernetes forwarding rules", nil},
372369
{utiliptables.TableNAT, kubeServicesChain, utiliptables.ChainOutput, "kubernetes service portals", nil},
373370
{utiliptables.TableNAT, kubeServicesChain, utiliptables.ChainPrerouting, "kubernetes service portals", nil},
374371
{utiliptables.TableNAT, kubePostroutingChain, utiliptables.ChainPostrouting, "kubernetes postrouting rules", nil},
372+
{utiliptables.TableFilter, kubeForwardChain, utiliptables.ChainForward, "kubernetes forwarding rules", nil},
375373
}
376374

377-
var iptablesCleanupOnlyChains = []iptablesJumpChain{}
375+
var iptablesCleanupOnlyChains = []iptablesJumpChain{
376+
// Present in kube 1.6 - 1.9. Removed by #56164 in favor of kubeExternalServicesChain
377+
{utiliptables.TableFilter, kubeServicesChain, utiliptables.ChainInput, "kubernetes service portals", nil},
378+
// Present in kube <= 1.9. Removed by #60306 in favor of rule with extraArgs
379+
{utiliptables.TableFilter, kubeServicesChain, utiliptables.ChainOutput, "kubernetes service portals", nil},
380+
}
378381

379382
// CleanupLeftovers removes all iptables rules and chains created by the Proxier
380383
// It returns true if an error was encountered. Errors are logged.
381384
func CleanupLeftovers(ipt utiliptables.Interface) (encounteredError bool) {
382385
// Unlink our chains
383-
for _, jump := range append(iptablesJumpChains, iptablesCleanupOnlyChains...) {
384-
args := append(jump.extraArgs,
385-
"-m", "comment", "--comment", jump.comment,
386-
"-j", string(jump.dstChain),
386+
for _, chain := range append(iptablesJumpChains, iptablesCleanupOnlyChains...) {
387+
args := append(chain.extraArgs,
388+
"-m", "comment", "--comment", chain.comment,
389+
"-j", string(chain.chain),
387390
)
388-
if err := ipt.DeleteRule(jump.table, jump.srcChain, args...); err != nil {
391+
if err := ipt.DeleteRule(chain.table, chain.sourceChain, args...); err != nil {
389392
if !utiliptables.IsNotFoundError(err) {
390393
glog.Errorf("Error removing pure-iptables proxy rule: %v", err)
391394
encounteredError = true
@@ -659,17 +662,17 @@ func (proxier *Proxier) syncProxyRules() {
659662
glog.V(3).Infof("Syncing iptables rules")
660663

661664
// Create and link the kube chains.
662-
for _, jump := range iptablesJumpChains {
663-
if _, err := proxier.iptables.EnsureChain(jump.table, jump.dstChain); err != nil {
664-
glog.Errorf("Failed to ensure that %s chain %s exists: %v", jump.table, jump.dstChain, err)
665+
for _, chain := range iptablesJumpChains {
666+
if _, err := proxier.iptables.EnsureChain(chain.table, chain.chain); err != nil {
667+
glog.Errorf("Failed to ensure that %s chain %s exists: %v", chain.table, kubeServicesChain, err)
665668
return
666669
}
667-
args := append(jump.extraArgs,
668-
"-m", "comment", "--comment", jump.comment,
669-
"-j", string(jump.dstChain),
670+
args := append(chain.extraArgs,
671+
"-m", "comment", "--comment", chain.comment,
672+
"-j", string(chain.chain),
670673
)
671-
if _, err := proxier.iptables.EnsureRule(utiliptables.Prepend, jump.table, jump.srcChain, args...); err != nil {
672-
glog.Errorf("Failed to ensure that %s chain %s jumps to %s: %v", jump.table, jump.srcChain, jump.dstChain, err)
674+
if _, err := proxier.iptables.EnsureRule(utiliptables.Prepend, chain.table, chain.sourceChain, args...); err != nil {
675+
glog.Errorf("Failed to ensure that %s chain %s jumps to %s: %v", chain.table, chain.sourceChain, chain.chain, err)
673676
return
674677
}
675678
}
@@ -827,7 +830,6 @@ func (proxier *Proxier) syncProxyRules() {
827830
}
828831
writeLine(proxier.natRules, append(args, "-j", string(svcChain))...)
829832
} else {
830-
// No endpoints.
831833
writeLine(proxier.filterRules,
832834
"-A", string(kubeServicesChain),
833835
"-m", "comment", "--comment", fmt.Sprintf(`"%s has no endpoints"`, svcNameString),
@@ -898,7 +900,6 @@ func (proxier *Proxier) syncProxyRules() {
898900
// This covers cases like GCE load-balancers which get added to the local routing table.
899901
writeLine(proxier.natRules, append(dstLocalOnlyArgs, "-j", string(svcChain))...)
900902
} else {
901-
// No endpoints.
902903
writeLine(proxier.filterRules,
903904
"-A", string(kubeExternalServicesChain),
904905
"-m", "comment", "--comment", fmt.Sprintf(`"%s has no endpoints"`, svcNameString),
@@ -911,10 +912,10 @@ func (proxier *Proxier) syncProxyRules() {
911912
}
912913

913914
// Capture load-balancer ingress.
914-
fwChain := svcInfo.serviceFirewallChainName
915-
for _, ingress := range svcInfo.LoadBalancerStatus.Ingress {
916-
if ingress.IP != "" {
917-
if hasEndpoints {
915+
if hasEndpoints {
916+
fwChain := svcInfo.serviceFirewallChainName
917+
for _, ingress := range svcInfo.LoadBalancerStatus.Ingress {
918+
if ingress.IP != "" {
918919
// create service firewall chain
919920
if chain, ok := existingNATChains[fwChain]; ok {
920921
writeBytesLine(proxier.natChains, chain)
@@ -975,19 +976,10 @@ func (proxier *Proxier) syncProxyRules() {
975976
// If the packet was able to reach the end of firewall chain, then it did not get DNATed.
976977
// It means the packet cannot go thru the firewall, then mark it for DROP
977978
writeLine(proxier.natRules, append(args, "-j", string(KubeMarkDropChain))...)
978-
} else {
979-
// No endpoints.
980-
writeLine(proxier.filterRules,
981-
"-A", string(kubeServicesChain),
982-
"-m", "comment", "--comment", fmt.Sprintf(`"%s has no endpoints"`, svcNameString),
983-
"-m", protocol, "-p", protocol,
984-
"-d", utilproxy.ToCIDR(net.ParseIP(ingress.IP)),
985-
"--dport", strconv.Itoa(svcInfo.Port),
986-
"-j", "REJECT",
987-
)
988979
}
989980
}
990981
}
982+
// FIXME: do we need REJECT rules for load-balancer ingress if !hasEndpoints?
991983

992984
// Capture nodeports. If we had more than 2 rules it might be
993985
// worthwhile to make a new per-service chain for nodeport rules, but
@@ -1069,7 +1061,6 @@ func (proxier *Proxier) syncProxyRules() {
10691061
writeLine(proxier.natRules, append(args, "-j", string(svcXlbChain))...)
10701062
}
10711063
} else {
1072-
// No endpoints.
10731064
writeLine(proxier.filterRules,
10741065
"-A", string(kubeExternalServicesChain),
10751066
"-m", "comment", "--comment", fmt.Sprintf(`"%s has no endpoints"`, svcNameString),

0 commit comments

Comments
 (0)