Merge branch 'fix-nvidia-ctk-path' into 'main'

Only use configured nvidia-ctk path if it is a full path

See merge request nvidia/container-toolkit/container-toolkit!281
This commit is contained in:
Evan Lezar 2023-02-01 11:42:09 +00:00
commit 9a06768863
3 changed files with 14 additions and 15 deletions

View File

@ -39,22 +39,24 @@ func CreateNvidiaCTKHook(executable string, hookName string, additionalArgs ...s
} }
// FindNvidiaCTK locates the nvidia-ctk executable to be used in hooks. // FindNvidiaCTK locates the nvidia-ctk executable to be used in hooks.
// If an override is specified, this is used instead. // If an nvidia-ctk path is specified as an absolute path, it is used directly
func FindNvidiaCTK(logger *logrus.Logger, override string) string { // without checking for existence of an executable at that path.
if override != "" { func FindNvidiaCTK(logger *logrus.Logger, nvidiaCTKPath string) string {
logger.Debugf("Using specified NVIDIA Container Toolkit CLI path %v", override) if filepath.IsAbs(nvidiaCTKPath) {
return override 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, "") lookup := lookup.NewExecutableLocator(logger, "")
hookPath := nvidiaCTKDefaultFilePath hookPath := nvidiaCTKDefaultFilePath
targets, err := lookup.Locate(nvidiaCTKExecutable) targets, err := lookup.Locate(nvidiaCTKPath)
if err != nil { 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 { } else if len(targets) == 0 {
logger.Warnf("%v not found", nvidiaCTKExecutable) logger.Warnf("%v not found", nvidiaCTKPath)
} else { } else {
logger.Debugf("Found %v candidates: %v", nvidiaCTKExecutable, targets) logger.Debugf("Found %v candidates: %v", nvidiaCTKPath, targets)
hookPath = targets[0] hookPath = targets[0]
} }
logger.Debugf("Using NVIDIA Container Toolkit CLI path %v", hookPath) logger.Debugf("Using NVIDIA Container Toolkit CLI path %v", hookPath)

View File

@ -21,7 +21,6 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -29,9 +28,8 @@ import (
func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, cfg *Config) (Discover, error) { func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, cfg *Config) (Discover, error) {
d := ldconfig{ d := ldconfig{
logger: logger, logger: logger,
nvidiaCTKPath: FindNvidiaCTK(logger, cfg.NvidiaCTKPath),
mountsFrom: mounts, mountsFrom: mounts,
lookup: lookup.NewExecutableLocator(logger, cfg.Root),
nvidiaCTKPath: cfg.NvidiaCTKPath,
} }
return &d, nil return &d, nil
@ -40,9 +38,8 @@ func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, cfg *Config) (
type ldconfig struct { type ldconfig struct {
None None
logger *logrus.Logger logger *logrus.Logger
mountsFrom Discover
lookup lookup.Locator
nvidiaCTKPath string nvidiaCTKPath string
mountsFrom Discover
} }
// Hooks checks the required mounts for libraries and returns a hook to update the LDcache for the discovered paths. // Hooks checks the required mounts for libraries and returns a hook to update the LDcache for the discovered paths.

View File

@ -108,7 +108,7 @@ func (e *edits) Modify(spec *ociSpecs.Spec) error {
} }
e.logger.Infof("Hooks:") e.logger.Infof("Hooks:")
for _, hook := range e.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) return e.Apply(spec)