mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 00:08:11 +00:00
Refactor hook creation
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
99baea9d51
commit
7914957105
@ -22,20 +22,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type legacy struct {
|
// NewLegacyDiscoverer creates a discoverer for the experimental runtime
|
||||||
None
|
|
||||||
logger *logrus.Logger
|
|
||||||
lookup lookup.Locator
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
|
||||||
nvidiaContainerRuntimeHookExecutable = "nvidia-container-runtime-hook"
|
|
||||||
hookDefaultFilePath = "/usr/bin/nvidia-container-runtime-hook"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ Discover = (*legacy)(nil)
|
|
||||||
|
|
||||||
// NewLegacyDiscoverer creates a discoverer for the legacy runtime
|
|
||||||
func NewLegacyDiscoverer(logger *logrus.Logger, root string) (Discover, error) {
|
func NewLegacyDiscoverer(logger *logrus.Logger, root string) (Discover, error) {
|
||||||
d := legacy{
|
d := legacy{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
@ -45,13 +32,23 @@ func NewLegacyDiscoverer(logger *logrus.Logger, root string) (Discover, error) {
|
|||||||
return &d, nil
|
return &d, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hooks returns the "legacy" NVIDIA Container Runtime hook. This hook calls out
|
type legacy struct {
|
||||||
// to the nvidia-container-cli to make modifications to the container as defined
|
None
|
||||||
// in libnvidia-container.
|
logger *logrus.Logger
|
||||||
func (d legacy) Hooks() ([]Hook, error) {
|
lookup lookup.Locator
|
||||||
var hooks []Hook
|
}
|
||||||
|
|
||||||
hookPath := hookDefaultFilePath
|
var _ Discover = (*legacy)(nil)
|
||||||
|
|
||||||
|
const (
|
||||||
|
nvidiaContainerRuntimeHookExecutable = "nvidia-container-runtime-hook"
|
||||||
|
nvidiaContainerRuntimeHookDefaultFilePath = "/usr/bin/nvidia-container-runtime-hook"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Hooks returns the "legacy" NVIDIA Container Runtime hook. This mirrors the behaviour of the stable
|
||||||
|
// modifier.
|
||||||
|
func (d legacy) Hooks() ([]Hook, error) {
|
||||||
|
hookPath := nvidiaContainerRuntimeHookDefaultFilePath
|
||||||
targets, err := d.lookup.Locate(nvidiaContainerRuntimeHookExecutable)
|
targets, err := d.lookup.Locate(nvidiaContainerRuntimeHookExecutable)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.logger.Warnf("Failed to locate %v: %v", nvidiaContainerRuntimeHookExecutable, err)
|
d.logger.Warnf("Failed to locate %v: %v", nvidiaContainerRuntimeHookExecutable, err)
|
||||||
@ -64,11 +61,11 @@ func (d legacy) Hooks() ([]Hook, error) {
|
|||||||
d.logger.Debugf("Using NVIDIA Container Runtime Hook path %v", hookPath)
|
d.logger.Debugf("Using NVIDIA Container Runtime Hook path %v", hookPath)
|
||||||
|
|
||||||
args := []string{hookPath, "prestart"}
|
args := []string{hookPath, "prestart"}
|
||||||
legacyHook := Hook{
|
h := Hook{
|
||||||
Lifecycle: cdi.PrestartHook,
|
Lifecycle: cdi.PrestartHook,
|
||||||
Path: hookPath,
|
Path: hookPath,
|
||||||
Args: args,
|
Args: args,
|
||||||
}
|
}
|
||||||
hooks = append(hooks, legacyHook)
|
|
||||||
return hooks, nil
|
return []Hook{h}, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user