From 5a0e7f19b6a46c71277e2ebc6a0df241945c015b Mon Sep 17 00:00:00 2001 From: caiweidong Date: Mon, 20 May 2019 19:12:27 +0800 Subject: [PATCH] Narrow down the lock --- .../volume/attachdetach/cache/actual_state_of_world.go | 6 +++--- .../volume/attachdetach/cache/desired_state_of_world.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/controller/volume/attachdetach/cache/actual_state_of_world.go b/pkg/controller/volume/attachdetach/cache/actual_state_of_world.go index 4322f15a60d..cd9bdff6454 100644 --- a/pkg/controller/volume/attachdetach/cache/actual_state_of_world.go +++ b/pkg/controller/volume/attachdetach/cache/actual_state_of_world.go @@ -277,9 +277,6 @@ func (asw *actualStateOfWorld) AddVolumeToReportAsAttached( func (asw *actualStateOfWorld) AddVolumeNode( uniqueName v1.UniqueVolumeName, volumeSpec *volume.Spec, nodeName types.NodeName, devicePath string, isAttached bool) (v1.UniqueVolumeName, error) { - asw.Lock() - defer asw.Unlock() - volumeName := uniqueName if volumeName == "" { if volumeSpec == nil { @@ -303,6 +300,9 @@ func (asw *actualStateOfWorld) AddVolumeNode( } } + asw.Lock() + defer asw.Unlock() + volumeObj, volumeExists := asw.attachedVolumes[volumeName] if !volumeExists { volumeObj = attachedVolume{ diff --git a/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go b/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go index 520d2ca38b9..067efe22251 100644 --- a/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go +++ b/pkg/controller/volume/attachdetach/cache/desired_state_of_world.go @@ -102,7 +102,7 @@ type DesiredStateOfWorld interface { // mounted and attached for terminated pods GetKeepTerminatedPodVolumesForNode(k8stypes.NodeName) bool - // Mark multiattach error as reported to prevent spamming multiple + // Mark multi-attach error as reported to prevent spamming multiple // events for same error SetMultiAttachError(v1.UniqueVolumeName, k8stypes.NodeName)