mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Move NVIDIA Container Runtime Hook executable name to shared constant
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
@@ -60,8 +61,8 @@ func (m nvidiaContainerRuntimeHookRemover) Modify(spec *specs.Spec) error {
|
||||
// nvidia-container-runtime or docker when specifying the --gpus flag.
|
||||
func isNVIDIAContainerRuntimeHook(hook *specs.Hook) bool {
|
||||
bins := map[string]struct{}{
|
||||
nvidiaContainerRuntimeHookExecutable: {},
|
||||
nvidiaContainerToolkitExecutable: {},
|
||||
config.NVIDIAContainerRuntimeHookExecutable: {},
|
||||
config.NVIDIAContainerToolkitExecutable: {},
|
||||
}
|
||||
|
||||
_, exists := bins[filepath.Base(hook.Path)]
|
||||
|
||||
@@ -28,11 +28,6 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
nvidiaContainerRuntimeHookExecutable = "nvidia-container-runtime-hook"
|
||||
nvidiaContainerToolkitExecutable = "nvidia-container-toolkit"
|
||||
)
|
||||
|
||||
// NewStableRuntimeModifier creates an OCI spec modifier that inserts the NVIDIA Container Runtime Hook into an OCI
|
||||
// spec. The specified logger is used to capture log output.
|
||||
func NewStableRuntimeModifier(logger *logrus.Logger) oci.SpecModifier {
|
||||
@@ -50,9 +45,9 @@ type stableRuntimeModifier struct {
|
||||
// Modify applies the required modification to the incoming OCI spec, inserting the nvidia-container-runtime-hook
|
||||
// as a prestart hook.
|
||||
func (m stableRuntimeModifier) Modify(spec *specs.Spec) error {
|
||||
path, err := exec.LookPath(nvidiaContainerRuntimeHookExecutable)
|
||||
path, err := exec.LookPath(config.NVIDIAContainerRuntimeHookExecutable)
|
||||
if err != nil {
|
||||
path = filepath.Join(config.DefaultExecutableDir, nvidiaContainerRuntimeHookExecutable)
|
||||
path = filepath.Join(config.DefaultExecutableDir, config.NVIDIAContainerRuntimeHookExecutable)
|
||||
_, err = os.Stat(path)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -66,7 +61,7 @@ func (m stableRuntimeModifier) Modify(spec *specs.Spec) error {
|
||||
spec.Hooks = &specs.Hooks{}
|
||||
} else if len(spec.Hooks.Prestart) != 0 {
|
||||
for _, hook := range spec.Hooks.Prestart {
|
||||
if strings.Contains(hook.Path, nvidiaContainerRuntimeHookExecutable) {
|
||||
if strings.Contains(hook.Path, config.NVIDIAContainerRuntimeHookExecutable) {
|
||||
m.logger.Infof("existing nvidia prestart hook found in OCI spec")
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user