From 7045a223d2b1be856fa1c399a07d1eb40a929b96 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 1 Feb 2023 04:12:49 +0100 Subject: [PATCH] Only use configured nvidia-ctk path if it is a full path If this is not done, the default config which sets the nvidia-ctk.path option as "nvidia-ctk" will result in an invalid OCI spec if a hook is injected. This change ensures that the path used is always an absolute path as required by the hook spec. Signed-off-by: Evan Lezar --- internal/discover/hooks.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/internal/discover/hooks.go b/internal/discover/hooks.go index f8aeea44..708260e1 100644 --- a/internal/discover/hooks.go +++ b/internal/discover/hooks.go @@ -39,22 +39,24 @@ func CreateNvidiaCTKHook(executable string, hookName string, additionalArgs ...s } // FindNvidiaCTK locates the nvidia-ctk executable to be used in hooks. -// If an override is specified, this is used instead. -func FindNvidiaCTK(logger *logrus.Logger, override string) string { - if override != "" { - logger.Debugf("Using specified NVIDIA Container Toolkit CLI path %v", override) - return override +// If an nvidia-ctk path is specified as an absolute path, it is used directly +// without checking for existence of an executable at that path. +func FindNvidiaCTK(logger *logrus.Logger, nvidiaCTKPath string) string { + if filepath.IsAbs(nvidiaCTKPath) { + logger.Debugf("Using specified NVIDIA Container Toolkit CLI path %v", nvidiaCTKPath) + return nvidiaCTKPath } + logger.Debugf("Locating NVIDIA Container Toolkit CLI as %v", nvidiaCTKPath) lookup := lookup.NewExecutableLocator(logger, "") hookPath := nvidiaCTKDefaultFilePath - targets, err := lookup.Locate(nvidiaCTKExecutable) + targets, err := lookup.Locate(nvidiaCTKPath) if err != nil { - logger.Warnf("Failed to locate %v: %v", nvidiaCTKExecutable, err) + logger.Warnf("Failed to locate %v: %v", nvidiaCTKPath, err) } else if len(targets) == 0 { - logger.Warnf("%v not found", nvidiaCTKExecutable) + logger.Warnf("%v not found", nvidiaCTKPath) } else { - logger.Debugf("Found %v candidates: %v", nvidiaCTKExecutable, targets) + logger.Debugf("Found %v candidates: %v", nvidiaCTKPath, targets) hookPath = targets[0] } logger.Debugf("Using NVIDIA Container Toolkit CLI path %v", hookPath)