Skip to content

Commit

Permalink
use uuid.NewSHA1 package to generate uuids
Browse files Browse the repository at this point in the history
Signed-off-by: Tariq Ibrahim <[email protected]>
  • Loading branch information
tariq1890 committed Oct 18, 2024
1 parent bfbce33 commit 1313167
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
22 changes: 4 additions & 18 deletions internal/lm/fabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}
4 changes: 2 additions & 2 deletions internal/lm/fabric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
}

Expand Down

0 comments on commit 1313167

Please sign in to comment.