From 405d5f802c6e1a8f7790d96eebc02590088f93a4 Mon Sep 17 00:00:00 2001 From: Weibin Lin Date: Mon, 25 Jun 2018 11:18:18 +0800 Subject: [PATCH] Not step into ipvs.CleanupLeftovers() if canUseIPVS's false --- cmd/kube-proxy/app/server_others.go | 11 ++++++++--- pkg/proxy/ipvs/proxier.go | 3 --- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/kube-proxy/app/server_others.go b/cmd/kube-proxy/app/server_others.go index 754d654f179..33dcd32a78b 100644 --- a/cmd/kube-proxy/app/server_others.go +++ b/cmd/kube-proxy/app/server_others.go @@ -92,7 +92,8 @@ func newProxyServer( iptInterface = utiliptables.New(execer, dbus, protocol) kernelHandler = ipvs.NewLinuxKernelHandler() ipsetInterface = utilipset.New(execer) - if canUse, _ := ipvs.CanUseIPVSProxier(kernelHandler, ipsetInterface); canUse { + canUseIPVS, _ := ipvs.CanUseIPVSProxier(kernelHandler, ipsetInterface) + if canUseIPVS { ipvsInterface = utilipvs.New(execer) } @@ -178,7 +179,9 @@ func newProxyServer( // Besides, ipvs proxier will create some ipvs rules as well. Because there is no way to tell if a given // ipvs rule is created by IPVS proxier or not. Users should explicitly specify `--clean-ipvs=true` to flush // all ipvs rules when kube-proxy start up. Users do this operation should be with caution. - ipvs.CleanupLeftovers(ipvsInterface, iptInterface, ipsetInterface, cleanupIPVS) + if canUseIPVS { + ipvs.CleanupLeftovers(ipvsInterface, iptInterface, ipsetInterface, cleanupIPVS) + } } else if proxyMode == proxyModeIPVS { glog.V(0).Info("Using ipvs Proxier.") proxierIPVS, err := ipvs.NewProxier( @@ -245,7 +248,9 @@ func newProxyServer( // Besides, ipvs proxier will create some ipvs rules as well. Because there is no way to tell if a given // ipvs rule is created by IPVS proxier or not. Users should explicitly specify `--clean-ipvs=true` to flush // all ipvs rules when kube-proxy start up. Users do this operation should be with caution. - ipvs.CleanupLeftovers(ipvsInterface, iptInterface, ipsetInterface, cleanupIPVS) + if canUseIPVS { + ipvs.CleanupLeftovers(ipvsInterface, iptInterface, ipsetInterface, cleanupIPVS) + } } iptInterface.AddReloadFunc(proxier.Sync) diff --git a/pkg/proxy/ipvs/proxier.go b/pkg/proxy/ipvs/proxier.go index dbbc505cb80..dc47e6002c2 100644 --- a/pkg/proxy/ipvs/proxier.go +++ b/pkg/proxy/ipvs/proxier.go @@ -548,9 +548,6 @@ func cleanupIptablesLeftovers(ipt utiliptables.Interface) (encounteredError bool // CleanupLeftovers clean up all ipvs and iptables rules created by ipvs Proxier. func CleanupLeftovers(ipvs utilipvs.Interface, ipt utiliptables.Interface, ipset utilipset.Interface, cleanupIPVS bool) (encounteredError bool) { - if canUse, _ := CanUseIPVSProxier(NewLinuxKernelHandler(), ipset); !canUse { - return false - } if cleanupIPVS { // Return immediately when ipvs interface is nil - Probably initialization failed in somewhere. if ipvs == nil {