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