mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Merge pull request #763 from elezar/allow-config-override-by-envvar
Add support for specifying the config file path in an environment variable
This commit is contained in:
commit
d1286bceed
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -14,11 +13,6 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
configPath = "/etc/nvidia-container-runtime/config.toml"
|
|
||||||
driverPath = "/run/nvidia/driver"
|
|
||||||
)
|
|
||||||
|
|
||||||
// hookConfig wraps the toolkit config.
|
// hookConfig wraps the toolkit config.
|
||||||
// This allows for functions to be defined on the local type.
|
// This allows for functions to be defined on the local type.
|
||||||
type hookConfig struct {
|
type hookConfig struct {
|
||||||
@ -29,29 +23,27 @@ type hookConfig struct {
|
|||||||
|
|
||||||
// loadConfig loads the required paths for the hook config.
|
// loadConfig loads the required paths for the hook config.
|
||||||
func loadConfig() (*config.Config, error) {
|
func loadConfig() (*config.Config, error) {
|
||||||
var configPaths []string
|
configFilePath, required := getConfigFilePath()
|
||||||
var required bool
|
cfg, err := config.New(
|
||||||
if len(*configflag) != 0 {
|
config.WithConfigFile(configFilePath),
|
||||||
configPaths = append(configPaths, *configflag)
|
config.WithRequired(true),
|
||||||
required = true
|
)
|
||||||
} else {
|
if err == nil {
|
||||||
configPaths = append(configPaths, path.Join(driverPath, configPath), configPath)
|
return cfg.Config()
|
||||||
|
} else if os.IsNotExist(err) && !required {
|
||||||
|
return config.GetDefault()
|
||||||
}
|
}
|
||||||
|
return nil, fmt.Errorf("couldn't open required configuration file: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range configPaths {
|
func getConfigFilePath() (string, bool) {
|
||||||
cfg, err := config.New(
|
if configFromFlag := *configflag; configFromFlag != "" {
|
||||||
config.WithConfigFile(p),
|
return configFromFlag, true
|
||||||
config.WithRequired(true),
|
|
||||||
)
|
|
||||||
if err == nil {
|
|
||||||
return cfg.Config()
|
|
||||||
} else if os.IsNotExist(err) && !required {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("couldn't open required configuration file: %v", err)
|
|
||||||
}
|
}
|
||||||
|
if configFromEnvvar := os.Getenv(config.FilePathOverrideEnvVar); configFromEnvvar != "" {
|
||||||
return config.GetDefault()
|
return configFromEnvvar, true
|
||||||
|
}
|
||||||
|
return config.GetConfigFilePath(), false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHookConfig() (*hookConfig, error) {
|
func getHookConfig() (*hookConfig, error) {
|
||||||
|
@ -28,7 +28,7 @@ type createDirectory struct {
|
|||||||
logger logger.Interface
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolkitInstaller) createDirectory() Installer {
|
func (t *ToolkitInstaller) createDirectory() Installer {
|
||||||
return &createDirectory{
|
return &createDirectory{
|
||||||
logger: t.logger,
|
logger: t.logger,
|
||||||
}
|
}
|
||||||
|
@ -28,20 +28,18 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/operator"
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk-installer/container/operator"
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
type executable struct {
|
type executable struct {
|
||||||
requiresKernelModule bool
|
requiresKernelModule bool
|
||||||
path string
|
path string
|
||||||
symlink string
|
symlink string
|
||||||
args []string
|
|
||||||
env map[string]string
|
env map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, error) {
|
func (t *ToolkitInstaller) collectExecutables(destDir string) ([]Installer, error) {
|
||||||
configHome := filepath.Join(destDir, ".config")
|
configFilePath := t.ConfigFilePath(destDir)
|
||||||
configDir := filepath.Join(configHome, "nvidia-container-runtime")
|
|
||||||
configPath := filepath.Join(configDir, "config.toml")
|
|
||||||
|
|
||||||
executables := []executable{
|
executables := []executable{
|
||||||
{
|
{
|
||||||
@ -56,7 +54,7 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
|
|||||||
path: runtime.Path,
|
path: runtime.Path,
|
||||||
requiresKernelModule: true,
|
requiresKernelModule: true,
|
||||||
env: map[string]string{
|
env: map[string]string{
|
||||||
"XDG_CONFIG_HOME": configHome,
|
config.FilePathOverrideEnvVar: configFilePath,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
executables = append(executables, e)
|
executables = append(executables, e)
|
||||||
@ -72,7 +70,9 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
|
|||||||
executable{
|
executable{
|
||||||
path: "nvidia-container-runtime-hook",
|
path: "nvidia-container-runtime-hook",
|
||||||
symlink: "nvidia-container-toolkit",
|
symlink: "nvidia-container-toolkit",
|
||||||
args: []string{fmt.Sprintf("-config %s", configPath)},
|
env: map[string]string{
|
||||||
|
config.FilePathOverrideEnvVar: configFilePath,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -94,7 +94,6 @@ func (t *toolkitInstaller) collectExecutables(destDir string) ([]Installer, erro
|
|||||||
Source: executablePath,
|
Source: executablePath,
|
||||||
WrappedExecutable: dotRealFilename,
|
WrappedExecutable: dotRealFilename,
|
||||||
CheckModules: executable.requiresKernelModule,
|
CheckModules: executable.requiresKernelModule,
|
||||||
Args: executable.args,
|
|
||||||
Envvars: map[string]string{
|
Envvars: map[string]string{
|
||||||
"PATH": strings.Join([]string{destDir, "$PATH"}, ":"),
|
"PATH": strings.Join([]string{destDir, "$PATH"}, ":"),
|
||||||
},
|
},
|
||||||
@ -124,7 +123,6 @@ type wrapper struct {
|
|||||||
Envvars map[string]string
|
Envvars map[string]string
|
||||||
WrappedExecutable string
|
WrappedExecutable string
|
||||||
CheckModules bool
|
CheckModules bool
|
||||||
Args []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type render struct {
|
type render struct {
|
||||||
@ -165,9 +163,6 @@ fi
|
|||||||
{{$key}}={{$value}} \
|
{{$key}}={{$value}} \
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{ .DestDir }}/{{ .WrappedExecutable }} \
|
{{ .DestDir }}/{{ .WrappedExecutable }} \
|
||||||
{{- range $arg := .Args }}
|
|
||||||
{{$arg}} \
|
|
||||||
{{- end }}
|
|
||||||
"$@"
|
"$@"
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -68,19 +68,6 @@ fi
|
|||||||
PATH=/foo/bar/baz \
|
PATH=/foo/bar/baz \
|
||||||
/dest-dir/some-runtime \
|
/dest-dir/some-runtime \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
description: "args are added",
|
|
||||||
w: &wrapper{
|
|
||||||
WrappedExecutable: "some-runtime",
|
|
||||||
Args: []string{"--config foo", "bar"},
|
|
||||||
},
|
|
||||||
expected: `#! /bin/sh
|
|
||||||
/dest-dir/some-runtime \
|
|
||||||
--config foo \
|
|
||||||
bar \
|
|
||||||
"$@"
|
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ type Installer interface {
|
|||||||
Install(string) error
|
Install(string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type toolkitInstaller struct {
|
type ToolkitInstaller struct {
|
||||||
logger logger.Interface
|
logger logger.Interface
|
||||||
ignoreErrors bool
|
ignoreErrors bool
|
||||||
sourceRoot string
|
sourceRoot string
|
||||||
@ -43,11 +43,11 @@ type toolkitInstaller struct {
|
|||||||
ensureTargetDirectory Installer
|
ensureTargetDirectory Installer
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Installer = (*toolkitInstaller)(nil)
|
var _ Installer = (*ToolkitInstaller)(nil)
|
||||||
|
|
||||||
// New creates a toolkit installer with the specified options.
|
// New creates a toolkit installer with the specified options.
|
||||||
func New(opts ...Option) (Installer, error) {
|
func New(opts ...Option) (*ToolkitInstaller, error) {
|
||||||
t := &toolkitInstaller{
|
t := &ToolkitInstaller{
|
||||||
sourceRoot: "/",
|
sourceRoot: "/",
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
@ -73,7 +73,7 @@ func New(opts ...Option) (Installer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Install ensures that the required toolkit files are installed in the specified directory.
|
// Install ensures that the required toolkit files are installed in the specified directory.
|
||||||
func (t *toolkitInstaller) Install(destDir string) error {
|
func (t *ToolkitInstaller) Install(destDir string) error {
|
||||||
var installers []Installer
|
var installers []Installer
|
||||||
|
|
||||||
installers = append(installers, t.ensureTargetDirectory)
|
installers = append(installers, t.ensureTargetDirectory)
|
||||||
@ -98,6 +98,11 @@ func (t *toolkitInstaller) Install(destDir string) error {
|
|||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *ToolkitInstaller) ConfigFilePath(destDir string) string {
|
||||||
|
toolkitConfigDir := filepath.Join(destDir, ".config", "nvidia-container-runtime")
|
||||||
|
return filepath.Join(toolkitConfigDir, "config.toml")
|
||||||
|
}
|
||||||
|
|
||||||
type symlink struct {
|
type symlink struct {
|
||||||
linkname string
|
linkname string
|
||||||
target string
|
target string
|
||||||
|
@ -112,7 +112,7 @@ func TestToolkitInstaller(t *testing.T) {
|
|||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
i := toolkitInstaller{
|
i := ToolkitInstaller{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
artifactRoot: r,
|
artifactRoot: r,
|
||||||
ensureTargetDirectory: createDirectory,
|
ensureTargetDirectory: createDirectory,
|
||||||
@ -172,8 +172,8 @@ if [ "${?}" != "0" ]; then
|
|||||||
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
||||||
exec runc "$@"
|
exec runc "$@"
|
||||||
fi
|
fi
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
XDG_CONFIG_HOME=/foo/bar/baz/.config \
|
|
||||||
/foo/bar/baz/nvidia-container-runtime.real \
|
/foo/bar/baz/nvidia-container-runtime.real \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
@ -187,8 +187,8 @@ if [ "${?}" != "0" ]; then
|
|||||||
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
||||||
exec runc "$@"
|
exec runc "$@"
|
||||||
fi
|
fi
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
XDG_CONFIG_HOME=/foo/bar/baz/.config \
|
|
||||||
/foo/bar/baz/nvidia-container-runtime.cdi.real \
|
/foo/bar/baz/nvidia-container-runtime.cdi.real \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
@ -202,8 +202,8 @@ if [ "${?}" != "0" ]; then
|
|||||||
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
echo "nvidia driver modules are not yet loaded, invoking runc directly"
|
||||||
exec runc "$@"
|
exec runc "$@"
|
||||||
fi
|
fi
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
XDG_CONFIG_HOME=/foo/bar/baz/.config \
|
|
||||||
/foo/bar/baz/nvidia-container-runtime.legacy.real \
|
/foo/bar/baz/nvidia-container-runtime.legacy.real \
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
@ -240,9 +240,9 @@ PATH=/foo/bar/baz:$PATH \
|
|||||||
path: "/foo/bar/baz/nvidia-container-runtime-hook",
|
path: "/foo/bar/baz/nvidia-container-runtime-hook",
|
||||||
mode: 0777,
|
mode: 0777,
|
||||||
wrapper: `#! /bin/sh
|
wrapper: `#! /bin/sh
|
||||||
|
NVIDIA_CTK_CONFIG_FILE_PATH=/foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
||||||
PATH=/foo/bar/baz:$PATH \
|
PATH=/foo/bar/baz:$PATH \
|
||||||
/foo/bar/baz/nvidia-container-runtime-hook.real \
|
/foo/bar/baz/nvidia-container-runtime-hook.real \
|
||||||
-config /foo/bar/baz/.config/nvidia-container-runtime/config.toml \
|
|
||||||
"$@"
|
"$@"
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
// A predefined set of library candidates are considered, with the first one
|
// A predefined set of library candidates are considered, with the first one
|
||||||
// resulting in success being installed to the toolkit folder. The install process
|
// resulting in success being installed to the toolkit folder. The install process
|
||||||
// resolves the symlink for the library and copies the versioned library itself.
|
// resolves the symlink for the library and copies the versioned library itself.
|
||||||
func (t *toolkitInstaller) collectLibraries() ([]Installer, error) {
|
func (t *ToolkitInstaller) collectLibraries() ([]Installer, error) {
|
||||||
requiredLibraries := []string{
|
requiredLibraries := []string{
|
||||||
"libnvidia-container.so.1",
|
"libnvidia-container.so.1",
|
||||||
"libnvidia-container-go.so.1",
|
"libnvidia-container-go.so.1",
|
||||||
|
@ -19,29 +19,29 @@ package installer
|
|||||||
|
|
||||||
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
|
|
||||||
type Option func(*toolkitInstaller)
|
type Option func(*ToolkitInstaller)
|
||||||
|
|
||||||
func WithLogger(logger logger.Interface) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.logger = logger
|
ti.logger = logger
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithArtifactRoot(artifactRoot *artifactRoot) Option {
|
func WithArtifactRoot(artifactRoot *artifactRoot) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.artifactRoot = artifactRoot
|
ti.artifactRoot = artifactRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithIgnoreErrors(ignoreErrors bool) Option {
|
func WithIgnoreErrors(ignoreErrors bool) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.ignoreErrors = ignoreErrors
|
ti.ignoreErrors = ignoreErrors
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithSourceRoot sets the root directory for locating artifacts to be installed.
|
// WithSourceRoot sets the root directory for locating artifacts to be installed.
|
||||||
func WithSourceRoot(sourceRoot string) Option {
|
func WithSourceRoot(sourceRoot string) Option {
|
||||||
return func(ti *toolkitInstaller) {
|
return func(ti *ToolkitInstaller) {
|
||||||
ti.sourceRoot = sourceRoot
|
ti.sourceRoot = sourceRoot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
// DefaultNvidiaDriverRoot specifies the default NVIDIA driver run directory
|
// DefaultNvidiaDriverRoot specifies the default NVIDIA driver run directory
|
||||||
DefaultNvidiaDriverRoot = "/run/nvidia/driver"
|
DefaultNvidiaDriverRoot = "/run/nvidia/driver"
|
||||||
|
|
||||||
configFilename = "config.toml"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cdiOptions struct {
|
type cdiOptions struct {
|
||||||
@ -316,7 +314,7 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
|
|||||||
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("could not install toolkit components: %w", err))
|
t.logger.Errorf("Ignoring error: %v", fmt.Errorf("could not install toolkit components: %w", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
err = t.installToolkitConfig(cli, opts)
|
err = t.installToolkitConfig(cli, opts, toolkit.ConfigFilePath(t.toolkitRoot))
|
||||||
if err != nil && !opts.ignoreErrors {
|
if err != nil && !opts.ignoreErrors {
|
||||||
return fmt.Errorf("error installing NVIDIA container toolkit config: %v", err)
|
return fmt.Errorf("error installing NVIDIA container toolkit config: %v", err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
@ -343,13 +341,11 @@ func (t *Installer) Install(cli *cli.Context, opts *Options) error {
|
|||||||
|
|
||||||
// installToolkitConfig installs the config file for the NVIDIA container toolkit ensuring
|
// installToolkitConfig installs the config file for the NVIDIA container toolkit ensuring
|
||||||
// that the settings are updated to match the desired install and nvidia driver directories.
|
// that the settings are updated to match the desired install and nvidia driver directories.
|
||||||
func (t *Installer) installToolkitConfig(c *cli.Context, opts *Options) error {
|
func (t *Installer) installToolkitConfig(c *cli.Context, opts *Options, toolkitConfigPath string) error {
|
||||||
toolkitConfigDir := filepath.Join(t.toolkitRoot, ".config", "nvidia-container-runtime")
|
|
||||||
toolkitConfigPath := filepath.Join(toolkitConfigDir, configFilename)
|
|
||||||
|
|
||||||
t.logger.Infof("Installing NVIDIA container toolkit config '%v'", toolkitConfigPath)
|
t.logger.Infof("Installing NVIDIA container toolkit config '%v'", toolkitConfigPath)
|
||||||
|
|
||||||
err := t.createDirectories(toolkitConfigDir)
|
err := t.createDirectories(filepath.Dir(toolkitConfigPath))
|
||||||
if err != nil && !opts.ignoreErrors {
|
if err != nil && !opts.ignoreErrors {
|
||||||
return fmt.Errorf("could not create required directories: %v", err)
|
return fmt.Errorf("could not create required directories: %v", err)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
@ -31,8 +31,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
configOverride = "XDG_CONFIG_HOME"
|
FilePathOverrideEnvVar = "NVIDIA_CTK_CONFIG_FILE_PATH"
|
||||||
configFilePath = "nvidia-container-runtime/config.toml"
|
RelativeFilePath = "nvidia-container-runtime/config.toml"
|
||||||
|
|
||||||
|
configRootOverride = "XDG_CONFIG_HOME"
|
||||||
|
|
||||||
nvidiaCTKExecutable = "nvidia-ctk"
|
nvidiaCTKExecutable = "nvidia-ctk"
|
||||||
nvidiaCTKDefaultFilePath = "/usr/bin/nvidia-ctk"
|
nvidiaCTKDefaultFilePath = "/usr/bin/nvidia-ctk"
|
||||||
@ -74,11 +76,15 @@ type Config struct {
|
|||||||
|
|
||||||
// GetConfigFilePath returns the path to the config file for the configured system
|
// GetConfigFilePath returns the path to the config file for the configured system
|
||||||
func GetConfigFilePath() string {
|
func GetConfigFilePath() string {
|
||||||
if XDGConfigDir := os.Getenv(configOverride); len(XDGConfigDir) != 0 {
|
if configFilePathOverride := os.Getenv(FilePathOverrideEnvVar); configFilePathOverride != "" {
|
||||||
return filepath.Join(XDGConfigDir, configFilePath)
|
return configFilePathOverride
|
||||||
|
}
|
||||||
|
configRoot := "/etc"
|
||||||
|
if XDGConfigDir := os.Getenv(configRootOverride); len(XDGConfigDir) != 0 {
|
||||||
|
configRoot = XDGConfigDir
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Join("/etc", configFilePath)
|
return filepath.Join(configRoot, RelativeFilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetConfig sets up the config struct. Values are read from a toml file
|
// GetConfig sets up the config struct. Values are read from a toml file
|
||||||
|
@ -27,9 +27,26 @@ import (
|
|||||||
|
|
||||||
func TestGetConfigWithCustomConfig(t *testing.T) {
|
func TestGetConfigWithCustomConfig(t *testing.T) {
|
||||||
testDir := t.TempDir()
|
testDir := t.TempDir()
|
||||||
t.Setenv(configOverride, testDir)
|
t.Setenv(configRootOverride, testDir)
|
||||||
|
|
||||||
filename := filepath.Join(testDir, configFilePath)
|
filename := filepath.Join(testDir, RelativeFilePath)
|
||||||
|
|
||||||
|
// By default debug is disabled
|
||||||
|
contents := []byte("[nvidia-container-runtime]\ndebug = \"/nvidia-container-toolkit.log\"")
|
||||||
|
|
||||||
|
require.NoError(t, os.MkdirAll(filepath.Dir(filename), 0766))
|
||||||
|
require.NoError(t, os.WriteFile(filename, contents, 0600))
|
||||||
|
|
||||||
|
cfg, err := GetConfig()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "/nvidia-container-toolkit.log", cfg.NVIDIAContainerRuntimeConfig.DebugFilePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetConfigWithConfigFilePathOverride(t *testing.T) {
|
||||||
|
testDir := t.TempDir()
|
||||||
|
filename := filepath.Join(testDir, RelativeFilePath)
|
||||||
|
|
||||||
|
t.Setenv(FilePathOverrideEnvVar, filename)
|
||||||
|
|
||||||
// By default debug is disabled
|
// By default debug is disabled
|
||||||
contents := []byte("[nvidia-container-runtime]\ndebug = \"/nvidia-container-toolkit.log\"")
|
contents := []byte("[nvidia-container-runtime]\ndebug = \"/nvidia-container-toolkit.log\"")
|
||||||
|
Loading…
Reference in New Issue
Block a user