From 1555877cc5d19915fc60f115f6d43b5ad6cb1124 Mon Sep 17 00:00:00 2001
From: njuptlzf
Date: Wed, 30 Jun 2021 00:32:36 +0800
Subject: [PATCH] fix data race for
Test_Run_Positive_VolumeMountControllerAttachEnabledRace
---
.../volumemanager/reconciler/reconciler_test.go | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/pkg/kubelet/volumemanager/reconciler/reconciler_test.go b/pkg/kubelet/volumemanager/reconciler/reconciler_test.go
index 10bb3080610..50c4267547b 100644
--- a/pkg/kubelet/volumemanager/reconciler/reconciler_test.go
+++ b/pkg/kubelet/volumemanager/reconciler/reconciler_test.go
@@ -36,6 +36,7 @@ import (
core "k8s.io/client-go/testing"
"k8s.io/client-go/tools/record"
featuregatetesting "k8s.io/component-base/featuregate/testing"
+ "k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubelet/volumemanager/cache"
"k8s.io/kubernetes/pkg/volume"
@@ -1834,10 +1835,11 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
fakePlugin.UnmountDeviceHook = func(mountPath string) error {
// Act:
// 3. While a volume is being unmounted, add it back to the desired state of world
- t.Logf("UnmountDevice called")
- generatedVolumeName, err = dsw.AddPodToVolume(
+ klog.InfoS("UnmountDevice called")
+ var generatedVolumeNameCopy v1.UniqueVolumeName
+ generatedVolumeNameCopy, err = dsw.AddPodToVolume(
podName, pod, volumeSpecCopy, volumeSpec.Name(), "" /* volumeGidValue */)
- dsw.MarkVolumesReportedInUse([]v1.UniqueVolumeName{generatedVolumeName})
+ dsw.MarkVolumesReportedInUse([]v1.UniqueVolumeName{generatedVolumeNameCopy})
return nil
}
@@ -1845,7 +1847,7 @@ func Test_Run_Positive_VolumeMountControllerAttachEnabledRace(t *testing.T) {
// Assert
// 4. When the volume is mounted again, expect that UnmountDevice operation did not clear devicePath
if devicePath == "" {
- t.Errorf("Expected WaitForAttach called with devicePath from Node.Status")
+ klog.ErrorS(nil, "Expected WaitForAttach called with devicePath from Node.Status")
close(finished)
return "", fmt.Errorf("Expected devicePath from Node.Status")
}