From ff83754a6b0bb162d3ce9e9eba4f64720df8f8ad Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Fri, 31 May 2019 10:39:10 -0700 Subject: [PATCH] Use read lock for reconciler#getHandlers --- pkg/kubelet/pluginmanager/cache/actual_state_of_world.go | 4 +--- pkg/kubelet/pluginmanager/cache/desired_state_of_world.go | 4 +--- pkg/kubelet/pluginmanager/reconciler/reconciler.go | 4 ++-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/kubelet/pluginmanager/cache/actual_state_of_world.go b/pkg/kubelet/pluginmanager/cache/actual_state_of_world.go index 5ccfa663c68..c52b9805f48 100644 --- a/pkg/kubelet/pluginmanager/cache/actual_state_of_world.go +++ b/pkg/kubelet/pluginmanager/cache/actual_state_of_world.go @@ -100,9 +100,7 @@ func (asw *actualStateOfWorld) RemovePlugin(socketPath string) { asw.Lock() defer asw.Unlock() - if _, ok := asw.socketFileToInfo[socketPath]; ok { - delete(asw.socketFileToInfo, socketPath) - } + delete(asw.socketFileToInfo, socketPath) } func (asw *actualStateOfWorld) GetRegisteredPlugins() []PluginInfo { diff --git a/pkg/kubelet/pluginmanager/cache/desired_state_of_world.go b/pkg/kubelet/pluginmanager/cache/desired_state_of_world.go index 237434bfc47..320fad456bd 100644 --- a/pkg/kubelet/pluginmanager/cache/desired_state_of_world.go +++ b/pkg/kubelet/pluginmanager/cache/desired_state_of_world.go @@ -147,9 +147,7 @@ func (dsw *desiredStateOfWorld) RemovePlugin(socketPath string) { dsw.Lock() defer dsw.Unlock() - if _, ok := dsw.socketFileToInfo[socketPath]; ok { - delete(dsw.socketFileToInfo, socketPath) - } + delete(dsw.socketFileToInfo, socketPath) } func (dsw *desiredStateOfWorld) GetPluginsToRegister() []PluginInfo { diff --git a/pkg/kubelet/pluginmanager/reconciler/reconciler.go b/pkg/kubelet/pluginmanager/reconciler/reconciler.go index f275a8612e9..10afecf8e7b 100644 --- a/pkg/kubelet/pluginmanager/reconciler/reconciler.go +++ b/pkg/kubelet/pluginmanager/reconciler/reconciler.go @@ -97,8 +97,8 @@ func (rc *reconciler) AddHandler(pluginType string, pluginHandler cache.PluginHa } func (rc *reconciler) getHandlers() map[string]cache.PluginHandler { - rc.Lock() - defer rc.Unlock() + rc.RLock() + defer rc.RUnlock() return rc.handlers }