fix kube-proxy cleanup

This commit is contained in:
Lion-Wei
2020-09-19 17:44:38 +08:00
parent e2a7bd5318
commit dbb5438b33
2 changed files with 34 additions and 26 deletions

View File

@@ -801,11 +801,20 @@ func getConntrackMax(config kubeproxyconfig.KubeProxyConntrackConfiguration) (in
return 0, nil
}
// CleanupAndExit remove iptables rules and exit if success return nil
// CleanupAndExit remove iptables rules and ipset/ipvs rules in ipvs proxy mode
// and exit if success return nil
func (s *ProxyServer) CleanupAndExit() error {
encounteredError := userspace.CleanupLeftovers(s.IptInterface)
encounteredError = iptables.CleanupLeftovers(s.IptInterface) || encounteredError
encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, s.IptInterface, s.IpsetInterface, s.CleanupIPVS) || encounteredError
// cleanup IPv6 and IPv4 iptables rules
ipts := []utiliptables.Interface{
utiliptables.New(s.execer, utiliptables.ProtocolIPv4),
utiliptables.New(s.execer, utiliptables.ProtocolIPv6),
}
var encounteredError bool
for _, ipt := range ipts {
encounteredError = userspace.CleanupLeftovers(ipt) || encounteredError
encounteredError = iptables.CleanupLeftovers(ipt) || encounteredError
encounteredError = ipvs.CleanupLeftovers(s.IpvsInterface, ipt, s.IpsetInterface, s.CleanupIPVS) || encounteredError
}
if encounteredError {
return errors.New("encountered an error while tearing down rules")
}