From 131316762cb35d599d3f37c08cd9ac61cae68a51 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Thu, 17 Oct 2024 11:33:05 -0700 Subject: [PATCH] use uuid.NewSHA1 package to generate uuids Signed-off-by: Tariq Ibrahim --- internal/lm/fabric.go | 22 ++++------------------ internal/lm/fabric_test.go | 4 ++-- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/internal/lm/fabric.go b/internal/lm/fabric.go index 8a4f66e8e..f84d2a3ed 100644 --- a/internal/lm/fabric.go +++ b/internal/lm/fabric.go @@ -20,17 +20,16 @@ import ( "bufio" "fmt" "io" - "math/rand" // nolint:gosec "net" "os" "sort" "strings" - spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1" - "github.com/NVIDIA/k8s-device-plugin/internal/resource" - "github.com/google/uuid" "k8s.io/klog/v2" + + spec "github.com/NVIDIA/k8s-device-plugin/api/config/v1" + "github.com/NVIDIA/k8s-device-plugin/internal/resource" ) func newImexLabeler(config *spec.Config, devices []resource.Device) (Labeler, error) { @@ -142,18 +141,5 @@ func getImexDomainID(r io.Reader) (string, error) { } func generateContentUUID(seed string) string { - // nolint:gosec - rand := rand.New(rand.NewSource(hash(seed))) - charset := make([]byte, 16) - rand.Read(charset) - uuid, _ := uuid.FromBytes(charset) - return uuid.String() -} - -func hash(s string) int64 { - h := int64(0) - for _, c := range s { - h = 31*h + int64(c) - } - return h + return uuid.NewSHA1(uuid.Nil, []byte(seed)).String() } diff --git a/internal/lm/fabric_test.go b/internal/lm/fabric_test.go index b951ef890..553976465 100644 --- a/internal/lm/fabric_test.go +++ b/internal/lm/fabric_test.go @@ -32,7 +32,7 @@ func TestGerenerateDomainUUID(t *testing.T) { { description: "single IP", ips: []string{"10.130.3.24"}, - expected: "4dbd3d31-fbb3-8a40-33bb-bcc0dd7b68b8", + expected: "60ad7226-0130-54d0-b762-2a5385a3a26f", }, { description: "multiple IPs", @@ -44,7 +44,7 @@ func TestGerenerateDomainUUID(t *testing.T) { "10.130.3.27", "10.130.3.25", }, - expected: "42401dd1-8a08-1889-4341-8429de2b6f42", + expected: "8a7363e9-1003-5814-9354-175fdff19204", }, }