Commit 7d00b427 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #30557 from freehan/cniconfig

Automatic merge from submit-queue move syncNetworkConfig to Init for cni network plugin start syncNetworkConfig routine in `Init` instead of probing. This fixes a bug where the syncNetworkConfig runs periodically even `cni` network plugin is not in use.
parents 874a1869 79641480
...@@ -51,6 +51,8 @@ type cniNetworkPlugin struct { ...@@ -51,6 +51,8 @@ type cniNetworkPlugin struct {
host network.Host host network.Host
execer utilexec.Interface execer utilexec.Interface
nsenterPath string nsenterPath string
pluginDir string
vendorCNIDirPrefix string
} }
type cniNetwork struct { type cniNetwork struct {
...@@ -64,14 +66,12 @@ func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, vendorCNIDirPrefix str ...@@ -64,14 +66,12 @@ func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, vendorCNIDirPrefix str
defaultNetwork: nil, defaultNetwork: nil,
loNetwork: getLoNetwork(vendorCNIDirPrefix), loNetwork: getLoNetwork(vendorCNIDirPrefix),
execer: utilexec.New(), execer: utilexec.New(),
pluginDir: pluginDir,
vendorCNIDirPrefix: vendorCNIDirPrefix,
} }
plugin.syncNetworkConfig(pluginDir, vendorCNIDirPrefix) // sync NetworkConfig in best effort during probing.
// sync network config from pluginDir periodically to detect network config updates plugin.syncNetworkConfig()
go wait.Forever(func() {
plugin.syncNetworkConfig(pluginDir, vendorCNIDirPrefix)
}, 10*time.Second)
return []network.NetworkPlugin{plugin} return []network.NetworkPlugin{plugin}
} }
...@@ -144,11 +144,16 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon ...@@ -144,11 +144,16 @@ func (plugin *cniNetworkPlugin) Init(host network.Host, hairpinMode componentcon
} }
plugin.host = host 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 return nil
} }
func (plugin *cniNetworkPlugin) syncNetworkConfig(pluginDir, vendorCNIDirPrefix string) { func (plugin *cniNetworkPlugin) syncNetworkConfig() {
network, err := getDefaultCNINetwork(pluginDir, vendorCNIDirPrefix) network, err := getDefaultCNINetwork(plugin.pluginDir, plugin.vendorCNIDirPrefix)
if err != nil { if err != nil {
glog.Errorf("error updating cni config: %s", err) glog.Errorf("error updating cni config: %s", err)
return return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment