From 1d0a733487b5ff433b7814dca842fddc0bd82e6e Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 6 Jun 2023 21:46:38 +0200 Subject: [PATCH] Replace logger.Warn(f) with logger.Warning(f) This aligns better with klog used in other projects. Signed-off-by: Evan Lezar --- .../hook/create-symlinks/create-symlinks.go | 12 ++++++------ .../create-dev-char-symlinks.go | 6 +++--- .../system/create-dev-char-symlinks/existing.go | 6 +++--- internal/config/config.go | 2 +- internal/discover/csv.go | 4 ++-- internal/discover/graphics.go | 2 +- internal/discover/mounts.go | 4 ++-- internal/discover/symlinks.go | 2 +- internal/logger/api.go | 3 +-- internal/logger/lib.go | 7 ++----- internal/lookup/library.go | 2 +- internal/modifier/csv.go | 4 ++-- internal/runtime/logger.go | 4 ++-- pkg/nvcdi/driver-wsl.go | 2 +- tools/container/container.go | 2 +- tools/container/containerd/containerd.go | 4 ++-- tools/container/docker/docker.go | 4 ++-- tools/container/nvidia-toolkit/run.go | 6 +++--- tools/container/toolkit/runtime.go | 4 ++-- tools/container/toolkit/toolkit.go | 2 +- 20 files changed, 39 insertions(+), 43 deletions(-) diff --git a/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go b/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go index 6766d760..3b253ed7 100644 --- a/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go +++ b/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go @@ -117,7 +117,7 @@ func (m command) run(c *cli.Context, cfg *config) error { } targets, err := chainLocator.Locate(ms.Path) 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...) } @@ -137,7 +137,7 @@ func (m command) run(c *cli.Context, cfg *config) error { err = m.createLink(created, cfg.hostRoot, containerRoot, target, candidate) 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 { parts := strings.Split(l, "::") if len(parts) != 2 { - m.logger.Warnf("Invalid link specification %v", l) + m.logger.Warningf("Invalid link specification %v", l) continue } err := m.createLink(created, cfg.hostRoot, containerRoot, parts[0], parts[1]) 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 { linkPath, err := changeRoot(hostRoot, containerRoot, link) 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] { 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) 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) diff --git a/cmd/nvidia-ctk/system/create-dev-char-symlinks/create-dev-char-symlinks.go b/cmd/nvidia-ctk/system/create-dev-char-symlinks/create-dev-char-symlinks.go index baae45ed..9d0c6a8d 100644 --- a/cmd/nvidia-ctk/system/create-dev-char-symlinks/create-dev-char-symlinks.go +++ b/cmd/nvidia-ctk/system/create-dev-char-symlinks/create-dev-char-symlinks.go @@ -130,12 +130,12 @@ func (m command) validateFlags(r *cli.Context, cfg *config) error { } 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 } 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 } @@ -365,7 +365,7 @@ func (m linkCreator) CreateLinks() error { err = os.Symlink(target, linkPath) if err != nil { - m.logger.Warnf("Could not create symlink: %v", err) + m.logger.Warningf("Could not create symlink: %v", err) } } diff --git a/cmd/nvidia-ctk/system/create-dev-char-symlinks/existing.go b/cmd/nvidia-ctk/system/create-dev-char-symlinks/existing.go index 98d0c782..a88da8f5 100644 --- a/cmd/nvidia-ctk/system/create-dev-char-symlinks/existing.go +++ b/cmd/nvidia-ctk/system/create-dev-char-symlinks/existing.go @@ -45,12 +45,12 @@ func (m existing) DeviceNodes() ([]deviceNode, error) { devices, err := locator.Locate("/dev/nvidia*") 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-*") 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 { @@ -67,7 +67,7 @@ func (m existing) DeviceNodes() ([]deviceNode, error) { var stat unix.Stat_t err := unix.Stat(d, &stat) if err != nil { - m.logger.Warnf("Could not stat device: %v", err) + m.logger.Warningf("Could not stat device: %v", err) continue } deviceNode := deviceNode{ diff --git a/internal/config/config.go b/internal/config/config.go index 6fd145b6..c25aa19d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -286,7 +286,7 @@ func resolveWithDefault(logger logger.Interface, label string, path string, defa resolvedPath := defaultPath targets, err := lookup.Locate(path) if err != nil { - logger.Warnf("Failed to locate %v: %v", path, err) + logger.Warningf("Failed to locate %v: %v", path, err) } else { logger.Debugf("Found %v candidates: %v", path, targets) resolvedPath = targets[0] diff --git a/internal/discover/csv.go b/internal/discover/csv.go index 3d7a9875..7b747b1c 100644 --- a/internal/discover/csv.go +++ b/internal/discover/csv.go @@ -29,7 +29,7 @@ import ( // single CSV files. func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string) (Discover, error) { if len(files) == 0 { - logger.Warnf("No CSV files specified") + logger.Warningf("No CSV files specified") return None{}, nil } @@ -46,7 +46,7 @@ func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string) for _, filename := range files { targets, err := loadCSVFile(logger, filename) if err != nil { - logger.Warnf("Skipping CSV file %v: %v", filename, err) + logger.Warningf("Skipping CSV file %v: %v", filename, err) continue } mountSpecs = append(mountSpecs, targets...) diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 7bfd4103..0bc9451e 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -259,7 +259,7 @@ var _ Discover = (*xorgHooks)(nil) func optionalXorgDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) Discover { xorg, err := newXorgDiscoverer(logger, driverRoot, nvidiaCTKPath) 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 xorg diff --git a/internal/discover/mounts.go b/internal/discover/mounts.go index 62a44d1e..9232dae3 100644 --- a/internal/discover/mounts.go +++ b/internal/discover/mounts.go @@ -75,11 +75,11 @@ func (d *mounts) Mounts() ([]Mount, error) { d.logger.Debugf("Locating %v", candidate) located, err := d.lookup.Locate(candidate) if err != nil { - d.logger.Warnf("Could not locate %v: %v", candidate, err) + d.logger.Warningf("Could not locate %v: %v", candidate, err) continue } if len(located) == 0 { - d.logger.Warnf("Missing %v", candidate) + d.logger.Warningf("Missing %v", candidate) continue } d.logger.Debugf("Located %v as %v", candidate, located) diff --git a/internal/discover/symlinks.go b/internal/discover/symlinks.go index 485f2353..b1afadef 100644 --- a/internal/discover/symlinks.go +++ b/internal/discover/symlinks.go @@ -129,7 +129,7 @@ func (d symlinkHook) getCSVFileSymlinks() []string { } targets, err := chainLocator.Locate(ms.Path) 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...) } diff --git a/internal/logger/api.go b/internal/logger/api.go index 5bb365d9..b8db9766 100644 --- a/internal/logger/api.go +++ b/internal/logger/api.go @@ -22,7 +22,6 @@ type Interface interface { Errorf(string, ...interface{}) Info(...interface{}) Infof(string, ...interface{}) - Warn(...interface{}) - Warnf(string, ...interface{}) + Warning(...interface{}) Warningf(string, ...interface{}) } diff --git a/internal/logger/lib.go b/internal/logger/lib.go index 075c6ea3..300e925f 100644 --- a/internal/logger/lib.go +++ b/internal/logger/lib.go @@ -40,11 +40,8 @@ func (l *NullLogger) Info(...interface{}) {} // Infof is a no-op for the null logger func (l *NullLogger) Infof(string, ...interface{}) {} -// Warn is a no-op for the null logger -func (l *NullLogger) Warn(...interface{}) {} - -// Warnf is a no-op for the null logger -func (l *NullLogger) Warnf(string, ...interface{}) {} +// Warning is a no-op for the null logger +func (l *NullLogger) Warning(...interface{}) {} // Warningf is a no-op for the null logger func (l *NullLogger) Warningf(string, ...interface{}) {} diff --git a/internal/lookup/library.go b/internal/lookup/library.go index e1fd9756..fabf53fe 100644 --- a/internal/lookup/library.go +++ b/internal/lookup/library.go @@ -58,7 +58,7 @@ func (l library) Locate(libname string) ([]string, error) { paths32, paths64 := l.cache.Lookup(libname) 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 { diff --git a/internal/modifier/csv.go b/internal/modifier/csv.go index d944bc20..81225d14 100644 --- a/internal/modifier/csv.go +++ b/internal/modifier/csv.go @@ -115,14 +115,14 @@ func checkRequirements(logger logger.Interface, image image.CUDA) error { cudaVersion, err := cuda.Version() if err != nil { - logger.Warnf("Failed to get CUDA version: %v", err) + logger.Warningf("Failed to get CUDA version: %v", err) } else { r.AddVersionProperty(requirements.CUDA, cudaVersion) } compteCapability, err := cuda.ComputeCapability(0) if err != nil { - logger.Warnf("Failed to get CUDA Compute Capability: %v", err) + logger.Warningf("Failed to get CUDA Compute Capability: %v", err) } else { r.AddVersionProperty(requirements.ARCH, compteCapability) } diff --git a/internal/runtime/logger.go b/internal/runtime/logger.go index ee946dbd..2cf2c953 100644 --- a/internal/runtime/logger.go +++ b/internal/runtime/logger.go @@ -52,7 +52,7 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) { level, logLevelError := configFromArgs.getLevel(logLevel) defer func() { 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() { if argLogFileError != nil { - l.Warnf("Failed to open log file: %v", argLogFileError) + l.Warningf("Failed to open log file: %v", argLogFileError) } }() diff --git a/pkg/nvcdi/driver-wsl.go b/pkg/nvcdi/driver-wsl.go index 9cf74b0e..f5d138cf 100644 --- a/pkg/nvcdi/driver-wsl.go +++ b/pkg/nvcdi/driver-wsl.go @@ -65,7 +65,7 @@ func newWSLDriverStoreDiscoverer(logger logger.Interface, driverRoot string, nvi searchPaths = append(searchPaths, path) } 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] searchPaths = append(searchPaths, "/usr/lib/wsl/lib") diff --git a/tools/container/container.go b/tools/container/container.go index 953e901b..85547019 100644 --- a/tools/container/container.go +++ b/tools/container/container.go @@ -134,7 +134,7 @@ func (o Options) RevertConfig(cfg engine.Interface) error { func (o Options) Restart(service string, withSignal func(string) error) error { switch o.RestartMode { 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 case restartModeSignal: return withSignal(o.Socket) diff --git a/tools/container/containerd/containerd.go b/tools/container/containerd/containerd.go index a7c2615c..15487c34 100644 --- a/tools/container/containerd/containerd.go +++ b/tools/container/containerd/containerd.go @@ -311,11 +311,11 @@ func SignalContainerd(socket string) error { if i == maxReloadAttempts-1 { 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) } 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 } diff --git a/tools/container/docker/docker.go b/tools/container/docker/docker.go index 9a482e1d..3229615d 100644 --- a/tools/container/docker/docker.go +++ b/tools/container/docker/docker.go @@ -285,11 +285,11 @@ func SignalDocker(socket string) error { if i == maxReloadAttempts-1 { 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) } 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 } diff --git a/tools/container/nvidia-toolkit/run.go b/tools/container/nvidia-toolkit/run.go index aff9dd40..78efd9a1 100644 --- a/tools/container/nvidia-toolkit/run.go +++ b/tools/container/nvidia-toolkit/run.go @@ -192,8 +192,8 @@ func initialize() error { err = unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB) if err != nil { - log.Warnf("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("Unable to get exclusive lock on '%v'", pidFile) + 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) } @@ -288,6 +288,6 @@ func shutdown() { err := os.Remove(pidFile) if err != nil { - log.Warnf("Unable to remove pidfile: %v", err) + log.Warningf("Unable to remove pidfile: %v", err) } } diff --git a/tools/container/toolkit/runtime.go b/tools/container/toolkit/runtime.go index d8d7abad..884dc4bf 100644 --- a/tools/container/toolkit/runtime.go +++ b/tools/container/toolkit/runtime.go @@ -50,7 +50,7 @@ func installContainerRuntimes(toolkitDir string, driverRoot string) error { // Install the experimental runtime and treat failures as non-fatal. err := installExperimentalRuntime(toolkitDir, driverRoot) if err != nil { - log.Warnf("Could not install experimental runtime: %v", err) + log.Warningf("Could not install experimental runtime: %v", err) } return nil @@ -60,7 +60,7 @@ func installContainerRuntimes(toolkitDir string, driverRoot string) error { func installExperimentalRuntime(toolkitDir string, driverRoot string) error { libraryRoot, err := findLibraryRoot(driverRoot) 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) diff --git a/tools/container/toolkit/toolkit.go b/tools/container/toolkit/toolkit.go index e86d2375..5f361f8f 100644 --- a/tools/container/toolkit/toolkit.go +++ b/tools/container/toolkit/toolkit.go @@ -448,7 +448,7 @@ func installToolkitConfig(c *cli.Context, toolkitConfigPath string, nvidiaContai } value = v.Value() 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)