From 796414805924609c04a79e8d939e2e565cf2339f Mon Sep 17 00:00:00 2001 From: Minhan Xia Date: Fri, 12 Aug 2016 16:49:25 -0700 Subject: [PATCH] move syncNetworkConfig to Init for cni network plugin --- pkg/kubelet/network/cni/cni.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/kubelet/network/cni/cni.go b/pkg/kubelet/network/cni/cni.go index 13d1e91653f..084e4779659 100644 --- a/pkg/kubelet/network/cni/cni.go +++ b/pkg/kubelet/network/cni/cni.go @@ -48,9 +48,11 @@ type cniNetworkPlugin struct { sync.RWMutex defaultNetwork *cniNetwork - host network.Host - execer utilexec.Interface - nsenterPath string + host network.Host + execer utilexec.Interface + nsenterPath string + pluginDir string + vendorCNIDirPrefix string } type cniNetwork struct { @@ -61,17 +63,15 @@ type cniNetwork struct { func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, vendorCNIDirPrefix string) []network.NetworkPlugin { plugin := &cniNetworkPlugin{ - defaultNetwork: nil, - loNetwork: getLoNetwork(vendorCNIDirPrefix), - execer: utilexec.New(), + defaultNetwork: nil, + loNetwork: getLoNetwork(vendorCNIDirPrefix), + execer: utilexec.New(), + pluginDir: pluginDir, + vendorCNIDirPrefix: vendorCNIDirPrefix, } - plugin.syncNetworkConfig(pluginDir, vendorCNIDirPrefix) - // sync network config from pluginDir periodically to detect network config updates - go wait.Forever(func() { - plugin.syncNetworkConfig(pluginDir, vendorCNIDirPrefix) - }, 10*time.Second) - + // sync NetworkConfig in best effort during probing. + plugin.syncNetworkConfig() return []network.NetworkPlugin{plugin} } @@ -144,11 +144,16 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon } plugin.host = host + + // sync network config from pluginDir periodically to detect network config updates + go wait.Forever(func() { + plugin.syncNetworkConfig() + }, 10*time.Second) return nil } -func (plugin *cniNetworkPlugin) syncNetworkConfig(pluginDir, vendorCNIDirPrefix string) { - network, err := getDefaultCNINetwork(pluginDir, vendorCNIDirPrefix) +func (plugin *cniNetworkPlugin) syncNetworkConfig() { + network, err := getDefaultCNINetwork(plugin.pluginDir, plugin.vendorCNIDirPrefix) if err != nil { glog.Errorf("error updating cni config: %s", err) return