@@ -990,37 +990,26 @@ func cleanupStaleRules(activePolicyChains, activePodFwChains, activePolicyIPSets
990990 }
991991 }
992992
993- // remove stale iptables chain references from the filter table chains
994- for _ , chain := range cleanupPodFwChains {
993+ // remove stale iptables podFwChain references from the filter table chains
994+ for _ , podFwChain := range cleanupPodFwChains {
995995
996- forwardChainRules , err := iptablesCmdHandler .List ("filter" , "FORWARD" )
997- if err != nil {
998- return fmt .Errorf ("failed to list rules in filter table, FORWARD chain due to %s" , err .Error ())
999- }
1000- outputChainRules , err := iptablesCmdHandler .List ("filter" , "OUTPUT" )
1001- if err != nil {
1002- return fmt .Errorf ("failed to list rules in filter table, OUTPUT chain due to %s" , err .Error ())
1003- }
1004-
1005- // TODO delete rule by spec, than rule number to avoid extra loop
1006- var realRuleNo int
1007- for i , rule := range forwardChainRules {
1008- if strings .Contains (rule , chain ) {
1009- err = iptablesCmdHandler .Delete ("filter" , "FORWARD" , strconv .Itoa (i - realRuleNo ))
1010- if err != nil {
1011- return fmt .Errorf ("failed to delete rule: %s from the FORWARD chain of filter table due to %s" , rule , err .Error ())
1012- }
1013- realRuleNo ++
996+ primaryChains := []string {"FORWARD" , "OUTPUT" , "INPUT" }
997+ for _ , egressChain := range primaryChains {
998+ forwardChainRules , err := iptablesCmdHandler .List ("filter" , egressChain )
999+ if err != nil {
1000+ return fmt .Errorf ("failed to list rules in filter table, %s podFwChain due to %s" , egressChain , err .Error ())
10141001 }
1015- }
1016- realRuleNo = 0
1017- for i , rule := range outputChainRules {
1018- if strings .Contains (rule , chain ) {
1019- err = iptablesCmdHandler .Delete ("filter" , "OUTPUT" , strconv .Itoa (i - realRuleNo ))
1020- if err != nil {
1021- return fmt .Errorf ("failed to delete rule: %s from the OUTPUT chain of filter table due to %s" , rule , err .Error ())
1002+
1003+ // TODO delete rule by spec, than rule number to avoid extra loop
1004+ var realRuleNo int
1005+ for i , rule := range forwardChainRules {
1006+ if strings .Contains (rule , podFwChain ) {
1007+ err = iptablesCmdHandler .Delete ("filter" , egressChain , strconv .Itoa (i - realRuleNo ))
1008+ if err != nil {
1009+ return fmt .Errorf ("failed to delete rule: %s from the %s podFwChain of filter table due to %s" , rule , egressChain , err .Error ())
1010+ }
1011+ realRuleNo ++
10221012 }
1023- realRuleNo ++
10241013 }
10251014 }
10261015 }
0 commit comments