switch volumemanager reconciler tests to fnv-1a

128 bit fnv-1a is a pretty good non-cryptographic drop-in for md5, it should be faster, and this test code is not sensitive anyhow
This commit is contained in:
Benjamin Elder
2025-08-14 12:15:41 -07:00
parent 797d316519
commit b3373320da

View File

@@ -18,8 +18,8 @@ package reconciler
import (
"context"
"crypto/md5"
"fmt"
"hash/fnv"
"path/filepath"
"sync"
"testing"
@@ -1523,16 +1523,14 @@ func Test_UncertainDeviceGlobalMounts(t *testing.T) {
modes := []v1.PersistentVolumeMode{v1.PersistentVolumeBlock, v1.PersistentVolumeFilesystem}
hasher := fnv.New128a()
for modeIndex := range modes {
for tcIndex := range tests {
mode := modes[modeIndex]
tc := tests[tcIndex]
testName := fmt.Sprintf("%s [%s]", tc.name, mode)
uniqueTestString := fmt.Sprintf("global-mount-%s", testName)
// TODO: finish removing existing md5 usage
// https://github.com/kubernetes/kubernetes/issues/129652
//nolint:forbidigo
uniquePodDir := fmt.Sprintf("%s-%x", kubeletPodsDir, md5.Sum([]byte(uniqueTestString)))
uniquePodDir := fmt.Sprintf("%s-%x", kubeletPodsDir, hasher.Sum([]byte(uniqueTestString)))
t.Run(testName+"[", func(t *testing.T) {
t.Parallel()
pv := &v1.PersistentVolume{
@@ -1739,16 +1737,14 @@ func Test_UncertainVolumeMountState(t *testing.T) {
}
modes := []v1.PersistentVolumeMode{v1.PersistentVolumeBlock, v1.PersistentVolumeFilesystem}
hasher := fnv.New128a()
for modeIndex := range modes {
for tcIndex := range tests {
mode := modes[modeIndex]
tc := tests[tcIndex]
testName := fmt.Sprintf("%s [%s]", tc.name, mode)
uniqueTestString := fmt.Sprintf("local-mount-%s", testName)
// TODO: finish removing existing md5 usage
// https://github.com/kubernetes/kubernetes/issues/129652
//nolint:forbidigo
uniquePodDir := fmt.Sprintf("%s-%x", kubeletPodsDir, md5.Sum([]byte(uniqueTestString)))
uniquePodDir := fmt.Sprintf("%s-%x", kubeletPodsDir, hasher.Sum([]byte(uniqueTestString)))
t.Run(testName, func(t *testing.T) {
t.Parallel()
pv := &v1.PersistentVolume{