Use the last NVIDIA_VISIBLE_DEVICES value from spec.

As described in #9401, we should use the last value of NVIDIA_VISIBLE_DEVICES
from the container spec to emulate nvidia-container-runtime-hook correctly.

Fixes #9401

PiperOrigin-RevId: 567480580
This commit is contained in:
Ayush Ranjan
2023-09-21 18:54:59 -07:00
committed by gVisor bot
parent fcacbf17c6
commit 19250b87ed
+8 -2
View File
@@ -657,9 +657,15 @@ func GetOOMScoreAdj(pid int) (int, error) {
return strconv.Atoi(strings.TrimSpace(string(data)))
}
// EnvVar looks for a varible value in the env slice assuming the following
// format: "NAME=VALUE".
// EnvVar looks for a variable value in the env slice assuming the following
// format: "NAME=VALUE". If a variable is defined multiple times, the last
// value is used.
func EnvVar(env []string, name string) (string, bool) {
var err error
env, err = ResolveEnvs(env)
if err != nil {
return "", false
}
prefix := name + "="
for _, e := range env {
if strings.HasPrefix(e, prefix) {