Use common code to construct nvidia-ctk hooks

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-01-19 10:37:10 +01:00
parent 27347c98d9
commit 19cfb2774d
2 changed files with 14 additions and 16 deletions

View File

@ -25,7 +25,6 @@ import (
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/drm"
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/sirupsen/logrus"
)
@ -130,18 +129,18 @@ func (d drmDevicesByPath) Hooks() ([]Hook, error) {
return nil, nil
}
args := []string{d.nvidiaCTKPath, "hook", "create-symlinks"}
var args []string
for _, l := range links {
args = append(args, "--link", l)
}
h := Hook{
Lifecycle: cdi.CreateContainerHook,
Path: d.nvidiaCTKPath,
Args: args,
}
hook := CreateNvidiaCTKHook(
d.nvidiaCTKPath,
"create-symlinks",
args...,
)
return []Hook{h}, nil
return []Hook{hook}, nil
}
// getSpecificLinkArgs returns the required specic links that need to be created

View File

@ -21,7 +21,6 @@ import (
"path/filepath"
"strings"
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
"github.com/sirupsen/logrus"
)
@ -47,7 +46,7 @@ func NewCreateSymlinksHook(logger *logrus.Logger, csvFiles []string, mounts Disc
// Hooks returns a hook to create the symlinks from the required CSV files
func (d symlinks) Hooks() ([]Hook, error) {
args := []string{d.nvidiaCTKPath, "hook", "create-symlinks"}
var args []string
for _, f := range d.csvFiles {
args = append(args, "--csv-filename", f)
}
@ -58,13 +57,13 @@ func (d symlinks) Hooks() ([]Hook, error) {
}
args = append(args, links...)
h := Hook{
Lifecycle: cdi.CreateContainerHook,
Path: d.nvidiaCTKPath,
Args: args,
}
hook := CreateNvidiaCTKHook(
d.nvidiaCTKPath,
"create-symlinks",
args...,
)
return []Hook{h}, nil
return []Hook{hook}, nil
}
// getSpecificLinkArgs returns the required specic links that need to be created