mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #100215 from pacoxu/fix/data-race
fix a data race in volume reconciler ut #99815
This commit is contained in:
commit
bacce2eca6
@ -1094,6 +1094,8 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// deep copy before reconciler runs to avoid data race.
|
||||||
|
pvWithSize := pv.DeepCopy()
|
||||||
volumePluginMgr, fakePlugin := volumetesting.GetTestKubeletVolumePluginMgr(t)
|
volumePluginMgr, fakePlugin := volumetesting.GetTestKubeletVolumePluginMgr(t)
|
||||||
dsw := cache.NewDesiredStateOfWorld(volumePluginMgr)
|
dsw := cache.NewDesiredStateOfWorld(volumePluginMgr)
|
||||||
asw := cache.NewActualStateOfWorld(nodeName, volumePluginMgr)
|
asw := cache.NewActualStateOfWorld(nodeName, volumePluginMgr)
|
||||||
@ -1138,8 +1140,8 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
|
|||||||
// Start the reconciler to fill ASW.
|
// Start the reconciler to fill ASW.
|
||||||
stopChan, stoppedChan := make(chan struct{}), make(chan struct{})
|
stopChan, stoppedChan := make(chan struct{}), make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
|
defer close(stoppedChan)
|
||||||
reconciler.Run(stopChan)
|
reconciler.Run(stopChan)
|
||||||
close(stoppedChan)
|
|
||||||
}()
|
}()
|
||||||
waitForMount(t, fakePlugin, volumeName, asw)
|
waitForMount(t, fakePlugin, volumeName, asw)
|
||||||
// Stop the reconciler.
|
// Stop the reconciler.
|
||||||
@ -1147,8 +1149,8 @@ func Test_Run_Positive_VolumeFSResizeControllerAttachEnabled(t *testing.T) {
|
|||||||
<-stoppedChan
|
<-stoppedChan
|
||||||
|
|
||||||
// Simulate what DSOWP does
|
// Simulate what DSOWP does
|
||||||
pv.Spec.Capacity[v1.ResourceStorage] = tc.newPVSize
|
pvWithSize.Spec.Capacity[v1.ResourceStorage] = tc.newPVSize
|
||||||
volumeSpec = &volume.Spec{PersistentVolume: pv}
|
volumeSpec = &volume.Spec{PersistentVolume: pvWithSize}
|
||||||
dsw.AddPodToVolume(podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */)
|
dsw.AddPodToVolume(podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */)
|
||||||
// mark volume as resize required
|
// mark volume as resize required
|
||||||
asw.MarkFSResizeRequired(volumeName, podName)
|
asw.MarkFSResizeRequired(volumeName, podName)
|
||||||
@ -1806,6 +1808,8 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
|
|||||||
|
|
||||||
// 1. Add a volume to DSW and wait until it's mounted
|
// 1. Add a volume to DSW and wait until it's mounted
|
||||||
volumeSpec := &volume.Spec{Volume: &pod.Spec.Volumes[0]}
|
volumeSpec := &volume.Spec{Volume: &pod.Spec.Volumes[0]}
|
||||||
|
// copy before reconciler runs to avoid data race.
|
||||||
|
volumeSpecCopy := &volume.Spec{Volume: &pod.Spec.Volumes[0]}
|
||||||
podName := util.GetUniquePodName(pod)
|
podName := util.GetUniquePodName(pod)
|
||||||
generatedVolumeName, err := dsw.AddPodToVolume(
|
generatedVolumeName, err := dsw.AddPodToVolume(
|
||||||
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */)
|
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */)
|
||||||
@ -1832,7 +1836,7 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
|
|||||||
// 3. While a volume is being unmounted, add it back to the desired state of world
|
// 3. While a volume is being unmounted, add it back to the desired state of world
|
||||||
t.Logf("UnmountDevice called")
|
t.Logf("UnmountDevice called")
|
||||||
generatedVolumeName, err = dsw.AddPodToVolume(
|
generatedVolumeName, err = dsw.AddPodToVolume(
|
||||||
podName, pod, volumeSpec, volumeSpec.Name(), "" /* volumeGidValue */)
|
podName, pod, volumeSpecCopy, volumeSpec.Name(), "" /* volumeGidValue */)
|
||||||
dsw.MarkVolumesReportedInUse([]v1.UniqueVolumeName{generatedVolumeName})
|
dsw.MarkVolumesReportedInUse([]v1.UniqueVolumeName{generatedVolumeName})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user