mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Read top-level config to propagate Root to experimental runtime
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
@@ -20,12 +20,12 @@ func main() {
|
||||
// run is an entry point that allows for idiomatic handling of errors
|
||||
// when calling from the main function.
|
||||
func run(argv []string) (rerr error) {
|
||||
cfg, err := config.GetRuntimeConfig()
|
||||
cfg, err := config.GetConfig()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading config: %v", err)
|
||||
}
|
||||
|
||||
err = logger.LogToFile(cfg.DebugFilePath)
|
||||
err = logger.LogToFile(cfg.NVIDIAContainerRuntimeConfig.DebugFilePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening debug log file: %v", err)
|
||||
}
|
||||
|
||||
@@ -36,14 +36,13 @@ type experimental struct {
|
||||
|
||||
// NewExperimentalModifier creates a modifier that applied the experimental
|
||||
// modications to an OCI spec if required by the runtime wrapper.
|
||||
func NewExperimentalModifier(logger *logrus.Logger, cfg *config.RuntimeConfig) (oci.SpecModifier, error) {
|
||||
func NewExperimentalModifier(logger *logrus.Logger, cfg *config.Config) (oci.SpecModifier, error) {
|
||||
logger.Infof("Constructing modifier from config: %+v", cfg)
|
||||
|
||||
// TODO: We need to specify the root
|
||||
root := ""
|
||||
root := cfg.NVIDIAContainerCLIConfig.Root
|
||||
|
||||
var d discover.Discover
|
||||
switch cfg.DiscoverMode {
|
||||
switch cfg.NVIDIAContainerRuntimeConfig.DiscoverMode {
|
||||
case "legacy":
|
||||
legacyDiscoverer, err := discover.NewLegacyDiscoverer(logger, root)
|
||||
if err != nil {
|
||||
@@ -51,7 +50,7 @@ func NewExperimentalModifier(logger *logrus.Logger, cfg *config.RuntimeConfig) (
|
||||
}
|
||||
d = legacyDiscoverer
|
||||
default:
|
||||
return nil, fmt.Errorf("invalid discover mode: %v", cfg.DiscoverMode)
|
||||
return nil, fmt.Errorf("invalid discover mode: %v", cfg.NVIDIAContainerRuntimeConfig.DiscoverMode)
|
||||
}
|
||||
|
||||
return newExperimentalModifierFromDiscoverer(logger, d)
|
||||
|
||||
@@ -32,25 +32,31 @@ func TestConstructor(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
cfg *config.RuntimeConfig
|
||||
cfg *config.Config
|
||||
expectedError error
|
||||
}{
|
||||
{
|
||||
description: "empty config raises error",
|
||||
cfg: &config.RuntimeConfig{},
|
||||
description: "empty config raises error",
|
||||
cfg: &config.Config{
|
||||
NVIDIAContainerRuntimeConfig: config.RuntimeConfig{},
|
||||
},
|
||||
expectedError: fmt.Errorf("invalid discover mode"),
|
||||
},
|
||||
{
|
||||
description: "non-legacy discover mode raises error",
|
||||
cfg: &config.RuntimeConfig{
|
||||
DiscoverMode: "non-legacy",
|
||||
cfg: &config.Config{
|
||||
NVIDIAContainerRuntimeConfig: config.RuntimeConfig{
|
||||
DiscoverMode: "non-legacy",
|
||||
},
|
||||
},
|
||||
expectedError: fmt.Errorf("invalid discover mode"),
|
||||
},
|
||||
{
|
||||
description: "legacy discover mode returns modifier",
|
||||
cfg: &config.RuntimeConfig{
|
||||
DiscoverMode: "legacy",
|
||||
cfg: &config.Config{
|
||||
NVIDIAContainerRuntimeConfig: config.RuntimeConfig{
|
||||
DiscoverMode: "legacy",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const (
|
||||
)
|
||||
|
||||
// newNVIDIAContainerRuntime is a factory method that constructs a runtime based on the selected configuration and specified logger
|
||||
func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.RuntimeConfig, argv []string) (oci.Runtime, error) {
|
||||
func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv []string) (oci.Runtime, error) {
|
||||
ociSpec, err := oci.NewSpec(logger, argv)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error constructing OCI specification: %v", err)
|
||||
@@ -45,7 +45,7 @@ func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.RuntimeConfig,
|
||||
}
|
||||
|
||||
var specModifier oci.SpecModifier
|
||||
if cfg.Experimental {
|
||||
if cfg.NVIDIAContainerRuntimeConfig.Experimental {
|
||||
specModifier, err = modifier.NewExperimentalModifier(logger, cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to construct experimental modifier: %v", err)
|
||||
|
||||
@@ -29,19 +29,21 @@ func TestFactoryMethod(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
description string
|
||||
config config.RuntimeConfig
|
||||
cfg *config.Config
|
||||
argv []string
|
||||
expectedError bool
|
||||
}{
|
||||
{
|
||||
description: "empty config no error",
|
||||
config: config.RuntimeConfig{},
|
||||
cfg: &config.Config{
|
||||
NVIDIAContainerRuntimeConfig: config.RuntimeConfig{},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.description, func(t *testing.T) {
|
||||
_, err := newNVIDIAContainerRuntime(logger, &tc.config, tc.argv)
|
||||
_, err := newNVIDIAContainerRuntime(logger, tc.cfg, tc.argv)
|
||||
if tc.expectedError {
|
||||
require.Error(t, err)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user