mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-15 02:48:18 +00:00
Ensure consistent sorting of annotation devices
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
8f514be1e8
commit
7fe0aad96b
@ -19,6 +19,7 @@ package image
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -281,17 +282,24 @@ func (i CUDA) cdiDeviceRequestsFromAnnotations() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
var devices []string
|
||||
for key, value := range i.annotations {
|
||||
var annotationKeys []string
|
||||
for key := range i.annotations {
|
||||
for _, prefix := range i.annotationsPrefixes {
|
||||
if strings.HasPrefix(key, prefix) {
|
||||
devices = append(devices, strings.Split(value, ",")...)
|
||||
annotationKeys = append(annotationKeys, key)
|
||||
// There is no need to check additional prefixes since we
|
||||
// typically deduplicate devices in any case.
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
// We sort the annotationKeys for consistent results.
|
||||
slices.Sort(annotationKeys)
|
||||
|
||||
var devices []string
|
||||
for _, key := range annotationKeys {
|
||||
devices = append(devices, strings.Split(i.annotations[key], ",")...)
|
||||
}
|
||||
return devices
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ func TestDeviceRequests(t *testing.T) {
|
||||
"another-prefix/bar": "example.com/device=baz",
|
||||
},
|
||||
},
|
||||
expectedDevices: []string{"example.com/device=bar", "example.com/device=baz"},
|
||||
expectedDevices: []string{"example.com/device=baz", "example.com/device=bar"},
|
||||
},
|
||||
{
|
||||
description: "multiple matching annotations with duplicate devices",
|
||||
|
Loading…
Reference in New Issue
Block a user