From 285e55c7b8db803037a52d197785b48e4ba9f7cf Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Tue, 15 Oct 2024 14:34:19 +0000 Subject: [PATCH] Sort UUIDs of prepared and allocatable devices for comparisons Signed-off-by: Kevin Klues --- cmd/nvidia-dra-plugin/allocatable.go | 8 +++++++- cmd/nvidia-dra-plugin/prepared.go | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/cmd/nvidia-dra-plugin/allocatable.go b/cmd/nvidia-dra-plugin/allocatable.go index 73dc530b..3350716c 100644 --- a/cmd/nvidia-dra-plugin/allocatable.go +++ b/cmd/nvidia-dra-plugin/allocatable.go @@ -17,6 +17,8 @@ package main import ( + "slices" + resourceapi "k8s.io/api/resource/v1alpha3" ) @@ -84,6 +86,7 @@ func (d AllocatableDevices) GpuUUIDs() []string { uuids = append(uuids, device.Gpu.UUID) } } + slices.Sort(uuids) return uuids } @@ -94,9 +97,12 @@ func (d AllocatableDevices) MigDeviceUUIDs() []string { uuids = append(uuids, device.Mig.UUID) } } + slices.Sort(uuids) return uuids } func (d AllocatableDevices) UUIDs() []string { - return append(d.GpuUUIDs(), d.MigDeviceUUIDs()...) + uuids := append(d.GpuUUIDs(), d.MigDeviceUUIDs()...) + slices.Sort(uuids) + return uuids } diff --git a/cmd/nvidia-dra-plugin/prepared.go b/cmd/nvidia-dra-plugin/prepared.go index bb9d59d9..edb369fe 100644 --- a/cmd/nvidia-dra-plugin/prepared.go +++ b/cmd/nvidia-dra-plugin/prepared.go @@ -17,6 +17,8 @@ package main import ( + "slices" + drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1alpha4" ) @@ -141,15 +143,21 @@ func (g *PreparedDeviceGroup) GetDevices() []*drapbv1.Device { } func (l PreparedDeviceList) UUIDs() []string { - return append(l.GpuUUIDs(), l.MigDeviceUUIDs()...) + uuids := append(l.GpuUUIDs(), l.MigDeviceUUIDs()...) + slices.Sort(uuids) + return uuids } func (g *PreparedDeviceGroup) UUIDs() []string { - return append(g.GpuUUIDs(), g.MigDeviceUUIDs()...) + uuids := append(g.GpuUUIDs(), g.MigDeviceUUIDs()...) + slices.Sort(uuids) + return uuids } func (d PreparedDevices) UUIDs() []string { - return append(d.GpuUUIDs(), d.MigDeviceUUIDs()...) + uuids := append(d.GpuUUIDs(), d.MigDeviceUUIDs()...) + slices.Sort(uuids) + return uuids } func (l PreparedDeviceList) GpuUUIDs() []string { @@ -157,6 +165,7 @@ func (l PreparedDeviceList) GpuUUIDs() []string { for _, device := range l.Gpus() { uuids = append(uuids, device.Gpu.Info.UUID) } + slices.Sort(uuids) return uuids } @@ -169,6 +178,7 @@ func (d PreparedDevices) GpuUUIDs() []string { for _, group := range d { uuids = append(uuids, group.GpuUUIDs()...) } + slices.Sort(uuids) return uuids } @@ -177,6 +187,7 @@ func (l PreparedDeviceList) MigDeviceUUIDs() []string { for _, device := range l.MigDevices() { uuids = append(uuids, device.Mig.Info.UUID) } + slices.Sort(uuids) return uuids } @@ -189,5 +200,6 @@ func (d PreparedDevices) MigDeviceUUIDs() []string { for _, group := range d { uuids = append(uuids, group.MigDeviceUUIDs()...) } + slices.Sort(uuids) return uuids }