From 19250b87ede7311b70238dcd7329e3096a1b49d5 Mon Sep 17 00:00:00 2001 From: Ayush Ranjan Date: Thu, 21 Sep 2023 18:53:04 -0700 Subject: [PATCH] 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 --- runsc/specutils/specutils.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/runsc/specutils/specutils.go b/runsc/specutils/specutils.go index 703c27385..ad0de31e2 100644 --- a/runsc/specutils/specutils.go +++ b/runsc/specutils/specutils.go @@ -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) {