mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 21:39:10 +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{
|
||||
Hooks: &specs.Hooks{
|
||||
Prestart: []specs.Hook{
|
||||
@ -254,20 +254,19 @@ func TestExperimentalModifier(t *testing.T) {
|
||||
return hooks, nil
|
||||
},
|
||||
},
|
||||
expectedError: fmt.Errorf("nvidia-container-runtime-hook already exists"),
|
||||
expectedSpec: &specs.Spec{
|
||||
Hooks: &specs.Hooks{
|
||||
Prestart: []specs.Hook{
|
||||
{
|
||||
Path: "/path/to/nvidia-container-runtime-hook",
|
||||
Args: []string{"/path/to/nvidia-container-runtime-hook", "prestart"},
|
||||
Path: "/hook/b",
|
||||
Args: []string{"/hook/b", "argb"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
description: "modification fails for existing nvidia-container-toolkit",
|
||||
description: "modification removes existing nvidia-container-toolkit",
|
||||
spec: &specs.Spec{
|
||||
Hooks: &specs.Hooks{
|
||||
Prestart: []specs.Hook{
|
||||
@ -290,13 +289,12 @@ func TestExperimentalModifier(t *testing.T) {
|
||||
return hooks, nil
|
||||
},
|
||||
},
|
||||
expectedError: fmt.Errorf("nvidia-container-toolkit already exists"),
|
||||
expectedSpec: &specs.Spec{
|
||||
Hooks: &specs.Hooks{
|
||||
Prestart: []specs.Hook{
|
||||
{
|
||||
Path: "/path/to/nvidia-container-toolkit",
|
||||
Args: []string{"/path/to/nvidia-container-toolkit", "prestart"},
|
||||
Path: "/hook/b",
|
||||
Args: []string{"/hook/b", "argb"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -17,7 +17,6 @@
|
||||
package modifier
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||
@ -46,10 +45,19 @@ func (m nvidiaContainerRuntimeHookRemover) Modify(spec *specs.Spec) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var newPrestart []specs.Hook
|
||||
|
||||
for _, hook := range spec.Hooks.Prestart {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user