Replace logger.Warn(f) with logger.Warning(f)

This aligns better with klog used in other projects.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-06-06 21:46:38 +02:00
parent 9464953924
commit 1d0a733487
20 changed files with 39 additions and 43 deletions

View File

@ -117,7 +117,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
} }
targets, err := chainLocator.Locate(ms.Path) targets, err := chainLocator.Locate(ms.Path)
if err != nil { if err != nil {
m.logger.Warnf("Failed to locate symlink %v", ms.Path) m.logger.Warningf("Failed to locate symlink %v", ms.Path)
} }
candidates = append(candidates, targets...) candidates = append(candidates, targets...)
} }
@ -137,7 +137,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
err = m.createLink(created, cfg.hostRoot, containerRoot, target, candidate) err = m.createLink(created, cfg.hostRoot, containerRoot, target, candidate)
if err != nil { if err != nil {
m.logger.Warnf("Failed to create link %v: %v", []string{target, candidate}, err) m.logger.Warningf("Failed to create link %v: %v", []string{target, candidate}, err)
} }
} }
@ -145,13 +145,13 @@ func (m command) run(c *cli.Context, cfg *config) error {
for _, l := range links { for _, l := range links {
parts := strings.Split(l, "::") parts := strings.Split(l, "::")
if len(parts) != 2 { if len(parts) != 2 {
m.logger.Warnf("Invalid link specification %v", l) m.logger.Warningf("Invalid link specification %v", l)
continue continue
} }
err := m.createLink(created, cfg.hostRoot, containerRoot, parts[0], parts[1]) err := m.createLink(created, cfg.hostRoot, containerRoot, parts[0], parts[1])
if err != nil { if err != nil {
m.logger.Warnf("Failed to create link %v: %v", parts, err) m.logger.Warningf("Failed to create link %v: %v", parts, err)
} }
} }
@ -162,7 +162,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
func (m command) createLink(created map[string]bool, hostRoot string, containerRoot string, target string, link string) error { func (m command) createLink(created map[string]bool, hostRoot string, containerRoot string, target string, link string) error {
linkPath, err := changeRoot(hostRoot, containerRoot, link) linkPath, err := changeRoot(hostRoot, containerRoot, link)
if err != nil { if err != nil {
m.logger.Warnf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err) m.logger.Warningf("Failed to resolve path for link %v relative to %v: %v", link, containerRoot, err)
} }
if created[linkPath] { if created[linkPath] {
m.logger.Debugf("Link %v already created", linkPath) m.logger.Debugf("Link %v already created", linkPath)
@ -171,7 +171,7 @@ func (m command) createLink(created map[string]bool, hostRoot string, containerR
targetPath, err := changeRoot(hostRoot, "/", target) targetPath, err := changeRoot(hostRoot, "/", target)
if err != nil { if err != nil {
m.logger.Warnf("Failed to resolve path for target %v relative to %v: %v", target, "/", err) m.logger.Warningf("Failed to resolve path for target %v relative to %v: %v", target, "/", err)
} }
m.logger.Infof("Symlinking %v to %v", linkPath, targetPath) m.logger.Infof("Symlinking %v to %v", linkPath, targetPath)

View File

@ -130,12 +130,12 @@ func (m command) validateFlags(r *cli.Context, cfg *config) error {
} }
if cfg.loadKernelModules && !cfg.createAll { if cfg.loadKernelModules && !cfg.createAll {
m.logger.Warn("load-kernel-modules is only applicable when create-all is set; ignoring") m.logger.Warning("load-kernel-modules is only applicable when create-all is set; ignoring")
cfg.loadKernelModules = false cfg.loadKernelModules = false
} }
if cfg.createDeviceNodes && !cfg.createAll { if cfg.createDeviceNodes && !cfg.createAll {
m.logger.Warn("create-device-nodes is only applicable when create-all is set; ignoring") m.logger.Warning("create-device-nodes is only applicable when create-all is set; ignoring")
cfg.createDeviceNodes = false cfg.createDeviceNodes = false
} }
@ -365,7 +365,7 @@ func (m linkCreator) CreateLinks() error {
err = os.Symlink(target, linkPath) err = os.Symlink(target, linkPath)
if err != nil { if err != nil {
m.logger.Warnf("Could not create symlink: %v", err) m.logger.Warningf("Could not create symlink: %v", err)
} }
} }

View File

@ -45,12 +45,12 @@ func (m existing) DeviceNodes() ([]deviceNode, error) {
devices, err := locator.Locate("/dev/nvidia*") devices, err := locator.Locate("/dev/nvidia*")
if err != nil { if err != nil {
m.logger.Warnf("Error while locating device: %v", err) m.logger.Warningf("Error while locating device: %v", err)
} }
capDevices, err := locator.Locate("/dev/nvidia-caps/nvidia-*") capDevices, err := locator.Locate("/dev/nvidia-caps/nvidia-*")
if err != nil { if err != nil {
m.logger.Warnf("Error while locating caps device: %v", err) m.logger.Warningf("Error while locating caps device: %v", err)
} }
if len(devices) == 0 && len(capDevices) == 0 { if len(devices) == 0 && len(capDevices) == 0 {
@ -67,7 +67,7 @@ func (m existing) DeviceNodes() ([]deviceNode, error) {
var stat unix.Stat_t var stat unix.Stat_t
err := unix.Stat(d, &stat) err := unix.Stat(d, &stat)
if err != nil { if err != nil {
m.logger.Warnf("Could not stat device: %v", err) m.logger.Warningf("Could not stat device: %v", err)
continue continue
} }
deviceNode := deviceNode{ deviceNode := deviceNode{

View File

@ -286,7 +286,7 @@ func resolveWithDefault(logger logger.Interface, label string, path string, defa
resolvedPath := defaultPath resolvedPath := defaultPath
targets, err := lookup.Locate(path) targets, err := lookup.Locate(path)
if err != nil { if err != nil {
logger.Warnf("Failed to locate %v: %v", path, err) logger.Warningf("Failed to locate %v: %v", path, err)
} else { } else {
logger.Debugf("Found %v candidates: %v", path, targets) logger.Debugf("Found %v candidates: %v", path, targets)
resolvedPath = targets[0] resolvedPath = targets[0]

View File

@ -29,7 +29,7 @@ import (
// single CSV files. // single CSV files.
func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string) (Discover, error) { func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string) (Discover, error) {
if len(files) == 0 { if len(files) == 0 {
logger.Warnf("No CSV files specified") logger.Warningf("No CSV files specified")
return None{}, nil return None{}, nil
} }
@ -46,7 +46,7 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string)
for _, filename := range files { for _, filename := range files {
targets, err := loadCSVFile(logger, filename) targets, err := loadCSVFile(logger, filename)
if err != nil { if err != nil {
logger.Warnf("Skipping CSV file %v: %v", filename, err) logger.Warningf("Skipping CSV file %v: %v", filename, err)
continue continue
} }
mountSpecs = append(mountSpecs, targets...) mountSpecs = append(mountSpecs, targets...)

View File

@ -259,7 +259,7 @@ var _ Discover = (*xorgHooks)(nil)
func optionalXorgDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) Discover { func optionalXorgDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) Discover {
xorg, err := newXorgDiscoverer(logger, driverRoot, nvidiaCTKPath) xorg, err := newXorgDiscoverer(logger, driverRoot, nvidiaCTKPath)
if err != nil { if err != nil {
logger.Warnf("Failed to create Xorg discoverer: %v; skipping xorg libraries", err) logger.Warningf("Failed to create Xorg discoverer: %v; skipping xorg libraries", err)
return None{} return None{}
} }
return xorg return xorg

View File

@ -75,11 +75,11 @@ func (d *mounts) Mounts() ([]Mount, error) {
d.logger.Debugf("Locating %v", candidate) d.logger.Debugf("Locating %v", candidate)
located, err := d.lookup.Locate(candidate) located, err := d.lookup.Locate(candidate)
if err != nil { if err != nil {
d.logger.Warnf("Could not locate %v: %v", candidate, err) d.logger.Warningf("Could not locate %v: %v", candidate, err)
continue continue
} }
if len(located) == 0 { if len(located) == 0 {
d.logger.Warnf("Missing %v", candidate) d.logger.Warningf("Missing %v", candidate)
continue continue
} }
d.logger.Debugf("Located %v as %v", candidate, located) d.logger.Debugf("Located %v as %v", candidate, located)

View File

@ -129,7 +129,7 @@ func (d symlinkHook) getCSVFileSymlinks() []string {
} }
targets, err := chainLocator.Locate(ms.Path) targets, err := chainLocator.Locate(ms.Path)
if err != nil { if err != nil {
d.logger.Warnf("Failed to locate symlink %v", ms.Path) d.logger.Warningf("Failed to locate symlink %v", ms.Path)
} }
candidates = append(candidates, targets...) candidates = append(candidates, targets...)
} }

View File

@ -22,7 +22,6 @@ type Interface interface {
Errorf(string, ...interface{}) Errorf(string, ...interface{})
Info(...interface{}) Info(...interface{})
Infof(string, ...interface{}) Infof(string, ...interface{})
Warn(...interface{}) Warning(...interface{})
Warnf(string, ...interface{})
Warningf(string, ...interface{}) Warningf(string, ...interface{})
} }

View File

@ -40,11 +40,8 @@ func (l *NullLogger) Info(...interface{}) {}
// Infof is a no-op for the null logger // Infof is a no-op for the null logger
func (l *NullLogger) Infof(string, ...interface{}) {} func (l *NullLogger) Infof(string, ...interface{}) {}
// Warn is a no-op for the null logger // Warning is a no-op for the null logger
func (l *NullLogger) Warn(...interface{}) {} func (l *NullLogger) Warning(...interface{}) {}
// Warnf is a no-op for the null logger
func (l *NullLogger) Warnf(string, ...interface{}) {}
// Warningf is a no-op for the null logger // Warningf is a no-op for the null logger
func (l *NullLogger) Warningf(string, ...interface{}) {} func (l *NullLogger) Warningf(string, ...interface{}) {}

View File

@ -58,7 +58,7 @@ func (l library) Locate(libname string) ([]string, error) {
paths32, paths64 := l.cache.Lookup(libname) paths32, paths64 := l.cache.Lookup(libname)
if len(paths32) > 0 { if len(paths32) > 0 {
l.logger.Warnf("Ignoring 32-bit libraries for %v: %v", libname, paths32) l.logger.Warningf("Ignoring 32-bit libraries for %v: %v", libname, paths32)
} }
if len(paths64) == 0 { if len(paths64) == 0 {

View File

@ -115,14 +115,14 @@ func checkRequirements(logger logger.Interface, image image.CUDA) error {
cudaVersion, err := cuda.Version() cudaVersion, err := cuda.Version()
if err != nil { if err != nil {
logger.Warnf("Failed to get CUDA version: %v", err) logger.Warningf("Failed to get CUDA version: %v", err)
} else { } else {
r.AddVersionProperty(requirements.CUDA, cudaVersion) r.AddVersionProperty(requirements.CUDA, cudaVersion)
} }
compteCapability, err := cuda.ComputeCapability(0) compteCapability, err := cuda.ComputeCapability(0)
if err != nil { if err != nil {
logger.Warnf("Failed to get CUDA Compute Capability: %v", err) logger.Warningf("Failed to get CUDA Compute Capability: %v", err)
} else { } else {
r.AddVersionProperty(requirements.ARCH, compteCapability) r.AddVersionProperty(requirements.ARCH, compteCapability)
} }

View File

@ -52,7 +52,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) {
level, logLevelError := configFromArgs.getLevel(logLevel) level, logLevelError := configFromArgs.getLevel(logLevel)
defer func() { defer func() {
if logLevelError != nil { if logLevelError != nil {
l.Warn(logLevelError) l.Warning(logLevelError)
} }
}() }()
@ -77,7 +77,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) {
} }
defer func() { defer func() {
if argLogFileError != nil { if argLogFileError != nil {
l.Warnf("Failed to open log file: %v", argLogFileError) l.Warningf("Failed to open log file: %v", argLogFileError)
} }
}() }()

View File

@ -65,7 +65,7 @@ func newWSLDriverStoreDiscoverer(logger logger.Interface, driverRoot string, nvi
searchPaths = append(searchPaths, path) searchPaths = append(searchPaths, path)
} }
if len(searchPaths) > 1 { if len(searchPaths) > 1 {
logger.Warnf("Found multiple driver store paths: %v", searchPaths) logger.Warningf("Found multiple driver store paths: %v", searchPaths)
} }
driverStorePath := searchPaths[0] driverStorePath := searchPaths[0]
searchPaths = append(searchPaths, "/usr/lib/wsl/lib") searchPaths = append(searchPaths, "/usr/lib/wsl/lib")

View File

@ -134,7 +134,7 @@ func (o Options) RevertConfig(cfg engine.Interface) error {
func (o Options) Restart(service string, withSignal func(string) error) error { func (o Options) Restart(service string, withSignal func(string) error) error {
switch o.RestartMode { switch o.RestartMode {
case restartModeNone: case restartModeNone:
logrus.Warnf("Skipping restart of %v due to --restart-mode=%v", service, o.RestartMode) logrus.Warningf("Skipping restart of %v due to --restart-mode=%v", service, o.RestartMode)
return nil return nil
case restartModeSignal: case restartModeSignal:
return withSignal(o.Socket) return withSignal(o.Socket)

View File

@ -311,11 +311,11 @@ func SignalContainerd(socket string) error {
if i == maxReloadAttempts-1 { if i == maxReloadAttempts-1 {
break break
} }
log.Warnf("Error signaling containerd, attempt %v/%v: %v", i+1, maxReloadAttempts, err) log.Warningf("Error signaling containerd, attempt %v/%v: %v", i+1, maxReloadAttempts, err)
time.Sleep(reloadBackoff) time.Sleep(reloadBackoff)
} }
if err != nil { if err != nil {
log.Warnf("Max retries reached %v/%v, aborting", maxReloadAttempts, maxReloadAttempts) log.Warningf("Max retries reached %v/%v, aborting", maxReloadAttempts, maxReloadAttempts)
return err return err
} }

View File

@ -285,11 +285,11 @@ func SignalDocker(socket string) error {
if i == maxReloadAttempts-1 { if i == maxReloadAttempts-1 {
break break
} }
log.Warnf("Error signaling docker, attempt %v/%v: %v", i+1, maxReloadAttempts, err) log.Warningf("Error signaling docker, attempt %v/%v: %v", i+1, maxReloadAttempts, err)
time.Sleep(reloadBackoff) time.Sleep(reloadBackoff)
} }
if err != nil { if err != nil {
log.Warnf("Max retries reached %v/%v, aborting", maxReloadAttempts, maxReloadAttempts) log.Warningf("Max retries reached %v/%v, aborting", maxReloadAttempts, maxReloadAttempts)
return err return err
} }

View File

@ -192,8 +192,8 @@ func initialize() error {
err = unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB) err = unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB)
if err != nil { if err != nil {
log.Warnf("Unable to get exclusive lock on '%v'", pidFile) log.Warningf("Unable to get exclusive lock on '%v'", pidFile)
log.Warnf("This normally means an instance of the NVIDIA toolkit Container is already running, aborting") log.Warningf("This normally means an instance of the NVIDIA toolkit Container is already running, aborting")
return fmt.Errorf("unable to get flock on pidfile: %v", err) return fmt.Errorf("unable to get flock on pidfile: %v", err)
} }
@ -288,6 +288,6 @@ func shutdown() {
err := os.Remove(pidFile) err := os.Remove(pidFile)
if err != nil { if err != nil {
log.Warnf("Unable to remove pidfile: %v", err) log.Warningf("Unable to remove pidfile: %v", err)
} }
} }

View File

@ -50,7 +50,7 @@ func installContainerRuntimes(toolkitDir string, driverRoot string) error {
// Install the experimental runtime and treat failures as non-fatal. // Install the experimental runtime and treat failures as non-fatal.
err := installExperimentalRuntime(toolkitDir, driverRoot) err := installExperimentalRuntime(toolkitDir, driverRoot)
if err != nil { if err != nil {
log.Warnf("Could not install experimental runtime: %v", err) log.Warningf("Could not install experimental runtime: %v", err)
} }
return nil return nil
@ -60,7 +60,7 @@ func installContainerRuntimes(toolkitDir string, driverRoot string) error {
func installExperimentalRuntime(toolkitDir string, driverRoot string) error { func installExperimentalRuntime(toolkitDir string, driverRoot string) error {
libraryRoot, err := findLibraryRoot(driverRoot) libraryRoot, err := findLibraryRoot(driverRoot)
if err != nil { if err != nil {
log.Warnf("Error finding library path for root %v: %v", driverRoot, err) log.Warningf("Error finding library path for root %v: %v", driverRoot, err)
} }
log.Infof("Using library root %v", libraryRoot) log.Infof("Using library root %v", libraryRoot)

View File

@ -448,7 +448,7 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai
} }
value = v.Value() value = v.Value()
default: default:
log.Warnf("Unexpected type for option %v=%v: %T", key, value, v) log.Warningf("Unexpected type for option %v=%v: %T", key, value, v)
} }
config.Set(key, value) config.Set(key, value)