Skip to content

Commit 42997cb

Browse files
lucasmundimmurali-reddy
authored andcommitted
Delete iptables rule if --masquerade-all is false (#665)
1 parent 961d8ab commit 42997cb

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pkg/controllers/proxy/network_services_controller.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,12 +1479,24 @@ func ensureMasqueradeIptablesRule(masqueradeAll bool, podCidr string) error {
14791479
if err != nil {
14801480
return errors.New("Failed to initialize iptables executor" + err.Error())
14811481
}
1482-
var args []string
1482+
var args = []string{"-m", "ipvs", "--ipvs", "--vdir", "ORIGINAL", "--vmethod", "MASQ", "-m", "comment", "--comment", "", "-j", "MASQUERADE"}
14831483
if masqueradeAll {
1484-
args = []string{"-m", "ipvs", "--ipvs", "--vdir", "ORIGINAL", "--vmethod", "MASQ", "-m", "comment", "--comment", "", "-j", "MASQUERADE"}
14851484
err = iptablesCmdHandler.AppendUnique("nat", "POSTROUTING", args...)
14861485
if err != nil {
1487-
return errors.New("Failed to run iptables command" + err.Error())
1486+
return errors.New("Failed to create iptables rule to masquerade all outbound IPVS traffic" + err.Error())
1487+
}
1488+
} else {
1489+
exists, err := iptablesCmdHandler.Exists("nat", "POSTROUTING", args...)
1490+
if err != nil {
1491+
return errors.New("Failed to lookup iptables rule to masquerade all outbound IPVS traffic: " + err.Error())
1492+
}
1493+
if exists {
1494+
err = iptablesCmdHandler.Delete("nat", "POSTROUTING", args...)
1495+
if err != nil {
1496+
return errors.New("Failed to delete iptables rule to masquerade all outbound IPVS traffic: " +
1497+
err.Error() + ". Masquerade might still work...")
1498+
}
1499+
glog.Infof("Deleted iptables rule to masquerade all outbound IVPS traffic.")
14881500
}
14891501
}
14901502
if len(podCidr) > 0 {

0 commit comments

Comments
 (0)