mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Merge branch 'fix-hook-removal' into 'main'
Improve locating NVIDIA Container Runtime Hook See merge request nvidia/container-toolkit/container-toolkit!215
This commit is contained in:
commit
9bbf7dcf96
@ -48,7 +48,12 @@ func run(argv []string) (rerr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to set up logger: %v", err)
|
return fmt.Errorf("failed to set up logger: %v", err)
|
||||||
}
|
}
|
||||||
defer logger.Reset()
|
defer func() {
|
||||||
|
if rerr != nil {
|
||||||
|
logger.Errorf("%v", rerr)
|
||||||
|
}
|
||||||
|
logger.Reset()
|
||||||
|
}()
|
||||||
|
|
||||||
logger.Debugf("Command line arguments: %v", argv)
|
logger.Debugf("Command line arguments: %v", argv)
|
||||||
runtime, err := newNVIDIAContainerRuntime(logger.Logger, cfg, argv)
|
runtime, err := newNVIDIAContainerRuntime(logger.Logger, cfg, argv)
|
||||||
|
@ -17,11 +17,10 @@
|
|||||||
package modifier
|
package modifier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"fmt"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -44,21 +43,8 @@ type stableRuntimeModifier struct {
|
|||||||
// Modify applies the required modification to the incoming OCI spec, inserting the nvidia-container-runtime-hook
|
// Modify applies the required modification to the incoming OCI spec, inserting the nvidia-container-runtime-hook
|
||||||
// as a prestart hook.
|
// as a prestart hook.
|
||||||
func (m stableRuntimeModifier) Modify(spec *specs.Spec) error {
|
func (m stableRuntimeModifier) Modify(spec *specs.Spec) error {
|
||||||
path, err := exec.LookPath(config.NVIDIAContainerRuntimeHookExecutable)
|
// If an NVIDIA Container Runtime Hook already exists, we don't make any modifications to the spec.
|
||||||
if err != nil {
|
if spec.Hooks != nil {
|
||||||
path = filepath.Join(config.DefaultExecutableDir, config.NVIDIAContainerRuntimeHookExecutable)
|
|
||||||
_, err = os.Stat(path)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m.logger.Infof("Using prestart hook path: %s", path)
|
|
||||||
|
|
||||||
args := []string{path}
|
|
||||||
if spec.Hooks == nil {
|
|
||||||
spec.Hooks = &specs.Hooks{}
|
|
||||||
} else if len(spec.Hooks.Prestart) != 0 {
|
|
||||||
for _, hook := range spec.Hooks.Prestart {
|
for _, hook := range spec.Hooks.Prestart {
|
||||||
if isNVIDIAContainerRuntimeHook(&hook) {
|
if isNVIDIAContainerRuntimeHook(&hook) {
|
||||||
m.logger.Infof("Existing nvidia prestart hook (%v) found in OCI spec", hook.Path)
|
m.logger.Infof("Existing nvidia prestart hook (%v) found in OCI spec", hook.Path)
|
||||||
@ -67,6 +53,21 @@ func (m stableRuntimeModifier) Modify(spec *specs.Spec) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We create a locator and look for the NVIDIA Container Runtime Hook in the path.
|
||||||
|
candidates, err := lookup.NewExecutableLocator(m.logger, "").Locate(config.NVIDIAContainerRuntimeHookExecutable)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to locate NVIDIA Container Runtime Hook: %v", err)
|
||||||
|
}
|
||||||
|
path := candidates[0]
|
||||||
|
if len(candidates) > 1 {
|
||||||
|
m.logger.Debugf("Using %v from multiple NVIDIA Container Runtime Hook candidates: %v", path, candidates)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logger.Infof("Using prestart hook path: %v", path)
|
||||||
|
args := []string{path}
|
||||||
|
if spec.Hooks == nil {
|
||||||
|
spec.Hooks = &specs.Hooks{}
|
||||||
|
}
|
||||||
spec.Hooks.Prestart = append(spec.Hooks.Prestart, specs.Hook{
|
spec.Hooks.Prestart = append(spec.Hooks.Prestart, specs.Hook{
|
||||||
Path: path,
|
Path: path,
|
||||||
Args: append(args, "prestart"),
|
Args: append(args, "prestart"),
|
||||||
|
@ -56,7 +56,7 @@ install -m 644 -t %{buildroot}/usr/share/containers/oci/hooks.d oci-nvidia-hook.
|
|||||||
ln -sf %{_bindir}/nvidia-container-runtime-hook %{_bindir}/nvidia-container-toolkit
|
ln -sf %{_bindir}/nvidia-container-runtime-hook %{_bindir}/nvidia-container-toolkit
|
||||||
|
|
||||||
%postun
|
%postun
|
||||||
rm -f %{_bindir}/nvidia-container-toolkit
|
if [ -L %{_bindir}/nvidia-container-toolkit ] then; rm -f %{_bindir}/nvidia-container-toolkit; fi
|
||||||
|
|
||||||
%files
|
%files
|
||||||
%license LICENSE
|
%license LICENSE
|
||||||
|
Loading…
Reference in New Issue
Block a user