Files
argo-cd/controller/syncid/id.go
Alexandre Gaudreault 1d09c8c8a1 fix(tests): race condition creating the sync id (#23481)
Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
2025-06-18 20:37:57 +00:00

21 lines
408 B
Go

package syncid
import (
"fmt"
"sync/atomic"
"github.com/argoproj/argo-cd/v3/util/rand"
)
var globalCount = &atomic.Uint64{}
// Generate generates a new ID
func Generate() (string, error) {
randSuffix, err := rand.String(5)
if err != nil {
return "", fmt.Errorf("failed to generate random suffix: %w", err)
}
prefix := globalCount.Add(1)
return fmt.Sprintf("%05d-%s", prefix, randSuffix), nil
}