Skip to content

Commit

Permalink
Merge pull request #180 from klueska/sort-uuids
Browse files Browse the repository at this point in the history
Sort UUIDs of prepared and allocatable devices for comparisons
  • Loading branch information
klueska authored Oct 15, 2024
2 parents 6602179 + 285e55c commit 0e74a41
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion cmd/nvidia-dra-plugin/allocatable.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package main

import (
"slices"

resourceapi "k8s.io/api/resource/v1alpha3"
)

Expand Down Expand Up @@ -84,6 +86,7 @@ func (d AllocatableDevices) GpuUUIDs() []string {
uuids = append(uuids, device.Gpu.UUID)
}
}
slices.Sort(uuids)
return uuids
}

Expand All @@ -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
}
18 changes: 15 additions & 3 deletions cmd/nvidia-dra-plugin/prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package main

import (
"slices"

drapbv1 "k8s.io/kubelet/pkg/apis/dra/v1alpha4"
)

Expand Down Expand Up @@ -141,22 +143,29 @@ 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 {
var uuids []string
for _, device := range l.Gpus() {
uuids = append(uuids, device.Gpu.Info.UUID)
}
slices.Sort(uuids)
return uuids
}

Expand All @@ -169,6 +178,7 @@ func (d PreparedDevices) GpuUUIDs() []string {
for _, group := range d {
uuids = append(uuids, group.GpuUUIDs()...)
}
slices.Sort(uuids)
return uuids
}

Expand All @@ -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
}

Expand All @@ -189,5 +200,6 @@ func (d PreparedDevices) MigDeviceUUIDs() []string {
for _, group := range d {
uuids = append(uuids, group.MigDeviceUUIDs()...)
}
slices.Sort(uuids)
return uuids
}

0 comments on commit 0e74a41

Please sign in to comment.