Merge pull request #115799 from pohly/test-util-data-race

test/utils: avoid data race during parallel create
This commit is contained in:
Kubernetes Prow Robot 2023-02-16 01:53:38 -08:00 committed by GitHub
commit 1e84987bac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1346,7 +1346,10 @@ func CreatePod(ctx context.Context, client clientset.Interface, namespace string
var createError error
lock := sync.Mutex{}
createPodFunc := func(i int) {
if err := makeCreatePod(client, namespace, podTemplate); err != nil {
// client-go writes into the object that is passed to Create,
// causing a data race unless we create a new copy for each
// parallel call.
if err := makeCreatePod(client, namespace, podTemplate.DeepCopy()); err != nil {
lock.Lock()
defer lock.Unlock()
createError = err