mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-03-17 02:38:40 +00:00
Remove exsiting NVIDIA Container Runtime Hooks from the spec
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
dab6f4b768
commit
45160b88a4
@ -231,7 +231,7 @@ func TestExperimentalModifier(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "modification fails for existing nvidia-container-runtime-hook",
|
description: "modification removes existing nvidia-container-runtime-hook",
|
||||||
spec: &specs.Spec{
|
spec: &specs.Spec{
|
||||||
Hooks: &specs.Hooks{
|
Hooks: &specs.Hooks{
|
||||||
Prestart: []specs.Hook{
|
Prestart: []specs.Hook{
|
||||||
@ -254,20 +254,19 @@ func TestExperimentalModifier(t *testing.T) {
|
|||||||
return hooks, nil
|
return hooks, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: fmt.Errorf("nvidia-container-runtime-hook already exists"),
|
|
||||||
expectedSpec: &specs.Spec{
|
expectedSpec: &specs.Spec{
|
||||||
Hooks: &specs.Hooks{
|
Hooks: &specs.Hooks{
|
||||||
Prestart: []specs.Hook{
|
Prestart: []specs.Hook{
|
||||||
{
|
{
|
||||||
Path: "/path/to/nvidia-container-runtime-hook",
|
Path: "/hook/b",
|
||||||
Args: []string{"/path/to/nvidia-container-runtime-hook", "prestart"},
|
Args: []string{"/hook/b", "argb"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "modification fails for existing nvidia-container-toolkit",
|
description: "modification removes existing nvidia-container-toolkit",
|
||||||
spec: &specs.Spec{
|
spec: &specs.Spec{
|
||||||
Hooks: &specs.Hooks{
|
Hooks: &specs.Hooks{
|
||||||
Prestart: []specs.Hook{
|
Prestart: []specs.Hook{
|
||||||
@ -290,13 +289,12 @@ func TestExperimentalModifier(t *testing.T) {
|
|||||||
return hooks, nil
|
return hooks, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expectedError: fmt.Errorf("nvidia-container-toolkit already exists"),
|
|
||||||
expectedSpec: &specs.Spec{
|
expectedSpec: &specs.Spec{
|
||||||
Hooks: &specs.Hooks{
|
Hooks: &specs.Hooks{
|
||||||
Prestart: []specs.Hook{
|
Prestart: []specs.Hook{
|
||||||
{
|
{
|
||||||
Path: "/path/to/nvidia-container-toolkit",
|
Path: "/hook/b",
|
||||||
Args: []string{"/path/to/nvidia-container-toolkit", "prestart"},
|
Args: []string{"/hook/b", "argb"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package modifier
|
package modifier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
@ -46,10 +45,19 @@ func (m nvidiaContainerRuntimeHookRemover) Modify(spec *specs.Spec) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var newPrestart []specs.Hook
|
||||||
|
|
||||||
for _, hook := range spec.Hooks.Prestart {
|
for _, hook := range spec.Hooks.Prestart {
|
||||||
if isNVIDIAContainerRuntimeHook(&hook) {
|
if isNVIDIAContainerRuntimeHook(&hook) {
|
||||||
return fmt.Errorf("spec already contains required 'prestart' hook")
|
m.logger.Debugf("Removing hook %v", hook)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
newPrestart = append(newPrestart, hook)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(newPrestart) != len(spec.Hooks.Prestart) {
|
||||||
|
m.logger.Debugf("Updating 'prestart' hooks to %v", newPrestart)
|
||||||
|
spec.Hooks.Prestart = newPrestart
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user