mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-25 05:21:33 +00:00
Merge branch 'add-log-level-config' into 'master'
Add log-level config option for nvidia-container-runtime See merge request nvidia/container-toolkit/container-toolkit!130
This commit is contained in:
commit
6d3bcb8723
@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = NewLogger()
|
var logger = NewLogger()
|
||||||
@ -38,6 +39,12 @@ func run(argv []string) (rerr error) {
|
|||||||
logger.CloseFile()
|
logger.CloseFile()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if logLevel, err := logrus.ParseLevel(cfg.NVIDIAContainerRuntimeConfig.LogLevel); err == nil {
|
||||||
|
logger.SetLevel(logLevel)
|
||||||
|
} else {
|
||||||
|
logger.Warnf("Invalid log-level '%v'; using '%v'", cfg.NVIDIAContainerRuntimeConfig.LogLevel, logger.Level.String())
|
||||||
|
}
|
||||||
|
|
||||||
runtime, err := newNVIDIAContainerRuntime(logger.Logger, cfg, argv)
|
runtime, err := newNVIDIAContainerRuntime(logger.Logger, cfg, argv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err)
|
return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err)
|
||||||
|
@ -64,6 +64,7 @@ func TestGetConfig(t *testing.T) {
|
|||||||
DebugFilePath: "/dev/null",
|
DebugFilePath: "/dev/null",
|
||||||
Experimental: false,
|
Experimental: false,
|
||||||
DiscoverMode: "auto",
|
DiscoverMode: "auto",
|
||||||
|
LogLevel: "info",
|
||||||
},
|
},
|
||||||
NVIDIACTKConfig: CTKConfig{
|
NVIDIACTKConfig: CTKConfig{
|
||||||
Path: "nvidia-ctk",
|
Path: "nvidia-ctk",
|
||||||
@ -77,6 +78,7 @@ func TestGetConfig(t *testing.T) {
|
|||||||
"nvidia-container-runtime.debug = \"/foo/bar\"",
|
"nvidia-container-runtime.debug = \"/foo/bar\"",
|
||||||
"nvidia-container-runtime.experimental = true",
|
"nvidia-container-runtime.experimental = true",
|
||||||
"nvidia-container-runtime.discover-mode = \"not-legacy\"",
|
"nvidia-container-runtime.discover-mode = \"not-legacy\"",
|
||||||
|
"nvidia-container-runtime.log-level = \"debug\"",
|
||||||
"nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"",
|
"nvidia-ctk.path = \"/foo/bar/nvidia-ctk\"",
|
||||||
},
|
},
|
||||||
expectedConfig: &Config{
|
expectedConfig: &Config{
|
||||||
@ -87,6 +89,7 @@ func TestGetConfig(t *testing.T) {
|
|||||||
DebugFilePath: "/foo/bar",
|
DebugFilePath: "/foo/bar",
|
||||||
Experimental: true,
|
Experimental: true,
|
||||||
DiscoverMode: "not-legacy",
|
DiscoverMode: "not-legacy",
|
||||||
|
LogLevel: "debug",
|
||||||
},
|
},
|
||||||
NVIDIACTKConfig: CTKConfig{
|
NVIDIACTKConfig: CTKConfig{
|
||||||
Path: "/foo/bar/nvidia-ctk",
|
Path: "/foo/bar/nvidia-ctk",
|
||||||
@ -102,6 +105,7 @@ func TestGetConfig(t *testing.T) {
|
|||||||
"debug = \"/foo/bar\"",
|
"debug = \"/foo/bar\"",
|
||||||
"experimental = true",
|
"experimental = true",
|
||||||
"discover-mode = \"not-legacy\"",
|
"discover-mode = \"not-legacy\"",
|
||||||
|
"log-level = \"debug\"",
|
||||||
"[nvidia-ctk]",
|
"[nvidia-ctk]",
|
||||||
"path = \"/foo/bar/nvidia-ctk\"",
|
"path = \"/foo/bar/nvidia-ctk\"",
|
||||||
},
|
},
|
||||||
@ -113,6 +117,7 @@ func TestGetConfig(t *testing.T) {
|
|||||||
DebugFilePath: "/foo/bar",
|
DebugFilePath: "/foo/bar",
|
||||||
Experimental: true,
|
Experimental: true,
|
||||||
DiscoverMode: "not-legacy",
|
DiscoverMode: "not-legacy",
|
||||||
|
LogLevel: "debug",
|
||||||
},
|
},
|
||||||
NVIDIACTKConfig: CTKConfig{
|
NVIDIACTKConfig: CTKConfig{
|
||||||
Path: "/foo/bar/nvidia-ctk",
|
Path: "/foo/bar/nvidia-ctk",
|
||||||
|
@ -18,6 +18,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RuntimeConfig stores the config options for the NVIDIA Container Runtime
|
// RuntimeConfig stores the config options for the NVIDIA Container Runtime
|
||||||
@ -25,6 +26,8 @@ type RuntimeConfig struct {
|
|||||||
DebugFilePath string
|
DebugFilePath string
|
||||||
Experimental bool
|
Experimental bool
|
||||||
DiscoverMode string
|
DiscoverMode string
|
||||||
|
// LogLevel defines the logging level for the application
|
||||||
|
LogLevel string
|
||||||
}
|
}
|
||||||
|
|
||||||
// getRuntimeConfigFrom reads the nvidia container runtime config from the specified toml Tree.
|
// getRuntimeConfigFrom reads the nvidia container runtime config from the specified toml Tree.
|
||||||
@ -38,6 +41,7 @@ func getRuntimeConfigFrom(toml *toml.Tree) *RuntimeConfig {
|
|||||||
cfg.DebugFilePath = toml.GetDefault("nvidia-container-runtime.debug", cfg.DebugFilePath).(string)
|
cfg.DebugFilePath = toml.GetDefault("nvidia-container-runtime.debug", cfg.DebugFilePath).(string)
|
||||||
cfg.Experimental = toml.GetDefault("nvidia-container-runtime.experimental", cfg.Experimental).(bool)
|
cfg.Experimental = toml.GetDefault("nvidia-container-runtime.experimental", cfg.Experimental).(bool)
|
||||||
cfg.DiscoverMode = toml.GetDefault("nvidia-container-runtime.discover-mode", cfg.DiscoverMode).(string)
|
cfg.DiscoverMode = toml.GetDefault("nvidia-container-runtime.discover-mode", cfg.DiscoverMode).(string)
|
||||||
|
cfg.LogLevel = toml.GetDefault("nvidia-container-runtime.log-level", cfg.LogLevel).(string)
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
}
|
}
|
||||||
@ -48,6 +52,7 @@ func GetDefaultRuntimeConfig() *RuntimeConfig {
|
|||||||
DebugFilePath: "/dev/null",
|
DebugFilePath: "/dev/null",
|
||||||
Experimental: false,
|
Experimental: false,
|
||||||
DiscoverMode: "auto",
|
DiscoverMode: "auto",
|
||||||
|
LogLevel: logrus.InfoLevel.String(),
|
||||||
}
|
}
|
||||||
|
|
||||||
return &c
|
return &c
|
||||||
|
2
third_party/libnvidia-container
vendored
2
third_party/libnvidia-container
vendored
@ -1 +1 @@
|
|||||||
Subproject commit a0c0a43e6a6d8c9cc584d15497230a2ecd0d65c7
|
Subproject commit d999036d0ee2d5a5ec47ede32e3a9d8c4d7b3992
|
Loading…
Reference in New Issue
Block a user