From 7045a223d2b1be856fa1c399a07d1eb40a929b96 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 1 Feb 2023 04:12:49 +0100 Subject: [PATCH 1/3] 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) From 92dc0506fe9871235da7b35dea4821201807ea49 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 1 Feb 2023 04:41:24 +0100 Subject: [PATCH 2/3] Add hook path to logger output Signed-off-by: Evan Lezar --- internal/edits/edits.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/edits/edits.go b/internal/edits/edits.go index 96d40c60..425e01a8 100644 --- a/internal/edits/edits.go +++ b/internal/edits/edits.go @@ -108,7 +108,7 @@ func (e *edits) Modify(spec *ociSpecs.Spec) error { } e.logger.Infof("Hooks:") for _, hook := range e.Hooks { - e.logger.Infof("Injecting %v", hook.Args) + e.logger.Infof("Injecting %v %v", hook.Path, hook.Args) } return e.Apply(spec) From 0c8379f6815cd5aa17b23c941c47ccfa8aed7cc8 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 1 Feb 2023 04:47:57 +0100 Subject: [PATCH 3/3] Fix nvidia-ctk path for update ldcache hook This change ensures that the update-ldcache hook is created in a manner consistent with other nvidia-ctk hooks ensuring that a full path is used. Without this change the update-ldcache hook on Tegra-based sytems had an invalid path. Signed-off-by: Evan Lezar --- internal/discover/ldconfig.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/discover/ldconfig.go b/internal/discover/ldconfig.go index 83f26b36..e56f605a 100644 --- a/internal/discover/ldconfig.go +++ b/internal/discover/ldconfig.go @@ -21,7 +21,6 @@ import ( "path/filepath" "strings" - "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/sirupsen/logrus" ) @@ -29,9 +28,8 @@ import ( func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, cfg *Config) (Discover, error) { d := ldconfig{ logger: logger, + nvidiaCTKPath: FindNvidiaCTK(logger, cfg.NvidiaCTKPath), mountsFrom: mounts, - lookup: lookup.NewExecutableLocator(logger, cfg.Root), - nvidiaCTKPath: cfg.NvidiaCTKPath, } return &d, nil @@ -40,9 +38,8 @@ func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, cfg *Config) ( type ldconfig struct { None logger *logrus.Logger - mountsFrom Discover - lookup lookup.Locator nvidiaCTKPath string + mountsFrom Discover } // Hooks checks the required mounts for libraries and returns a hook to update the LDcache for the discovered paths.