Skip to content

Commit

Permalink
Merge branch 'fix-nvidia-ctk-path' into 'main'
Browse files Browse the repository at this point in the history
Only use configured nvidia-ctk path if it is a full path

See merge request nvidia/container-toolkit/container-toolkit!281
  • Loading branch information
Evan Lezar committed Feb 1, 2023
2 parents 763e493 + 0c8379f commit 9a06768
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
20 changes: 11 additions & 9 deletions internal/discover/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions internal/discover/ldconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ import (
"path/filepath"
"strings"

"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
"github.com/sirupsen/logrus"
)

// NewLDCacheUpdateHook creates a discoverer that updates the ldcache for the specified mounts. A logger can also be specified
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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion internal/edits/edits.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9a06768

Please sign in to comment.