mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2024-11-22 08:18:32 +00:00
Merge branch 'treat-log-errors-as-non-fatal' into 'main'
Ignore errors when creating debug log file See merge request nvidia/container-toolkit/container-toolkit!404
This commit is contained in:
parent
b776bf712e
commit
36d1b7d2a5
@ -6,6 +6,7 @@
|
|||||||
* Fix bug in creation of `/dev/char` symlinks by failing operation if kernel modules are not loaded.
|
* Fix bug in creation of `/dev/char` symlinks by failing operation if kernel modules are not loaded.
|
||||||
* Add option to load kernel modules when creating device nodes
|
* Add option to load kernel modules when creating device nodes
|
||||||
* Add option to create device nodes when creating `/dev/char` symlinks
|
* Add option to create device nodes when creating `/dev/char` symlinks
|
||||||
|
* Treat failures to open debug log files as non-fatal.
|
||||||
|
|
||||||
## v1.13.1
|
## v1.13.1
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package runtime
|
package runtime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -43,7 +44,7 @@ func NewLogger() *Logger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update constructs a Logger with a preddefined formatter
|
// Update constructs a Logger with a preddefined formatter
|
||||||
func (l *Logger) Update(filename string, logLevel string, argv []string) error {
|
func (l *Logger) Update(filename string, logLevel string, argv []string) {
|
||||||
|
|
||||||
configFromArgs := parseArgs(argv)
|
configFromArgs := parseArgs(argv)
|
||||||
|
|
||||||
@ -61,7 +62,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) error {
|
|||||||
if !configFromArgs.version {
|
if !configFromArgs.version {
|
||||||
configLogFile, err := createLogFile(filename)
|
configLogFile, err := createLogFile(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error opening debug log file: %v", err)
|
argLogFileError = errors.Join(argLogFileError, err)
|
||||||
}
|
}
|
||||||
if configLogFile != nil {
|
if configLogFile != nil {
|
||||||
logFiles = append(logFiles, configLogFile)
|
logFiles = append(logFiles, configLogFile)
|
||||||
@ -71,7 +72,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) error {
|
|||||||
if argLogFile != nil {
|
if argLogFile != nil {
|
||||||
logFiles = append(logFiles, argLogFile)
|
logFiles = append(logFiles, argLogFile)
|
||||||
}
|
}
|
||||||
argLogFileError = err
|
argLogFileError = errors.Join(argLogFileError, err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if argLogFileError != nil {
|
if argLogFileError != nil {
|
||||||
@ -119,8 +120,6 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) error {
|
|||||||
previousLogger: l.Logger,
|
previousLogger: l.Logger,
|
||||||
logFiles: logFiles,
|
logFiles: logFiles,
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset closes the log file (if any) and resets the logger output to what it
|
// Reset closes the log file (if any) and resets the logger output to what it
|
||||||
@ -157,11 +156,16 @@ func (l *Logger) Reset() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createLogFile(filename string) (*os.File, error) {
|
func createLogFile(filename string) (*os.File, error) {
|
||||||
if filename != "" && filename != os.DevNull {
|
if filename == "" || filename == os.DevNull {
|
||||||
return os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
if dir := filepath.Dir(filepath.Clean(filename)); dir != "." {
|
||||||
return nil, nil
|
err := os.MkdirAll(dir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
type loggerConfig struct {
|
type loggerConfig struct {
|
||||||
|
@ -44,18 +44,11 @@ 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 != "" {
|
r.logger.Update(
|
||||||
cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride
|
|
||||||
}
|
|
||||||
|
|
||||||
err = r.logger.Update(
|
|
||||||
cfg.NVIDIAContainerRuntimeConfig.DebugFilePath,
|
cfg.NVIDIAContainerRuntimeConfig.DebugFilePath,
|
||||||
cfg.NVIDIAContainerRuntimeConfig.LogLevel,
|
cfg.NVIDIAContainerRuntimeConfig.LogLevel,
|
||||||
argv,
|
argv,
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to set up logger: %v", err)
|
|
||||||
}
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
r.logger.Errorf("%v", rerr)
|
r.logger.Errorf("%v", rerr)
|
||||||
@ -65,6 +58,9 @@ func (r rt) Run(argv []string) (rerr error) {
|
|||||||
|
|
||||||
// We apply some config updates here to ensure that the config is valid in
|
// We apply some config updates here to ensure that the config is valid in
|
||||||
// all cases.
|
// all cases.
|
||||||
|
if r.modeOverride != "" {
|
||||||
|
cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride
|
||||||
|
}
|
||||||
cfg.NVIDIAContainerRuntimeHookConfig.Path = config.ResolveNVIDIAContainerRuntimeHookPath(r.logger.Logger, cfg.NVIDIAContainerRuntimeHookConfig.Path)
|
cfg.NVIDIAContainerRuntimeHookConfig.Path = config.ResolveNVIDIAContainerRuntimeHookPath(r.logger.Logger, cfg.NVIDIAContainerRuntimeHookConfig.Path)
|
||||||
|
|
||||||
// Print the config to the output.
|
// Print the config to the output.
|
||||||
|
Loading…
Reference in New Issue
Block a user