@@ -356,36 +356,39 @@ func NewProxier(ipt utiliptables.Interface,
356
356
}
357
357
358
358
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
364
364
}
365
365
366
366
var iptablesJumpChains = []iptablesJumpChain {
367
367
{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" }},
369
368
{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 },
372
369
{utiliptables .TableNAT , kubeServicesChain , utiliptables .ChainOutput , "kubernetes service portals" , nil },
373
370
{utiliptables .TableNAT , kubeServicesChain , utiliptables .ChainPrerouting , "kubernetes service portals" , nil },
374
371
{utiliptables .TableNAT , kubePostroutingChain , utiliptables .ChainPostrouting , "kubernetes postrouting rules" , nil },
372
+ {utiliptables .TableFilter , kubeForwardChain , utiliptables .ChainForward , "kubernetes forwarding rules" , nil },
375
373
}
376
374
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
+ }
378
381
379
382
// CleanupLeftovers removes all iptables rules and chains created by the Proxier
380
383
// It returns true if an error was encountered. Errors are logged.
381
384
func CleanupLeftovers (ipt utiliptables.Interface ) (encounteredError bool ) {
382
385
// 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 ),
387
390
)
388
- if err := ipt .DeleteRule (jump .table , jump . srcChain , args ... ); err != nil {
391
+ if err := ipt .DeleteRule (chain .table , chain . sourceChain , args ... ); err != nil {
389
392
if ! utiliptables .IsNotFoundError (err ) {
390
393
glog .Errorf ("Error removing pure-iptables proxy rule: %v" , err )
391
394
encounteredError = true
@@ -659,17 +662,17 @@ func (proxier *Proxier) syncProxyRules() {
659
662
glog .V (3 ).Infof ("Syncing iptables rules" )
660
663
661
664
// 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 )
665
668
return
666
669
}
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 ),
670
673
)
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 )
673
676
return
674
677
}
675
678
}
@@ -827,7 +830,6 @@ func (proxier *Proxier) syncProxyRules() {
827
830
}
828
831
writeLine (proxier .natRules , append (args , "-j" , string (svcChain ))... )
829
832
} else {
830
- // No endpoints.
831
833
writeLine (proxier .filterRules ,
832
834
"-A" , string (kubeServicesChain ),
833
835
"-m" , "comment" , "--comment" , fmt .Sprintf (`"%s has no endpoints"` , svcNameString ),
@@ -898,7 +900,6 @@ func (proxier *Proxier) syncProxyRules() {
898
900
// This covers cases like GCE load-balancers which get added to the local routing table.
899
901
writeLine (proxier .natRules , append (dstLocalOnlyArgs , "-j" , string (svcChain ))... )
900
902
} else {
901
- // No endpoints.
902
903
writeLine (proxier .filterRules ,
903
904
"-A" , string (kubeExternalServicesChain ),
904
905
"-m" , "comment" , "--comment" , fmt .Sprintf (`"%s has no endpoints"` , svcNameString ),
@@ -911,10 +912,10 @@ func (proxier *Proxier) syncProxyRules() {
911
912
}
912
913
913
914
// 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 != "" {
918
919
// create service firewall chain
919
920
if chain , ok := existingNATChains [fwChain ]; ok {
920
921
writeBytesLine (proxier .natChains , chain )
@@ -975,19 +976,10 @@ func (proxier *Proxier) syncProxyRules() {
975
976
// If the packet was able to reach the end of firewall chain, then it did not get DNATed.
976
977
// It means the packet cannot go thru the firewall, then mark it for DROP
977
978
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
- )
988
979
}
989
980
}
990
981
}
982
+ // FIXME: do we need REJECT rules for load-balancer ingress if !hasEndpoints?
991
983
992
984
// Capture nodeports. If we had more than 2 rules it might be
993
985
// worthwhile to make a new per-service chain for nodeport rules, but
@@ -1069,7 +1061,6 @@ func (proxier *Proxier) syncProxyRules() {
1069
1061
writeLine (proxier .natRules , append (args , "-j" , string (svcXlbChain ))... )
1070
1062
}
1071
1063
} else {
1072
- // No endpoints.
1073
1064
writeLine (proxier .filterRules ,
1074
1065
"-A" , string (kubeExternalServicesChain ),
1075
1066
"-m" , "comment" , "--comment" , fmt .Sprintf (`"%s has no endpoints"` , svcNameString ),
0 commit comments