11/*
2- Copyright The Kubernetes Authors.
2+ Copyright 2026 The Kubernetes Authors.
33
44Licensed under the Apache License, Version 2.0 (the "License");
55you may not use this file except in compliance with the License.
@@ -48,6 +48,9 @@ type ExemplaryPodFuzzer struct {
4848 // Maps BasePodName -> FuzzedPrototype
4949 mu sync.Mutex
5050 cachedPrototypes map [string ]* v1.Pod
51+
52+ // rngMu protects access to the non-thread-safe rng.
53+ rngMu sync.Mutex
5154}
5255
5356// NewExemplaryPodFuzzer creates a new fuzzer with a seeded RNG and global settings.
@@ -163,7 +166,10 @@ func (f *ExemplaryPodFuzzer) fuzzMapRecursive(m map[string]interface{}) {
163166
164167 var newKey string
165168 if strings .HasPrefix (oldKey , "k:" ) {
166- newKey = fmt .Sprintf ("k:{\" id\" :%d,\" name\" :\" fuzzed-node-%s\" }" , f .rng .Intn (100 ), f .randomString (4 ))
169+ f .rngMu .Lock ()
170+ idx := f .rng .Intn (100 )
171+ f .rngMu .Unlock ()
172+ newKey = fmt .Sprintf ("k:{\" id\" :%d,\" name\" :\" fuzzed-node-%s\" }" , idx , f .randomString (4 ))
167173 } else if strings .HasPrefix (oldKey , "f:" ) {
168174 newKey = "f:fuzzed_field_" + f .randomString (4 )
169175 } else if oldKey == "." {
@@ -187,6 +193,8 @@ func (f *ExemplaryPodFuzzer) randomString(length int) string {
187193 }
188194 const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
189195 b := make ([]byte , length )
196+ f .rngMu .Lock ()
197+ defer f .rngMu .Unlock ()
190198 for i := range b {
191199 b [i ] = charset [f .rng .Intn (len (charset ))]
192200 }
0 commit comments