mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 13:35:00 +00:00
Remove discover.Config
These changes remove the use of discover.Config which was used to pass the driver root and the nvidiaCTK path in some cases. Instead, the nvidiaCTKPath is resolved at the begining of runtime invocation to ensure that this is valid at all points where it is used. Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
ee47f26d1c
commit
8bb0235c92
@ -16,12 +16,6 @@
|
|||||||
|
|
||||||
package discover
|
package discover
|
||||||
|
|
||||||
// Config represents the configuration options for discovery
|
|
||||||
type Config struct {
|
|
||||||
DriverRoot string
|
|
||||||
NvidiaCTKPath string
|
|
||||||
}
|
|
||||||
|
|
||||||
// Device represents a discovered character device.
|
// Device represents a discovered character device.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
HostPath string
|
HostPath string
|
||||||
|
@ -31,9 +31,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewGraphicsDiscoverer returns the discoverer for graphics tools such as Vulkan.
|
// NewGraphicsDiscoverer returns the discoverer for graphics tools such as Vulkan.
|
||||||
func NewGraphicsDiscoverer(logger *logrus.Logger, devices image.VisibleDevices, cfg *Config) (Discover, error) {
|
func NewGraphicsDiscoverer(logger *logrus.Logger, devices image.VisibleDevices, driverRoot string, nvidiaCTKPath string) (Discover, error) {
|
||||||
driverRoot := cfg.DriverRoot
|
|
||||||
|
|
||||||
mounts, err := NewGraphicsMountsDiscoverer(logger, driverRoot)
|
mounts, err := NewGraphicsMountsDiscoverer(logger, driverRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create mounts discoverer: %v", err)
|
return nil, fmt.Errorf("failed to create mounts discoverer: %v", err)
|
||||||
@ -44,9 +42,9 @@ func NewGraphicsDiscoverer(logger *logrus.Logger, devices image.VisibleDevices,
|
|||||||
return nil, fmt.Errorf("failed to create DRM device discoverer: %v", err)
|
return nil, fmt.Errorf("failed to create DRM device discoverer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
drmByPathSymlinks := newCreateDRMByPathSymlinks(logger, drmDeviceNodes, cfg)
|
drmByPathSymlinks := newCreateDRMByPathSymlinks(logger, drmDeviceNodes, driverRoot, nvidiaCTKPath)
|
||||||
|
|
||||||
xorg := optionalXorgDiscoverer(logger, driverRoot, cfg.NvidiaCTKPath)
|
xorg := optionalXorgDiscoverer(logger, driverRoot, nvidiaCTKPath)
|
||||||
|
|
||||||
discover := Merge(
|
discover := Merge(
|
||||||
Merge(drmDeviceNodes, drmByPathSymlinks),
|
Merge(drmDeviceNodes, drmByPathSymlinks),
|
||||||
@ -106,11 +104,11 @@ type drmDevicesByPath struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newCreateDRMByPathSymlinks creates a discoverer for a hook to create the by-path symlinks for DRM devices discovered by the specified devices discoverer
|
// newCreateDRMByPathSymlinks creates a discoverer for a hook to create the by-path symlinks for DRM devices discovered by the specified devices discoverer
|
||||||
func newCreateDRMByPathSymlinks(logger *logrus.Logger, devices Discover, cfg *Config) Discover {
|
func newCreateDRMByPathSymlinks(logger *logrus.Logger, devices Discover, driverRoot string, nvidiaCTKPath string) Discover {
|
||||||
d := drmDevicesByPath{
|
d := drmDevicesByPath{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaCTKPath: FindNvidiaCTK(logger, cfg.NvidiaCTKPath),
|
nvidiaCTKPath: nvidiaCTKPath,
|
||||||
driverRoot: cfg.DriverRoot,
|
driverRoot: driverRoot,
|
||||||
devicesFrom: devices,
|
devicesFrom: devices,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -300,7 +298,7 @@ func newXorgDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath s
|
|||||||
xorgHooks := xorgHooks{
|
xorgHooks := xorgHooks{
|
||||||
libraries: xorgLibs,
|
libraries: xorgLibs,
|
||||||
driverVersion: version,
|
driverVersion: version,
|
||||||
nvidiaCTKPath: FindNvidiaCTK(logger, nvidiaCTKPath),
|
nvidiaCTKPath: nvidiaCTKPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
xorgConfg := NewMounts(
|
xorgConfg := NewMounts(
|
||||||
|
@ -25,10 +25,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewLDCacheUpdateHook creates a discoverer that updates the ldcache for the specified mounts. A logger can also be specified
|
// NewLDCacheUpdateHook creates a discoverer that updates the ldcache for the specified mounts. A logger can also be specified
|
||||||
func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, cfg *Config) (Discover, error) {
|
func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, nvidiaCTKPath string) (Discover, error) {
|
||||||
d := ldconfig{
|
d := ldconfig{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaCTKPath: FindNvidiaCTK(logger, cfg.NvidiaCTKPath),
|
nvidiaCTKPath: nvidiaCTKPath,
|
||||||
mountsFrom: mounts,
|
mountsFrom: mounts,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,11 +31,6 @@ const (
|
|||||||
func TestLDCacheUpdateHook(t *testing.T) {
|
func TestLDCacheUpdateHook(t *testing.T) {
|
||||||
logger, _ := testlog.NewNullLogger()
|
logger, _ := testlog.NewNullLogger()
|
||||||
|
|
||||||
cfg := Config{
|
|
||||||
DriverRoot: "/",
|
|
||||||
NvidiaCTKPath: testNvidiaCTKPath,
|
|
||||||
}
|
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
mounts []Mount
|
mounts []Mount
|
||||||
@ -95,7 +90,7 @@ func TestLDCacheUpdateHook(t *testing.T) {
|
|||||||
Lifecycle: "createContainer",
|
Lifecycle: "createContainer",
|
||||||
}
|
}
|
||||||
|
|
||||||
d, err := NewLDCacheUpdateHook(logger, mountMock, &cfg)
|
d, err := NewLDCacheUpdateHook(logger, mountMock, testNvidiaCTKPath)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
hooks, err := d.Hooks()
|
hooks, err := d.Hooks()
|
||||||
|
@ -33,10 +33,10 @@ type symlinks struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCreateSymlinksHook creates a discoverer for a hook that creates required symlinks in the container
|
// NewCreateSymlinksHook creates a discoverer for a hook that creates required symlinks in the container
|
||||||
func NewCreateSymlinksHook(logger *logrus.Logger, csvFiles []string, mounts Discover, cfg *Config) (Discover, error) {
|
func NewCreateSymlinksHook(logger *logrus.Logger, csvFiles []string, mounts Discover, nvidiaCTKPath string) (Discover, error) {
|
||||||
d := symlinks{
|
d := symlinks{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaCTKPath: FindNvidiaCTK(logger, cfg.NvidiaCTKPath),
|
nvidiaCTKPath: nvidiaCTKPath,
|
||||||
csvFiles: csvFiles,
|
csvFiles: csvFiles,
|
||||||
mountsFrom: mounts,
|
mountsFrom: mounts,
|
||||||
}
|
}
|
||||||
|
@ -61,11 +61,6 @@ func NewCSVModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec)
|
|||||||
}
|
}
|
||||||
logger.Infof("Constructing modifier from config: %+v", *cfg)
|
logger.Infof("Constructing modifier from config: %+v", *cfg)
|
||||||
|
|
||||||
config := &discover.Config{
|
|
||||||
DriverRoot: cfg.NVIDIAContainerCLIConfig.Root,
|
|
||||||
NvidiaCTKPath: cfg.NVIDIACTKConfig.Path,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := checkRequirements(logger, image); err != nil {
|
if err := checkRequirements(logger, image); err != nil {
|
||||||
return nil, fmt.Errorf("requirements not met: %v", err)
|
return nil, fmt.Errorf("requirements not met: %v", err)
|
||||||
}
|
}
|
||||||
@ -79,17 +74,17 @@ func NewCSVModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec)
|
|||||||
csvFiles = csv.BaseFilesOnly(csvFiles)
|
csvFiles = csv.BaseFilesOnly(csvFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
csvDiscoverer, err := discover.NewFromCSVFiles(logger, csvFiles, config.DriverRoot)
|
csvDiscoverer, err := discover.NewFromCSVFiles(logger, csvFiles, cfg.NVIDIAContainerCLIConfig.Root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create CSV discoverer: %v", err)
|
return nil, fmt.Errorf("failed to create CSV discoverer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
createSymlinksHook, err := discover.NewCreateSymlinksHook(logger, csvFiles, csvDiscoverer, config)
|
createSymlinksHook, err := discover.NewCreateSymlinksHook(logger, csvFiles, csvDiscoverer, cfg.NVIDIACTKConfig.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create symlink hook discoverer: %v", err)
|
return nil, fmt.Errorf("failed to create symlink hook discoverer: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ldcacheUpdateHook, err := discover.NewLDCacheUpdateHook(logger, csvDiscoverer, config)
|
ldcacheUpdateHook, err := discover.NewLDCacheUpdateHook(logger, csvDiscoverer, cfg.NVIDIACTKConfig.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create ldcach update hook discoverer: %v", err)
|
return nil, fmt.Errorf("failed to create ldcach update hook discoverer: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -44,14 +44,11 @@ func NewGraphicsModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &discover.Config{
|
|
||||||
DriverRoot: cfg.NVIDIAContainerCLIConfig.Root,
|
|
||||||
NvidiaCTKPath: cfg.NVIDIACTKConfig.Path,
|
|
||||||
}
|
|
||||||
d, err := discover.NewGraphicsDiscoverer(
|
d, err := discover.NewGraphicsDiscoverer(
|
||||||
logger,
|
logger,
|
||||||
image.DevicesFromEnvvars(visibleDevicesEnvvar),
|
image.DevicesFromEnvvars(visibleDevicesEnvvar),
|
||||||
config,
|
cfg.NVIDIAContainerCLIConfig.Root,
|
||||||
|
cfg.NVIDIACTKConfig.Path,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to construct discoverer: %v", err)
|
return nil, fmt.Errorf("failed to construct discoverer: %v", err)
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
@ -44,10 +45,6 @@ func (r rt) Run(argv []string) (rerr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error loading config: %v", err)
|
return fmt.Errorf("error loading config: %v", err)
|
||||||
}
|
}
|
||||||
if r.modeOverride != "" {
|
|
||||||
cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.logger.Update(
|
err = r.logger.Update(
|
||||||
cfg.NVIDIAContainerRuntimeConfig.DebugFilePath,
|
cfg.NVIDIAContainerRuntimeConfig.DebugFilePath,
|
||||||
cfg.NVIDIAContainerRuntimeConfig.LogLevel,
|
cfg.NVIDIAContainerRuntimeConfig.LogLevel,
|
||||||
@ -63,6 +60,13 @@ func (r rt) Run(argv []string) (rerr error) {
|
|||||||
r.logger.Reset()
|
r.logger.Reset()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// We apply some config updates here to ensure that the config is valid in
|
||||||
|
// all cases.
|
||||||
|
if r.modeOverride != "" {
|
||||||
|
cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride
|
||||||
|
}
|
||||||
|
cfg.NVIDIACTKConfig.Path = discover.FindNvidiaCTK(r.logger.Logger, cfg.NVIDIACTKConfig.Path)
|
||||||
|
|
||||||
// Print the config to the output.
|
// Print the config to the output.
|
||||||
configJSON, err := json.MarshalIndent(cfg, "", " ")
|
configJSON, err := json.MarshalIndent(cfg, "", " ")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -86,11 +86,7 @@ func NewDriverLibraryDiscoverer(logger *logrus.Logger, driverRoot string, nvidia
|
|||||||
libraryPaths,
|
libraryPaths,
|
||||||
)
|
)
|
||||||
|
|
||||||
cfg := &discover.Config{
|
hooks, _ := discover.NewLDCacheUpdateHook(logger, libraries, nvidiaCTKPath)
|
||||||
DriverRoot: driverRoot,
|
|
||||||
NvidiaCTKPath: nvidiaCTKPath,
|
|
||||||
}
|
|
||||||
hooks, _ := discover.NewLDCacheUpdateHook(logger, libraries, cfg)
|
|
||||||
|
|
||||||
d := discover.Merge(
|
d := discover.Merge(
|
||||||
libraries,
|
libraries,
|
||||||
|
@ -90,11 +90,7 @@ func newWSLDriverStoreDiscoverer(logger *logrus.Logger, driverRoot string, nvidi
|
|||||||
links := []string{fmt.Sprintf("%s::%s", target, link)}
|
links := []string{fmt.Sprintf("%s::%s", target, link)}
|
||||||
symlinkHook := discover.CreateCreateSymlinkHook(nvidiaCTKPath, links)
|
symlinkHook := discover.CreateCreateSymlinkHook(nvidiaCTKPath, links)
|
||||||
|
|
||||||
cfg := &discover.Config{
|
ldcacheHook, _ := discover.NewLDCacheUpdateHook(logger, libraries, nvidiaCTKPath)
|
||||||
DriverRoot: driverRoot,
|
|
||||||
NvidiaCTKPath: nvidiaCTKPath,
|
|
||||||
}
|
|
||||||
ldcacheHook, _ := discover.NewLDCacheUpdateHook(logger, libraries, cfg)
|
|
||||||
|
|
||||||
d := discover.Merge(
|
d := discover.Merge(
|
||||||
libraries,
|
libraries,
|
||||||
|
Loading…
Reference in New Issue
Block a user