From 0b8dc56408fd04e5073a9bbe262729424a56f99f Mon Sep 17 00:00:00 2001 From: yuzhiquan Date: Tue, 1 Jun 2021 17:14:00 +0800 Subject: [PATCH] fix volume failing test --- .../volume/attachdetach/testing/testvolumespec.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/controller/volume/attachdetach/testing/testvolumespec.go b/pkg/controller/volume/attachdetach/testing/testvolumespec.go index 776d79f16c4..7df558cc7fa 100644 --- a/pkg/controller/volume/attachdetach/testing/testvolumespec.go +++ b/pkg/controller/volume/attachdetach/testing/testvolumespec.go @@ -173,29 +173,38 @@ func CreateTestClient() *fake.Clientset { obj.Items = append(obj.Items, nodes.Items...) return true, obj, nil }) + var mu sync.Mutex volumeAttachments = &storagev1.VolumeAttachmentList{} fakeClient.AddReactor("list", "volumeattachments", func(action core.Action) (handled bool, ret runtime.Object, err error) { obj := &storagev1.VolumeAttachmentList{} + mu.Lock() obj.Items = append(obj.Items, volumeAttachments.Items...) + mu.Unlock() return true, obj, nil }) fakeClient.AddReactor("create", "volumeattachments", func(action core.Action) (handled bool, ret runtime.Object, err error) { createAction := action.(core.CreateAction) va := createAction.GetObject().(*storagev1.VolumeAttachment) + mu.Lock() volumeAttachments.Items = append(volumeAttachments.Items, *va) + mu.Unlock() return true, createAction.GetObject(), nil }) pvs = &v1.PersistentVolumeList{} fakeClient.AddReactor("list", "persistentvolumes", func(action core.Action) (handled bool, ret runtime.Object, err error) { obj := &v1.PersistentVolumeList{} + mu.Lock() obj.Items = append(obj.Items, pvs.Items...) + mu.Unlock() return true, obj, nil }) fakeClient.AddReactor("create", "persistentvolumes", func(action core.Action) (handled bool, ret runtime.Object, err error) { createAction := action.(core.CreateAction) pv := createAction.GetObject().(*v1.PersistentVolume) + mu.Lock() pvs.Items = append(pvs.Items, *pv) + mu.Unlock() return true, createAction.GetObject(), nil })