mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
add lock in volume manager reconciler to avoid data race
Signed-off-by: Paco Xu <paco.xu@daocloud.io>
This commit is contained in:
parent
7afcfe1826
commit
5134520a3b
@ -18,6 +18,7 @@ package reconciler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@ -139,10 +140,12 @@ type reconciler struct {
|
|||||||
volumePluginMgr *volumepkg.VolumePluginMgr
|
volumePluginMgr *volumepkg.VolumePluginMgr
|
||||||
skippedDuringReconstruction map[v1.UniqueVolumeName]*globalVolumeInfo
|
skippedDuringReconstruction map[v1.UniqueVolumeName]*globalVolumeInfo
|
||||||
kubeletPodsDir string
|
kubeletPodsDir string
|
||||||
timeOfLastSync time.Time
|
// lock protects timeOfLastSync for updating and checking
|
||||||
volumesFailedReconstruction []podVolume
|
timeOfLastSyncLock sync.Mutex
|
||||||
volumesNeedDevicePath []v1.UniqueVolumeName
|
timeOfLastSync time.Time
|
||||||
volumesNeedReportedInUse []v1.UniqueVolumeName
|
volumesFailedReconstruction []podVolume
|
||||||
|
volumesNeedDevicePath []v1.UniqueVolumeName
|
||||||
|
volumesNeedReportedInUse []v1.UniqueVolumeName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reconciler) Run(stopCh <-chan struct{}) {
|
func (rc *reconciler) Run(stopCh <-chan struct{}) {
|
||||||
|
@ -72,10 +72,14 @@ type globalVolumeInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reconciler) updateLastSyncTime() {
|
func (rc *reconciler) updateLastSyncTime() {
|
||||||
|
rc.timeOfLastSyncLock.Lock()
|
||||||
|
defer rc.timeOfLastSyncLock.Unlock()
|
||||||
rc.timeOfLastSync = time.Now()
|
rc.timeOfLastSync = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rc *reconciler) StatesHasBeenSynced() bool {
|
func (rc *reconciler) StatesHasBeenSynced() bool {
|
||||||
|
rc.timeOfLastSyncLock.Lock()
|
||||||
|
defer rc.timeOfLastSyncLock.Unlock()
|
||||||
return !rc.timeOfLastSync.IsZero()
|
return !rc.timeOfLastSync.IsZero()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user