From a02bc27c3ee248bcd222efa7ca8977481777eea8 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 22 Mar 2023 14:27:43 +0200 Subject: [PATCH 1/4] Define a basic logger interface Signed-off-by: Evan Lezar --- cmd/nvidia-container-runtime/main_test.go | 12 ++++---- cmd/nvidia-ctk/cdi/cdi.go | 6 ++-- cmd/nvidia-ctk/cdi/generate/generate.go | 6 ++-- cmd/nvidia-ctk/cdi/list/list.go | 6 ++-- cmd/nvidia-ctk/cdi/transform/root/root.go | 6 ++-- cmd/nvidia-ctk/cdi/transform/transform.go | 6 ++-- cmd/nvidia-ctk/config/config.go | 6 ++-- .../config/create-default/create-default.go | 6 ++-- cmd/nvidia-ctk/hook/chmod/chmod.go | 6 ++-- .../hook/create-symlinks/create-symlinks.go | 6 ++-- cmd/nvidia-ctk/hook/hook.go | 6 ++-- .../hook/update-ldcache/update-ldcache.go | 6 ++-- cmd/nvidia-ctk/info/info.go | 6 ++-- cmd/nvidia-ctk/main.go | 14 +++++----- cmd/nvidia-ctk/runtime/configure/configure.go | 6 ++-- cmd/nvidia-ctk/runtime/runtime.go | 6 ++-- .../system/create-dev-char-symlinks/all.go | 6 ++-- .../create-dev-char-symlinks.go | 12 ++++---- .../create-dev-char-symlinks/existing.go | 4 +-- .../create-device-nodes.go | 6 ++-- .../system/print-ldcache/print-ldcache.go | 6 ++-- cmd/nvidia-ctk/system/system.go | 6 ++-- internal/config/config.go | 8 +++--- internal/discover/char_devices.go | 6 ++-- internal/discover/csv.go | 8 +++--- internal/discover/csv/csv.go | 6 ++-- internal/discover/filter.go | 6 ++-- internal/discover/gds.go | 6 ++-- internal/discover/graphics.go | 18 ++++++------ internal/discover/icp_test.go | 5 ++-- internal/discover/ipc.go | 4 +-- internal/discover/ldconfig.go | 6 ++-- internal/discover/mofed.go | 6 ++-- internal/discover/mounts.go | 8 +++--- internal/discover/symlinks.go | 6 ++-- internal/discover/tegra/tegra.go | 6 ++-- internal/edits/edits.go | 6 ++-- internal/ldcache/ldcache.go | 6 ++-- internal/logger/api.go | 28 +++++++++++++++++++ internal/logger/lib.go | 24 ++++++++++++++++ internal/lookup/cuda/cuda.go | 8 +++--- internal/lookup/dir.go | 4 +-- internal/lookup/executable.go | 6 ++-- internal/lookup/file.go | 8 +++--- internal/lookup/library.go | 6 ++-- internal/lookup/symlinks.go | 6 ++-- internal/modifier/cdi.go | 8 +++--- internal/modifier/csv.go | 8 +++--- internal/modifier/discover.go | 6 ++-- internal/modifier/gds.go | 4 +-- internal/modifier/graphics.go | 4 +-- internal/modifier/hook_remover.go | 4 +-- internal/modifier/mofed.go | 4 +-- internal/modifier/stable.go | 6 ++-- internal/modifier/stable_test.go | 4 +-- internal/oci/runtime_low_level.go | 6 ++-- internal/oci/runtime_modifier.go | 6 ++-- internal/oci/runtime_path.go | 6 ++-- internal/oci/spec.go | 4 +-- internal/requirements/constraints/factory.go | 6 ++-- internal/requirements/requirements.go | 6 ++-- internal/runtime/logger.go | 13 +++++---- internal/runtime/logger_test.go | 6 ++-- internal/runtime/runtime.go | 6 ++-- internal/runtime/runtime_factory.go | 8 +++--- internal/runtime/runtime_factory_test.go | 6 ++-- internal/system/options.go | 4 +-- internal/system/system.go | 6 ++-- pkg/config/engine/crio/option.go | 15 ++++++---- pkg/nvcdi/common-nvml.go | 4 +-- pkg/nvcdi/device-wsl.go | 4 +-- pkg/nvcdi/driver-nvml.go | 14 +++++----- pkg/nvcdi/driver-wsl.go | 6 ++-- pkg/nvcdi/full-gpu-nvml.go | 6 ++-- pkg/nvcdi/lib.go | 6 ++-- pkg/nvcdi/mig-device-nvml.go | 6 ++-- pkg/nvcdi/options.go | 4 +-- .../workarounds-device-folder-permissions.go | 6 ++-- 78 files changed, 307 insertions(+), 246 deletions(-) create mode 100644 internal/logger/api.go create mode 100644 internal/logger/lib.go diff --git a/cmd/nvidia-container-runtime/main_test.go b/cmd/nvidia-container-runtime/main_test.go index b8037751..4260559b 100644 --- a/cmd/nvidia-container-runtime/main_test.go +++ b/cmd/nvidia-container-runtime/main_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "io/ioutil" + "log" "os" "os/exec" "path/filepath" @@ -13,7 +14,7 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/modifier" "github.com/NVIDIA/nvidia-container-toolkit/internal/test" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" + testlog "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" ) @@ -42,7 +43,7 @@ func TestMain(m *testing.M) { var err error moduleRoot, err := test.GetModuleRoot() if err != nil { - logrus.Fatalf("error in test setup: could not get module root: %v", err) + log.Fatalf("error in test setup: could not get module root: %v", err) } testBinPath := filepath.Join(moduleRoot, "test", "bin") testInputPath := filepath.Join(moduleRoot, "test", "input") @@ -54,11 +55,11 @@ func TestMain(m *testing.M) { // Confirm that the environment is configured correctly runcPath, err := exec.LookPath(runcExecutableName) if err != nil || filepath.Join(testBinPath, runcExecutableName) != runcPath { - logrus.Fatalf("error in test setup: mock runc path set incorrectly in TestMain(): %v", err) + log.Fatalf("error in test setup: mock runc path set incorrectly in TestMain(): %v", err) } hookPath, err := exec.LookPath(nvidiaHook) if err != nil || filepath.Join(testBinPath, nvidiaHook) != hookPath { - logrus.Fatalf("error in test setup: mock hook path set incorrectly in TestMain(): %v", err) + log.Fatalf("error in test setup: mock hook path set incorrectly in TestMain(): %v", err) } // Store the root and binary paths in the test Config @@ -172,7 +173,8 @@ func TestDuplicateHook(t *testing.T) { // addNVIDIAHook is a basic wrapper for an addHookModifier that is used for // testing. func addNVIDIAHook(spec *specs.Spec) error { - m := modifier.NewStableRuntimeModifier(logrus.StandardLogger(), nvidiaHook) + logger, _ := testlog.NewNullLogger() + m := modifier.NewStableRuntimeModifier(logger, nvidiaHook) return m.Modify(spec) } diff --git a/cmd/nvidia-ctk/cdi/cdi.go b/cmd/nvidia-ctk/cdi/cdi.go index 57ea64dd..0c394b70 100644 --- a/cmd/nvidia-ctk/cdi/cdi.go +++ b/cmd/nvidia-ctk/cdi/cdi.go @@ -20,16 +20,16 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/generate" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/list" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/transform" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs an info command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/cdi/generate/generate.go b/cmd/nvidia-ctk/cdi/generate/generate.go index cab3f97a..00f8e4b5 100644 --- a/cmd/nvidia-ctk/cdi/generate/generate.go +++ b/cmd/nvidia-ctk/cdi/generate/generate.go @@ -24,11 +24,11 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -37,7 +37,7 @@ const ( ) type command struct { - logger *logrus.Logger + logger logger.Interface } type options struct { @@ -56,7 +56,7 @@ type options struct { } // NewCommand constructs a generate-cdi command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/cdi/list/list.go b/cmd/nvidia-ctk/cdi/list/list.go index b7aab6e0..2acec2e4 100644 --- a/cmd/nvidia-ctk/cdi/list/list.go +++ b/cmd/nvidia-ctk/cdi/list/list.go @@ -19,19 +19,19 @@ package list import ( "fmt" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } type config struct{} // NewCommand constructs a cdi list command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/cdi/transform/root/root.go b/cmd/nvidia-ctk/cdi/transform/root/root.go index b89a6c15..191eb8be 100644 --- a/cmd/nvidia-ctk/cdi/transform/root/root.go +++ b/cmd/nvidia-ctk/cdi/transform/root/root.go @@ -21,10 +21,10 @@ import ( "io" "os" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -34,7 +34,7 @@ type loadSaver interface { } type command struct { - logger *logrus.Logger + logger logger.Interface } type transformOptions struct { @@ -49,7 +49,7 @@ type options struct { } // NewCommand constructs a generate-cdi command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/cdi/transform/transform.go b/cmd/nvidia-ctk/cdi/transform/transform.go index 5538166d..98c17b85 100644 --- a/cmd/nvidia-ctk/cdi/transform/transform.go +++ b/cmd/nvidia-ctk/cdi/transform/transform.go @@ -18,16 +18,16 @@ package transform import ( "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/transform/root" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs a command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/config/config.go b/cmd/nvidia-ctk/config/config.go index cc36d11f..2f00ed59 100644 --- a/cmd/nvidia-ctk/config/config.go +++ b/cmd/nvidia-ctk/config/config.go @@ -18,16 +18,16 @@ package config import ( createdefault "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/config/create-default" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs an config command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/config/create-default/create-default.go b/cmd/nvidia-ctk/config/create-default/create-default.go index c0a92cf9..db89345a 100644 --- a/cmd/nvidia-ctk/config/create-default/create-default.go +++ b/cmd/nvidia-ctk/config/create-default/create-default.go @@ -22,12 +22,12 @@ import ( "os" nvctkConfig "github.com/NVIDIA/nvidia-container-toolkit/internal/config" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } // options stores the subcommand options @@ -36,7 +36,7 @@ type options struct { } // NewCommand constructs a default command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/hook/chmod/chmod.go b/cmd/nvidia-ctk/hook/chmod/chmod.go index 0a78b6e8..4f2f28e1 100644 --- a/cmd/nvidia-ctk/hook/chmod/chmod.go +++ b/cmd/nvidia-ctk/hook/chmod/chmod.go @@ -23,14 +23,14 @@ import ( "strings" "syscall" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } type config struct { @@ -40,7 +40,7 @@ type config struct { } // NewCommand constructs a chmod command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go b/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go index 39ade7f0..6766d760 100644 --- a/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go +++ b/cmd/nvidia-ctk/hook/create-symlinks/create-symlinks.go @@ -23,15 +23,15 @@ import ( "strings" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } type config struct { @@ -42,7 +42,7 @@ type config struct { } // NewCommand constructs a hook command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/hook/hook.go b/cmd/nvidia-ctk/hook/hook.go index 8fc403ae..e796eafd 100644 --- a/cmd/nvidia-ctk/hook/hook.go +++ b/cmd/nvidia-ctk/hook/hook.go @@ -18,19 +18,19 @@ package hook import ( chmod "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/hook/chmod" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" symlinks "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/hook/create-symlinks" ldcache "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/hook/update-ldcache" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type hookCommand struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs a hook command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := hookCommand{ logger: logger, } diff --git a/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go b/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go index 119573e6..a0267297 100644 --- a/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go +++ b/cmd/nvidia-ctk/hook/update-ldcache/update-ldcache.go @@ -22,13 +22,13 @@ import ( "path/filepath" "syscall" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } type config struct { @@ -37,7 +37,7 @@ type config struct { } // NewCommand constructs an update-ldcache command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/info/info.go b/cmd/nvidia-ctk/info/info.go index d2aa50cc..6fccbd43 100644 --- a/cmd/nvidia-ctk/info/info.go +++ b/cmd/nvidia-ctk/info/info.go @@ -17,16 +17,16 @@ package info import ( - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs an info command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/main.go b/cmd/nvidia-ctk/main.go index 9fd9e603..a1566559 100644 --- a/cmd/nvidia-ctk/main.go +++ b/cmd/nvidia-ctk/main.go @@ -26,13 +26,11 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/runtime" "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system" "github.com/NVIDIA/nvidia-container-toolkit/internal/info" + "github.com/sirupsen/logrus" - log "github.com/sirupsen/logrus" cli "github.com/urfave/cli/v2" ) -var logger = log.New() - // options defines the options that can be set for the CLI through config files, // environment variables, or command line flags type options struct { @@ -41,6 +39,8 @@ type options struct { } func main() { + logger := logrus.New() + // Create a options struct to hold the parsed environment variables or command line flags opts := options{} @@ -65,9 +65,9 @@ func main() { // Set log-level for all subcommands c.Before = func(c *cli.Context) error { - logLevel := log.InfoLevel + logLevel := logrus.InfoLevel if opts.Debug { - logLevel = log.DebugLevel + logLevel = logrus.DebugLevel } logger.SetLevel(logLevel) return nil @@ -86,7 +86,7 @@ func main() { // Run the CLI err := c.Run(os.Args) if err != nil { - log.Errorf("%v", err) - log.Exit(1) + logger.Errorf("%v", err) + os.Exit(1) } } diff --git a/cmd/nvidia-ctk/runtime/configure/configure.go b/cmd/nvidia-ctk/runtime/configure/configure.go index d9085d45..f978b403 100644 --- a/cmd/nvidia-ctk/runtime/configure/configure.go +++ b/cmd/nvidia-ctk/runtime/configure/configure.go @@ -20,11 +20,11 @@ import ( "fmt" "path/filepath" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/crio" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/docker" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -43,11 +43,11 @@ const ( ) type command struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs an configure command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/runtime/runtime.go b/cmd/nvidia-ctk/runtime/runtime.go index e760f30a..d2828e64 100644 --- a/cmd/nvidia-ctk/runtime/runtime.go +++ b/cmd/nvidia-ctk/runtime/runtime.go @@ -18,16 +18,16 @@ package runtime import ( "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/runtime/configure" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type runtimeCommand struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs a runtime command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := runtimeCommand{ logger: logger, } diff --git a/cmd/nvidia-ctk/system/create-dev-char-symlinks/all.go b/cmd/nvidia-ctk/system/create-dev-char-symlinks/all.go index c8c0e3b7..f601e3e7 100644 --- a/cmd/nvidia-ctk/system/create-dev-char-symlinks/all.go +++ b/cmd/nvidia-ctk/system/create-dev-char-symlinks/all.go @@ -21,13 +21,13 @@ import ( "path/filepath" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc/devices" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/nvcaps" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvpci" ) type allPossible struct { - logger *logrus.Logger + logger logger.Interface driverRoot string deviceMajors devices.Devices migCaps nvcaps.MigCaps @@ -35,7 +35,7 @@ type allPossible struct { // newAllPossible returns a new allPossible device node lister. // This lister lists all possible device nodes for NVIDIA GPUs, control devices, and capability devices. -func newAllPossible(logger *logrus.Logger, driverRoot string) (nodeLister, error) { +func newAllPossible(logger logger.Interface, driverRoot string) (nodeLister, error) { deviceMajors, err := devices.GetNVIDIADevices() if err != nil { return nil, fmt.Errorf("failed reading device majors: %v", err) 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 8bd1e563..baae45ed 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 @@ -24,9 +24,9 @@ import ( "strings" "syscall" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/system" "github.com/fsnotify/fsnotify" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) @@ -35,7 +35,7 @@ const ( ) type command struct { - logger *logrus.Logger + logger logger.Interface } type config struct { @@ -49,7 +49,7 @@ type config struct { } // NewCommand constructs a command sub-command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } @@ -213,7 +213,7 @@ create: } type linkCreator struct { - logger *logrus.Logger + logger logger.Interface lister nodeLister driverRoot string devCharPath string @@ -238,7 +238,7 @@ func NewSymlinkCreator(opts ...Option) (Creator, error) { opt(&c) } if c.logger == nil { - c.logger = logrus.StandardLogger() + c.logger = logger.New() } if c.driverRoot == "" { c.driverRoot = "/" @@ -313,7 +313,7 @@ func WithDryRun(dryRun bool) Option { } // WithLogger sets the logger. -func WithLogger(logger *logrus.Logger) Option { +func WithLogger(logger logger.Interface) Option { return func(c *linkCreator) { c.logger = logger } 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 556a89d2..98d0c782 100644 --- a/cmd/nvidia-ctk/system/create-dev-char-symlinks/existing.go +++ b/cmd/nvidia-ctk/system/create-dev-char-symlinks/existing.go @@ -20,8 +20,8 @@ import ( "path/filepath" "strings" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" "golang.org/x/sys/unix" ) @@ -30,7 +30,7 @@ type nodeLister interface { } type existing struct { - logger *logrus.Logger + logger logger.Interface driverRoot string } diff --git a/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go b/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go index 508177bf..94605b6c 100644 --- a/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go +++ b/cmd/nvidia-ctk/system/create-device-nodes/create-device-nodes.go @@ -19,13 +19,13 @@ package createdevicenodes import ( "fmt" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/system" - "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } type options struct { @@ -39,7 +39,7 @@ type options struct { } // NewCommand constructs a command sub-command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go b/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go index a53b813f..b7547f48 100644 --- a/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go +++ b/cmd/nvidia-ctk/system/print-ldcache/print-ldcache.go @@ -20,12 +20,12 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } type options struct { @@ -33,7 +33,7 @@ type options struct { } // NewCommand constructs a command sub-command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/cmd/nvidia-ctk/system/system.go b/cmd/nvidia-ctk/system/system.go index 6683c974..cbb328da 100644 --- a/cmd/nvidia-ctk/system/system.go +++ b/cmd/nvidia-ctk/system/system.go @@ -20,16 +20,16 @@ import ( devchar "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-dev-char-symlinks" devicenodes "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-device-nodes" ldcache "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/print-ldcache" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/urfave/cli/v2" ) type command struct { - logger *logrus.Logger + logger logger.Interface } // NewCommand constructs a runtime command with the specified logger -func NewCommand(logger *logrus.Logger) *cli.Command { +func NewCommand(logger logger.Interface) *cli.Command { c := command{ logger: logger, } diff --git a/internal/config/config.go b/internal/config/config.go index 21763918..6fd145b6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,10 +25,10 @@ import ( "path/filepath" "strings" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/pelletier/go-toml" - "github.com/sirupsen/logrus" ) const ( @@ -249,7 +249,7 @@ func getDistIDLike() []string { // This executable is used in hooks and needs to be an absolute path. // If the path is specified as an absolute path, it is used directly // without checking for existence of an executable at that path. -func ResolveNVIDIACTKPath(logger *logrus.Logger, nvidiaCTKPath string) string { +func ResolveNVIDIACTKPath(logger logger.Interface, nvidiaCTKPath string) string { return resolveWithDefault( logger, "NVIDIA Container Toolkit CLI", @@ -259,7 +259,7 @@ func ResolveNVIDIACTKPath(logger *logrus.Logger, nvidiaCTKPath string) string { } // ResolveNVIDIAContainerRuntimeHookPath resolves the path the nvidia-container-runtime-hook binary. -func ResolveNVIDIAContainerRuntimeHookPath(logger *logrus.Logger, nvidiaContainerRuntimeHookPath string) string { +func ResolveNVIDIAContainerRuntimeHookPath(logger logger.Interface, nvidiaContainerRuntimeHookPath string) string { return resolveWithDefault( logger, "NVIDIA Container Runtime Hook", @@ -271,7 +271,7 @@ func ResolveNVIDIAContainerRuntimeHookPath(logger *logrus.Logger, nvidiaContaine // resolveWithDefault resolves the path to the specified binary. // If an absolute path is specified, it is used directly without searching for the binary. // If the binary cannot be found in the path, the specified default is used instead. -func resolveWithDefault(logger *logrus.Logger, label string, path string, defaultPath string) string { +func resolveWithDefault(logger logger.Interface, label string, path string, defaultPath string) string { if filepath.IsAbs(path) { logger.Debugf("Using specified %v path %v", label, path) return path diff --git a/internal/discover/char_devices.go b/internal/discover/char_devices.go index 2b149142..715d979a 100644 --- a/internal/discover/char_devices.go +++ b/internal/discover/char_devices.go @@ -17,8 +17,8 @@ package discover import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) // charDevices is a discover for a list of character devices @@ -27,7 +27,7 @@ type charDevices mounts var _ Discover = (*charDevices)(nil) // NewCharDeviceDiscoverer creates a discoverer which locates the specified set of device nodes. -func NewCharDeviceDiscoverer(logger *logrus.Logger, devices []string, root string) Discover { +func NewCharDeviceDiscoverer(logger logger.Interface, devices []string, root string) Discover { locator := lookup.NewCharDeviceLocator( lookup.WithLogger(logger), lookup.WithRoot(root), @@ -37,7 +37,7 @@ func NewCharDeviceDiscoverer(logger *logrus.Logger, devices []string, root strin } // NewDeviceDiscoverer creates a discoverer which locates the specified set of device nodes using the specified locator. -func NewDeviceDiscoverer(logger *logrus.Logger, locator lookup.Locator, root string, devices []string) Discover { +func NewDeviceDiscoverer(logger logger.Interface, locator lookup.Locator, root string, devices []string) Discover { m := NewMounts(logger, locator, root, devices).(*mounts) return (*charDevices)(m) diff --git a/internal/discover/csv.go b/internal/discover/csv.go index 3af4a850..3d7a9875 100644 --- a/internal/discover/csv.go +++ b/internal/discover/csv.go @@ -20,14 +20,14 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) // NewFromCSVFiles creates a discoverer for the specified CSV files. A logger is also supplied. // The constructed discoverer is comprised of a list, with each element in the list being associated with a // single CSV files. -func NewFromCSVFiles(logger *logrus.Logger, files []string, driverRoot string) (Discover, error) { +func NewFromCSVFiles(logger logger.Interface, files []string, driverRoot string) (Discover, error) { if len(files) == 0 { logger.Warnf("No CSV files specified") return None{}, nil @@ -56,7 +56,7 @@ func NewFromCSVFiles(logger *logrus.Logger, files []string, driverRoot string) ( } // loadCSVFile loads the specified CSV file and returns the list of mount specs -func loadCSVFile(logger *logrus.Logger, filename string) ([]*csv.MountSpec, error) { +func loadCSVFile(logger logger.Interface, filename string) ([]*csv.MountSpec, error) { // Create a discoverer for each file-kind combination targets, err := csv.NewCSVFileParser(logger, filename).Parse() if err != nil { @@ -71,7 +71,7 @@ func loadCSVFile(logger *logrus.Logger, filename string) ([]*csv.MountSpec, erro // newFromMountSpecs creates a discoverer for the CSV file. A logger is also supplied. // A list of csvDiscoverers is returned, with each being associated with a single MountSpecType. -func newFromMountSpecs(logger *logrus.Logger, locators map[csv.MountSpecType]lookup.Locator, driverRoot string, targets []*csv.MountSpec) (Discover, error) { +func newFromMountSpecs(logger logger.Interface, locators map[csv.MountSpecType]lookup.Locator, driverRoot string, targets []*csv.MountSpec) (Discover, error) { if len(targets) == 0 { return &None{}, nil } diff --git a/internal/discover/csv/csv.go b/internal/discover/csv/csv.go index 64bc34ff..c4f6f495 100644 --- a/internal/discover/csv/csv.go +++ b/internal/discover/csv/csv.go @@ -25,7 +25,7 @@ import ( "path/filepath" "strings" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) const ( @@ -103,12 +103,12 @@ type Parser interface { } type csv struct { - logger *logrus.Logger + logger logger.Interface filename string } // NewCSVFileParser creates a new parser for reading MountSpecs from the specified CSV file -func NewCSVFileParser(logger *logrus.Logger, filename string) Parser { +func NewCSVFileParser(logger logger.Interface, filename string) Parser { p := csv{ logger: logger, filename: filename, diff --git a/internal/discover/filter.go b/internal/discover/filter.go index ee4b78ae..7fd94f09 100644 --- a/internal/discover/filter.go +++ b/internal/discover/filter.go @@ -16,7 +16,7 @@ package discover -import "github.com/sirupsen/logrus" +import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" // Filter defines an interface for filtering discovered entities type Filter interface { @@ -26,12 +26,12 @@ type Filter interface { // filtered represents a filtered discoverer type filtered struct { Discover - logger *logrus.Logger + logger logger.Interface filter Filter } // newFilteredDisoverer creates a discoverer that applies the specified filter to the returned entities of the discoverer -func newFilteredDisoverer(logger *logrus.Logger, applyTo Discover, filter Filter) Discover { +func newFilteredDisoverer(logger logger.Interface, applyTo Discover, filter Filter) Discover { return filtered{ Discover: applyTo, logger: logger, diff --git a/internal/discover/gds.go b/internal/discover/gds.go index 7da5e07d..01360d82 100644 --- a/internal/discover/gds.go +++ b/internal/discover/gds.go @@ -17,19 +17,19 @@ package discover import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) type gdsDeviceDiscoverer struct { None - logger *logrus.Logger + logger logger.Interface devices Discover mounts Discover } // NewGDSDiscoverer creates a discoverer for GPUDirect Storage devices and mounts. -func NewGDSDiscoverer(logger *logrus.Logger, root string) (Discover, error) { +func NewGDSDiscoverer(logger logger.Interface, root string) (Discover, error) { devices := NewCharDeviceDiscoverer( logger, []string{"/dev/nvidia-fs*"}, diff --git a/internal/discover/graphics.go b/internal/discover/graphics.go index 0c515e53..7bfd4103 100644 --- a/internal/discover/graphics.go +++ b/internal/discover/graphics.go @@ -25,13 +25,13 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/drm" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda" - "github.com/sirupsen/logrus" ) // NewGraphicsDiscoverer returns the discoverer for graphics tools such as Vulkan. -func NewGraphicsDiscoverer(logger *logrus.Logger, devices image.VisibleDevices, driverRoot string, nvidiaCTKPath string) (Discover, error) { +func NewGraphicsDiscoverer(logger logger.Interface, devices image.VisibleDevices, driverRoot string, nvidiaCTKPath string) (Discover, error) { mounts, err := NewGraphicsMountsDiscoverer(logger, driverRoot, nvidiaCTKPath) if err != nil { return nil, fmt.Errorf("failed to create mounts discoverer: %v", err) @@ -53,7 +53,7 @@ func NewGraphicsDiscoverer(logger *logrus.Logger, devices image.VisibleDevices, } // NewGraphicsMountsDiscoverer creates a discoverer for the mounts required by graphics tools such as vulkan. -func NewGraphicsMountsDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string) (Discover, error) { +func NewGraphicsMountsDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) (Discover, error) { locator, err := lookup.NewLibraryLocator(logger, driverRoot) if err != nil { return nil, fmt.Errorf("failed to construct library locator: %v", err) @@ -97,14 +97,14 @@ func NewGraphicsMountsDiscoverer(logger *logrus.Logger, driverRoot string, nvidi type drmDevicesByPath struct { None - logger *logrus.Logger + logger logger.Interface nvidiaCTKPath string driverRoot string devicesFrom Discover } // newCreateDRMByPathSymlinks creates a discoverer for a hook to create the by-path symlinks for DRM devices discovered by the specified devices discoverer -func newCreateDRMByPathSymlinks(logger *logrus.Logger, devices Discover, driverRoot string, nvidiaCTKPath string) Discover { +func newCreateDRMByPathSymlinks(logger logger.Interface, devices Discover, driverRoot string, nvidiaCTKPath string) Discover { d := drmDevicesByPath{ logger: logger, nvidiaCTKPath: nvidiaCTKPath, @@ -181,7 +181,7 @@ func (d drmDevicesByPath) getSpecificLinkArgs(devices []Device) ([]string, error } // newDRMDeviceDiscoverer creates a discoverer for the DRM devices associated with the requested devices. -func newDRMDeviceDiscoverer(logger *logrus.Logger, devices image.VisibleDevices, driverRoot string) (Discover, error) { +func newDRMDeviceDiscoverer(logger logger.Interface, devices image.VisibleDevices, driverRoot string) (Discover, error) { allDevices := NewDeviceDiscoverer( logger, lookup.NewCharDeviceLocator( @@ -211,7 +211,7 @@ func newDRMDeviceDiscoverer(logger *logrus.Logger, devices image.VisibleDevices, } // newDRMDeviceFilter creates a filter that matches DRM devices nodes for the visible devices. -func newDRMDeviceFilter(logger *logrus.Logger, devices image.VisibleDevices, driverRoot string) (Filter, error) { +func newDRMDeviceFilter(logger logger.Interface, devices image.VisibleDevices, driverRoot string) (Filter, error) { gpuInformationPaths, err := proc.GetInformationFilePaths(driverRoot) if err != nil { return nil, fmt.Errorf("failed to read GPU information: %v", err) @@ -256,7 +256,7 @@ var _ Discover = (*xorgHooks)(nil) // optionalXorgDiscoverer creates a discoverer for Xorg libraries. // If the creation of the discoverer fails, a None discoverer is returned. -func optionalXorgDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string) Discover { +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) @@ -265,7 +265,7 @@ func optionalXorgDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKP return xorg } -func newXorgDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string) (Discover, error) { +func newXorgDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) (Discover, error) { libCudaPaths, err := cuda.New( cuda.WithLogger(logger), cuda.WithDriverRoot(driverRoot), diff --git a/internal/discover/icp_test.go b/internal/discover/icp_test.go index d2318b44..6769886c 100644 --- a/internal/discover/icp_test.go +++ b/internal/discover/icp_test.go @@ -20,14 +20,15 @@ import ( "testing" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" + testlog "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" ) func TestIPCMounts(t *testing.T) { + logger, _ := testlog.NewNullLogger() l := ipcMounts( mounts{ - logger: logrus.New(), + logger: logger, lookup: &lookup.LocatorMock{ LocateFunc: func(path string) ([]string, error) { return []string{"/host/path"}, nil diff --git a/internal/discover/ipc.go b/internal/discover/ipc.go index 0604a522..9b0fc11c 100644 --- a/internal/discover/ipc.go +++ b/internal/discover/ipc.go @@ -17,14 +17,14 @@ package discover import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) type ipcMounts mounts // NewIPCDiscoverer creats a discoverer for NVIDIA IPC sockets. -func NewIPCDiscoverer(logger *logrus.Logger, driverRoot string) (Discover, error) { +func NewIPCDiscoverer(logger logger.Interface, driverRoot string) (Discover, error) { sockets := newMounts( logger, lookup.NewFileLocator( diff --git a/internal/discover/ldconfig.go b/internal/discover/ldconfig.go index a1c237e0..1a4c5955 100644 --- a/internal/discover/ldconfig.go +++ b/internal/discover/ldconfig.go @@ -21,11 +21,11 @@ import ( "path/filepath" "strings" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) // NewLDCacheUpdateHook creates a discoverer that updates the ldcache for the specified mounts. A logger can also be specified -func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, nvidiaCTKPath string) (Discover, error) { +func NewLDCacheUpdateHook(logger logger.Interface, mounts Discover, nvidiaCTKPath string) (Discover, error) { d := ldconfig{ logger: logger, nvidiaCTKPath: nvidiaCTKPath, @@ -37,7 +37,7 @@ func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, nvidiaCTKPath type ldconfig struct { None - logger *logrus.Logger + logger logger.Interface nvidiaCTKPath string mountsFrom Discover } diff --git a/internal/discover/mofed.go b/internal/discover/mofed.go index c48725e2..c893db3b 100644 --- a/internal/discover/mofed.go +++ b/internal/discover/mofed.go @@ -16,12 +16,10 @@ package discover -import ( - "github.com/sirupsen/logrus" -) +import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" // NewMOFEDDiscoverer creates a discoverer for MOFED devices. -func NewMOFEDDiscoverer(logger *logrus.Logger, root string) (Discover, error) { +func NewMOFEDDiscoverer(logger logger.Interface, root string) (Discover, error) { devices := NewCharDeviceDiscoverer( logger, []string{ diff --git a/internal/discover/mounts.go b/internal/discover/mounts.go index e60ecba0..62a44d1e 100644 --- a/internal/discover/mounts.go +++ b/internal/discover/mounts.go @@ -22,8 +22,8 @@ import ( "strings" "sync" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) // mounts is a generic discoverer for Mounts. It is customized by specifying the @@ -31,7 +31,7 @@ import ( // based on the entry in the list. type mounts struct { None - logger *logrus.Logger + logger logger.Interface lookup lookup.Locator root string required []string @@ -42,12 +42,12 @@ type mounts struct { var _ Discover = (*mounts)(nil) // NewMounts creates a discoverer for the required mounts using the specified locator. -func NewMounts(logger *logrus.Logger, lookup lookup.Locator, root string, required []string) Discover { +func NewMounts(logger logger.Interface, lookup lookup.Locator, root string, required []string) Discover { return newMounts(logger, lookup, root, required) } // newMounts creates a discoverer for the required mounts using the specified locator. -func newMounts(logger *logrus.Logger, lookup lookup.Locator, root string, required []string) *mounts { +func newMounts(logger logger.Interface, lookup lookup.Locator, root string, required []string) *mounts { return &mounts{ logger: logger, lookup: lookup, diff --git a/internal/discover/symlinks.go b/internal/discover/symlinks.go index a9e15d8e..485f2353 100644 --- a/internal/discover/symlinks.go +++ b/internal/discover/symlinks.go @@ -22,14 +22,14 @@ import ( "strings" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks" - "github.com/sirupsen/logrus" ) type symlinkHook struct { None - logger *logrus.Logger + logger logger.Interface driverRoot string nvidiaCTKPath string csvFiles []string @@ -37,7 +37,7 @@ type symlinkHook struct { } // NewCreateSymlinksHook creates a discoverer for a hook that creates required symlinks in the container -func NewCreateSymlinksHook(logger *logrus.Logger, csvFiles []string, mounts Discover, nvidiaCTKPath string) (Discover, error) { +func NewCreateSymlinksHook(logger logger.Interface, csvFiles []string, mounts Discover, nvidiaCTKPath string) (Discover, error) { d := symlinkHook{ logger: logger, nvidiaCTKPath: nvidiaCTKPath, diff --git a/internal/discover/tegra/tegra.go b/internal/discover/tegra/tegra.go index e749b3de..3091c500 100644 --- a/internal/discover/tegra/tegra.go +++ b/internal/discover/tegra/tegra.go @@ -20,12 +20,12 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) type tegraOptions struct { - logger *logrus.Logger + logger logger.Interface csvFiles []string driverRoot string nvidiaCTKPath string @@ -78,7 +78,7 @@ func New(opts ...Option) (discover.Discover, error) { } // WithLogger sets the logger for the discoverer. -func WithLogger(logger *logrus.Logger) Option { +func WithLogger(logger logger.Interface) Option { return func(o *tegraOptions) { o.logger = logger } diff --git a/internal/edits/edits.go b/internal/edits/edits.go index 425e01a8..492845d1 100644 --- a/internal/edits/edits.go +++ b/internal/edits/edits.go @@ -20,21 +20,21 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/container-orchestrated-devices/container-device-interface/specs-go" ociSpecs "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) type edits struct { cdi.ContainerEdits - logger *logrus.Logger + logger logger.Interface } // NewSpecEdits creates a SpecModifier that defines the required OCI spec edits (as CDI ContainerEdits) from the specified // discoverer. -func NewSpecEdits(logger *logrus.Logger, d discover.Discover) (oci.SpecModifier, error) { +func NewSpecEdits(logger logger.Interface, d discover.Discover) (oci.SpecModifier, error) { c, err := FromDiscoverer(d) if err != nil { return nil, fmt.Errorf("error constructing container edits: %v", err) diff --git a/internal/ldcache/ldcache.go b/internal/ldcache/ldcache.go index 96e52675..7673a49a 100644 --- a/internal/ldcache/ldcache.go +++ b/internal/ldcache/ldcache.go @@ -29,8 +29,8 @@ import ( "syscall" "unsafe" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks" - log "github.com/sirupsen/logrus" ) const ldcachePath = "/etc/ld.so.cache" @@ -94,11 +94,11 @@ type ldcache struct { entries []entry2 root string - logger *log.Logger + logger logger.Interface } // New creates a new LDCache with the specified logger and root. -func New(logger *log.Logger, root string) (LDCache, error) { +func New(logger logger.Interface, root string) (LDCache, error) { path := filepath.Join(root, ldcachePath) logger.Debugf("Opening ld.conf at %v", path) diff --git a/internal/logger/api.go b/internal/logger/api.go new file mode 100644 index 00000000..5bb365d9 --- /dev/null +++ b/internal/logger/api.go @@ -0,0 +1,28 @@ +/** +# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +**/ + +package logger + +// Interface defines the API for the logger package +type Interface interface { + Debugf(string, ...interface{}) + Errorf(string, ...interface{}) + Info(...interface{}) + Infof(string, ...interface{}) + Warn(...interface{}) + Warnf(string, ...interface{}) + Warningf(string, ...interface{}) +} diff --git a/internal/logger/lib.go b/internal/logger/lib.go new file mode 100644 index 00000000..f9e46b64 --- /dev/null +++ b/internal/logger/lib.go @@ -0,0 +1,24 @@ +/** +# Copyright (c) NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +**/ + +package logger + +import "github.com/sirupsen/logrus" + +// New returns a new logger +func New() Interface { + return logrus.StandardLogger() +} diff --git a/internal/lookup/cuda/cuda.go b/internal/lookup/cuda/cuda.go index 35688eea..100dbdf2 100644 --- a/internal/lookup/cuda/cuda.go +++ b/internal/lookup/cuda/cuda.go @@ -19,12 +19,12 @@ package cuda import ( "path/filepath" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) type cudaLocator struct { - logger *logrus.Logger + logger logger.Interface driverRoot string } @@ -32,7 +32,7 @@ type cudaLocator struct { type Options func(*cudaLocator) // WithLogger is an option that configures the logger used by the locator. -func WithLogger(logger *logrus.Logger) Options { +func WithLogger(logger logger.Interface) Options { return func(c *cudaLocator) { c.logger = logger } @@ -53,7 +53,7 @@ func New(opts ...Options) lookup.Locator { } if c.logger == nil { - c.logger = logrus.StandardLogger() + c.logger = logger.New() } if c.driverRoot == "" { c.driverRoot = "/" diff --git a/internal/lookup/dir.go b/internal/lookup/dir.go index 87b32507..cf6eeb0b 100644 --- a/internal/lookup/dir.go +++ b/internal/lookup/dir.go @@ -20,12 +20,12 @@ import ( "fmt" "os" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) // NewDirectoryLocator creates a Locator that can be used to find directories at the specified root. A logger // is also specified. -func NewDirectoryLocator(logger *log.Logger, root string) Locator { +func NewDirectoryLocator(logger logger.Interface, root string) Locator { return NewFileLocator( WithLogger(logger), WithRoot(root), diff --git a/internal/lookup/executable.go b/internal/lookup/executable.go index 08316ed3..b94e850a 100644 --- a/internal/lookup/executable.go +++ b/internal/lookup/executable.go @@ -21,7 +21,7 @@ import ( "os" "strings" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) type executable struct { @@ -29,13 +29,13 @@ type executable struct { } // NewExecutableLocator creates a locator to fine executable files in the path. A logger can also be specified. -func NewExecutableLocator(logger *log.Logger, root string) Locator { +func NewExecutableLocator(logger logger.Interface, root string) Locator { paths := GetPaths(root) return newExecutableLocator(logger, root, paths...) } -func newExecutableLocator(logger *log.Logger, root string, paths ...string) *executable { +func newExecutableLocator(logger logger.Interface, root string, paths ...string) *executable { f := newFileLocator( WithLogger(logger), WithRoot(root), diff --git a/internal/lookup/file.go b/internal/lookup/file.go index c382c468..d6fb5825 100644 --- a/internal/lookup/file.go +++ b/internal/lookup/file.go @@ -21,13 +21,13 @@ import ( "os" "path/filepath" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) // file can be used to locate file (or file-like elements) at a specified set of // prefixes. The validity of a file is determined by a filter function. type file struct { - logger *log.Logger + logger logger.Interface root string prefixes []string filter func(string) error @@ -46,7 +46,7 @@ func WithRoot(root string) Option { } // WithLogger sets the logger for the file locator -func WithLogger(logger *log.Logger) Option { +func WithLogger(logger logger.Interface) Option { return func(f *file) { f.logger = logger } @@ -93,7 +93,7 @@ func newFileLocator(opts ...Option) *file { opt(f) } if f.logger == nil { - f.logger = log.StandardLogger() + f.logger = logger.New() } if f.filter == nil { f.filter = assertFile diff --git a/internal/lookup/library.go b/internal/lookup/library.go index 225b9f55..e1fd9756 100644 --- a/internal/lookup/library.go +++ b/internal/lookup/library.go @@ -21,11 +21,11 @@ import ( "strings" "github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) type library struct { - logger *log.Logger + logger logger.Interface symlink Locator cache ldcache.LDCache } @@ -33,7 +33,7 @@ type library struct { var _ Locator = (*library)(nil) // NewLibraryLocator creates a library locator using the specified logger. -func NewLibraryLocator(logger *log.Logger, root string) (Locator, error) { +func NewLibraryLocator(logger logger.Interface, root string) (Locator, error) { cache, err := ldcache.New(logger, root) if err != nil { return nil, fmt.Errorf("error loading ldcache: %v", err) diff --git a/internal/lookup/symlinks.go b/internal/lookup/symlinks.go index 438e42d5..27fd9096 100644 --- a/internal/lookup/symlinks.go +++ b/internal/lookup/symlinks.go @@ -20,8 +20,8 @@ import ( "fmt" "path/filepath" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks" - "github.com/sirupsen/logrus" ) type symlinkChain struct { @@ -34,7 +34,7 @@ type symlink struct { // NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks. // A logger can also be specified. -func NewSymlinkChainLocator(logger *logrus.Logger, root string) Locator { +func NewSymlinkChainLocator(logger logger.Interface, root string) Locator { f := newFileLocator(WithLogger(logger), WithRoot(root)) l := symlinkChain{ file: *f, @@ -45,7 +45,7 @@ func NewSymlinkChainLocator(logger *logrus.Logger, root string) Locator { // NewSymlinkLocator creats a locator that can be used for locating files through symlinks. // A logger can also be specified. -func NewSymlinkLocator(logger *logrus.Logger, root string) Locator { +func NewSymlinkLocator(logger logger.Interface, root string) Locator { f := newFileLocator(WithLogger(logger), WithRoot(root)) l := symlink{ file: *f, diff --git a/internal/modifier/cdi.go b/internal/modifier/cdi.go index 879967b9..eba2d6f0 100644 --- a/internal/modifier/cdi.go +++ b/internal/modifier/cdi.go @@ -22,14 +22,14 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) type cdiModifier struct { - logger *logrus.Logger + logger logger.Interface specDirs []string devices []string } @@ -37,7 +37,7 @@ type cdiModifier struct { // NewCDIModifier creates an OCI spec modifier that determines the modifications to make based on the // CDI specifications available on the system. The NVIDIA_VISIBLE_DEVICES enviroment variable is // used to select the devices to include. -func NewCDIModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { +func NewCDIModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { devices, err := getDevicesFromSpec(logger, ociSpec, cfg) if err != nil { return nil, fmt.Errorf("failed to get required devices from OCI specification: %v", err) @@ -62,7 +62,7 @@ func NewCDIModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) return m, nil } -func getDevicesFromSpec(logger *logrus.Logger, ociSpec oci.Spec, cfg *config.Config) ([]string, error) { +func getDevicesFromSpec(logger logger.Interface, ociSpec oci.Spec, cfg *config.Config) ([]string, error) { rawSpec, err := ociSpec.Load() if err != nil { return nil, fmt.Errorf("failed to load OCI spec: %v", err) diff --git a/internal/modifier/csv.go b/internal/modifier/csv.go index 84eb0c6d..d944bc20 100644 --- a/internal/modifier/csv.go +++ b/internal/modifier/csv.go @@ -25,14 +25,14 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/tegra" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/NVIDIA/nvidia-container-toolkit/internal/requirements" - "github.com/sirupsen/logrus" ) // csvMode represents the modifications as performed by the csv runtime mode type csvMode struct { - logger *logrus.Logger + logger logger.Interface discoverer discover.Discover } @@ -45,7 +45,7 @@ const ( // NewCSVModifier creates a modifier that applies modications to an OCI spec if required by the runtime wrapper. // The modifications are defined by CSV MountSpecs. -func NewCSVModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { +func NewCSVModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { rawSpec, err := ociSpec.Load() if err != nil { return nil, fmt.Errorf("failed to load OCI spec: %v", err) @@ -98,7 +98,7 @@ func NewCSVModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) return modifiers, nil } -func checkRequirements(logger *logrus.Logger, image image.CUDA) error { +func checkRequirements(logger logger.Interface, image image.CUDA) error { if image.HasDisableRequire() { // TODO: We could print the real value here instead logger.Debugf("NVIDIA_DISABLE_REQUIRE=%v; skipping requirement checks", true) diff --git a/internal/modifier/discover.go b/internal/modifier/discover.go index 475b7469..2dfa1129 100644 --- a/internal/modifier/discover.go +++ b/internal/modifier/discover.go @@ -21,19 +21,19 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" "github.com/NVIDIA/nvidia-container-toolkit/internal/edits" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) type discoverModifier struct { - logger *logrus.Logger + logger logger.Interface discoverer discover.Discover } // NewModifierFromDiscoverer creates a modifier that applies the discovered // modifications to an OCI spec if required by the runtime wrapper. -func NewModifierFromDiscoverer(logger *logrus.Logger, d discover.Discover) (oci.SpecModifier, error) { +func NewModifierFromDiscoverer(logger logger.Interface, d discover.Discover) (oci.SpecModifier, error) { m := discoverModifier{ logger: logger, discoverer: d, diff --git a/internal/modifier/gds.go b/internal/modifier/gds.go index 78c0e38a..5334346c 100644 --- a/internal/modifier/gds.go +++ b/internal/modifier/gds.go @@ -22,8 +22,8 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" ) const ( @@ -32,7 +32,7 @@ const ( // NewGDSModifier creates the modifiers for GDS devices. // If the spec does not contain the NVIDIA_GDS=enabled environment variable no changes are made. -func NewGDSModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { +func NewGDSModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { rawSpec, err := ociSpec.Load() if err != nil { return nil, fmt.Errorf("failed to load OCI spec: %v", err) diff --git a/internal/modifier/graphics.go b/internal/modifier/graphics.go index ec4750d0..e80de124 100644 --- a/internal/modifier/graphics.go +++ b/internal/modifier/graphics.go @@ -22,13 +22,13 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" ) // NewGraphicsModifier constructs a modifier that injects graphics-related modifications into an OCI runtime specification. // The value of the NVIDIA_DRIVER_CAPABILITIES environment variable is checked to determine if this modification should be made. -func NewGraphicsModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { +func NewGraphicsModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { rawSpec, err := ociSpec.Load() if err != nil { return nil, fmt.Errorf("failed to load OCI spec: %v", err) diff --git a/internal/modifier/hook_remover.go b/internal/modifier/hook_remover.go index c737bdcc..f92011fd 100644 --- a/internal/modifier/hook_remover.go +++ b/internal/modifier/hook_remover.go @@ -20,14 +20,14 @@ import ( "path/filepath" "github.com/NVIDIA/nvidia-container-toolkit/internal/config" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) // nvidiaContainerRuntimeHookRemover is a spec modifer that detects and removes inserted nvidia-container-runtime hooks type nvidiaContainerRuntimeHookRemover struct { - logger *logrus.Logger + logger logger.Interface } var _ oci.SpecModifier = (*nvidiaContainerRuntimeHookRemover)(nil) diff --git a/internal/modifier/mofed.go b/internal/modifier/mofed.go index abdf8baf..92796506 100644 --- a/internal/modifier/mofed.go +++ b/internal/modifier/mofed.go @@ -22,8 +22,8 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/config/image" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" ) const ( @@ -32,7 +32,7 @@ const ( // NewMOFEDModifier creates the modifiers for MOFED devices. // If the spec does not contain the NVIDIA_MOFED=enabled environment variable no changes are made. -func NewMOFEDModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { +func NewMOFEDModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spec) (oci.SpecModifier, error) { rawSpec, err := ociSpec.Load() if err != nil { return nil, fmt.Errorf("failed to load OCI spec: %v", err) diff --git a/internal/modifier/stable.go b/internal/modifier/stable.go index 8281ce89..44dbc094 100644 --- a/internal/modifier/stable.go +++ b/internal/modifier/stable.go @@ -19,14 +19,14 @@ package modifier import ( "path/filepath" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) // NewStableRuntimeModifier creates an OCI spec modifier that inserts the NVIDIA Container Runtime Hook into an OCI // spec. The specified logger is used to capture log output. -func NewStableRuntimeModifier(logger *logrus.Logger, nvidiaContainerRuntimeHookPath string) oci.SpecModifier { +func NewStableRuntimeModifier(logger logger.Interface, nvidiaContainerRuntimeHookPath string) oci.SpecModifier { m := stableRuntimeModifier{ logger: logger, nvidiaContainerRuntimeHookPath: nvidiaContainerRuntimeHookPath, @@ -38,7 +38,7 @@ func NewStableRuntimeModifier(logger *logrus.Logger, nvidiaContainerRuntimeHookP // stableRuntimeModifier modifies an OCI spec inplace, inserting the nvidia-container-runtime-hook as a // prestart hook. If the hook is already present, no modification is made. type stableRuntimeModifier struct { - logger *logrus.Logger + logger logger.Interface nvidiaContainerRuntimeHookPath string } diff --git a/internal/modifier/stable_test.go b/internal/modifier/stable_test.go index 0b8eaff9..283b9e8b 100644 --- a/internal/modifier/stable_test.go +++ b/internal/modifier/stable_test.go @@ -17,13 +17,13 @@ package modifier import ( + "log" "os" "path/filepath" "testing" "github.com/NVIDIA/nvidia-container-toolkit/internal/test" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" testlog "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" ) @@ -41,7 +41,7 @@ func TestMain(m *testing.M) { var err error moduleRoot, err := test.GetModuleRoot() if err != nil { - logrus.Fatalf("error in test setup: could not get module root: %v", err) + log.Fatalf("error in test setup: could not get module root: %v", err) } testBinPath := filepath.Join(moduleRoot, "test", "bin") diff --git a/internal/oci/runtime_low_level.go b/internal/oci/runtime_low_level.go index 795c4e14..4150eb52 100644 --- a/internal/oci/runtime_low_level.go +++ b/internal/oci/runtime_low_level.go @@ -19,14 +19,14 @@ package oci import ( "fmt" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - log "github.com/sirupsen/logrus" ) // NewLowLevelRuntime creates a Runtime that wraps a low-level runtime executable. // The executable specified is taken from the list of supplied candidates, with the first match // present in the PATH being selected. A logger is also specified. -func NewLowLevelRuntime(logger *log.Logger, candidates []string) (Runtime, error) { +func NewLowLevelRuntime(logger logger.Interface, candidates []string) (Runtime, error) { runtimePath, err := findRuntime(logger, candidates) if err != nil { return nil, fmt.Errorf("error locating runtime: %v", err) @@ -38,7 +38,7 @@ func NewLowLevelRuntime(logger *log.Logger, candidates []string) (Runtime, error // findRuntime checks elements in a list of supplied candidates for a matching executable in the PATH. // The absolute path to the first match is returned. -func findRuntime(logger *log.Logger, candidates []string) (string, error) { +func findRuntime(logger logger.Interface, candidates []string) (string, error) { if len(candidates) == 0 { return "", fmt.Errorf("at least one runtime candidate must be specified") } diff --git a/internal/oci/runtime_modifier.go b/internal/oci/runtime_modifier.go index 2a61445d..797f5cd9 100644 --- a/internal/oci/runtime_modifier.go +++ b/internal/oci/runtime_modifier.go @@ -19,11 +19,11 @@ package oci import ( "fmt" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) type modifyingRuntimeWrapper struct { - logger *log.Logger + logger logger.Interface runtime Runtime ociSpec Spec modifier SpecModifier @@ -33,7 +33,7 @@ var _ Runtime = (*modifyingRuntimeWrapper)(nil) // NewModifyingRuntimeWrapper creates a runtime wrapper that applies the specified modifier to the OCI specification // before invoking the wrapped runtime. If the modifier is nil, the input runtime is returned. -func NewModifyingRuntimeWrapper(logger *log.Logger, runtime Runtime, spec Spec, modifier SpecModifier) Runtime { +func NewModifyingRuntimeWrapper(logger logger.Interface, runtime Runtime, spec Spec, modifier SpecModifier) Runtime { if modifier == nil { logger.Infof("Using low-level runtime with no modification") return runtime diff --git a/internal/oci/runtime_path.go b/internal/oci/runtime_path.go index 102e84f6..948312f3 100644 --- a/internal/oci/runtime_path.go +++ b/internal/oci/runtime_path.go @@ -20,14 +20,14 @@ import ( "fmt" "os" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) // pathRuntime wraps the path that a binary and defines the semanitcs for how to exec into it. // This can be used to wrap an OCI-compliant low-level runtime binary, allowing it to be used through the // Runtime internface. type pathRuntime struct { - logger *log.Logger + logger logger.Interface path string execRuntime Runtime } @@ -35,7 +35,7 @@ type pathRuntime struct { var _ Runtime = (*pathRuntime)(nil) // NewRuntimeForPath creates a Runtime for the specified logger and path -func NewRuntimeForPath(logger *log.Logger, path string) (Runtime, error) { +func NewRuntimeForPath(logger logger.Interface, path string) (Runtime, error) { info, err := os.Stat(path) if err != nil { return nil, fmt.Errorf("invalid path '%v': %v", path, err) diff --git a/internal/oci/spec.go b/internal/oci/spec.go index bfd7465f..dedf794c 100644 --- a/internal/oci/spec.go +++ b/internal/oci/spec.go @@ -19,8 +19,8 @@ package oci import ( "fmt" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" ) // SpecModifier defines an interace for modifying a (raw) OCI spec @@ -42,7 +42,7 @@ type Spec interface { // NewSpec creates fileSpec based on the command line arguments passed to the // application using the specified logger. -func NewSpec(logger *logrus.Logger, args []string) (Spec, error) { +func NewSpec(logger logger.Interface, args []string) (Spec, error) { bundleDir, err := GetBundleDir(args) if err != nil { return nil, fmt.Errorf("error getting bundle directory: %v", err) diff --git a/internal/requirements/constraints/factory.go b/internal/requirements/constraints/factory.go index 29227c66..d874bdaa 100644 --- a/internal/requirements/constraints/factory.go +++ b/internal/requirements/constraints/factory.go @@ -20,16 +20,16 @@ import ( "fmt" "strings" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) type factory struct { - logger *logrus.Logger + logger logger.Interface properties map[string]Property } // New creates a new constraint for the supplied requirements and properties -func New(logger *logrus.Logger, requirements []string, properties map[string]Property) (Constraint, error) { +func New(logger logger.Interface, requirements []string, properties map[string]Property) (Constraint, error) { if len(requirements) == 0 { return &always{}, nil } diff --git a/internal/requirements/requirements.go b/internal/requirements/requirements.go index 5305ce28..55373ad2 100644 --- a/internal/requirements/requirements.go +++ b/internal/requirements/requirements.go @@ -17,19 +17,19 @@ package requirements import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/requirements/constraints" - "github.com/sirupsen/logrus" ) // Requirements represents a collection of requirements that can be compared to properties type Requirements struct { - logger *logrus.Logger + logger logger.Interface requirements []string properties map[string]constraints.Property } // New creates a new set of requirements -func New(logger *logrus.Logger, requirements []string) *Requirements { +func New(logger logger.Interface, requirements []string) *Requirements { r := Requirements{ logger: logger, requirements: requirements, diff --git a/internal/runtime/logger.go b/internal/runtime/logger.go index b3122acc..ee946dbd 100644 --- a/internal/runtime/logger.go +++ b/internal/runtime/logger.go @@ -26,20 +26,21 @@ import ( "strconv" "strings" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/sirupsen/logrus" ) // Logger adds a way to manage output to a log file to a logrus.Logger type Logger struct { - *logrus.Logger - previousLogger *logrus.Logger + logger.Interface + previousLogger logger.Interface logFiles []*os.File } // NewLogger creates an empty logger func NewLogger() *Logger { return &Logger{ - Logger: logrus.New(), + Interface: logrus.New(), } } @@ -116,8 +117,8 @@ func (l *Logger) Update(filename string, logLevel string, argv []string) { } *l = Logger{ - Logger: newLogger, - previousLogger: l.Logger, + Interface: newLogger, + previousLogger: l.Interface, logFiles: logFiles, } } @@ -130,7 +131,7 @@ func (l *Logger) Reset() error { if previous == nil { previous = logrus.New() } - l.Logger = previous + l.Interface = previous l.previousLogger = nil l.logFiles = nil }() diff --git a/internal/runtime/logger_test.go b/internal/runtime/logger_test.go index 6999b9d4..e0c27f48 100644 --- a/internal/runtime/logger_test.go +++ b/internal/runtime/logger_test.go @@ -28,7 +28,9 @@ func TestLogger(t *testing.T) { l.Update("", "debug", nil) - require.Equal(t, logrus.DebugLevel, l.Logger.Level) - require.Equal(t, logrus.InfoLevel, l.previousLogger.Level) + ll := l.Interface.(*logrus.Logger) + require.Equal(t, logrus.DebugLevel, ll.Level) + lp := l.previousLogger.(*logrus.Logger) + require.Equal(t, logrus.InfoLevel, lp.Level) } diff --git a/internal/runtime/runtime.go b/internal/runtime/runtime.go index 1866ca0c..e43c778a 100644 --- a/internal/runtime/runtime.go +++ b/internal/runtime/runtime.go @@ -61,8 +61,8 @@ func (r rt) Run(argv []string) (rerr error) { if r.modeOverride != "" { cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride } - cfg.NVIDIACTKConfig.Path = config.ResolveNVIDIACTKPath(r.logger.Logger, cfg.NVIDIACTKConfig.Path) - cfg.NVIDIAContainerRuntimeHookConfig.Path = config.ResolveNVIDIAContainerRuntimeHookPath(r.logger.Logger, cfg.NVIDIAContainerRuntimeHookConfig.Path) + cfg.NVIDIACTKConfig.Path = config.ResolveNVIDIACTKPath(r.logger, cfg.NVIDIACTKConfig.Path) + cfg.NVIDIAContainerRuntimeHookConfig.Path = config.ResolveNVIDIAContainerRuntimeHookPath(r.logger, cfg.NVIDIAContainerRuntimeHookConfig.Path) // Print the config to the output. configJSON, err := json.MarshalIndent(cfg, "", " ") @@ -73,7 +73,7 @@ func (r rt) Run(argv []string) (rerr error) { } r.logger.Debugf("Command line arguments: %v", argv) - runtime, err := newNVIDIAContainerRuntime(r.logger.Logger, cfg, argv) + runtime, err := newNVIDIAContainerRuntime(r.logger, cfg, argv) if err != nil { return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err) } diff --git a/internal/runtime/runtime_factory.go b/internal/runtime/runtime_factory.go index a417907e..dd1a847a 100644 --- a/internal/runtime/runtime_factory.go +++ b/internal/runtime/runtime_factory.go @@ -21,13 +21,13 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/info" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/modifier" "github.com/NVIDIA/nvidia-container-toolkit/internal/oci" - "github.com/sirupsen/logrus" ) // newNVIDIAContainerRuntime is a factory method that constructs a runtime based on the selected configuration and specified logger -func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv []string) (oci.Runtime, error) { +func newNVIDIAContainerRuntime(logger logger.Interface, cfg *config.Config, argv []string) (oci.Runtime, error) { lowLevelRuntime, err := oci.NewLowLevelRuntime(logger, cfg.NVIDIAContainerRuntimeConfig.Runtimes) if err != nil { return nil, fmt.Errorf("error constructing low-level runtime: %v", err) @@ -60,7 +60,7 @@ func newNVIDIAContainerRuntime(logger *logrus.Logger, cfg *config.Config, argv [ } // newSpecModifier is a factory method that creates constructs an OCI spec modifer based on the provided config. -func newSpecModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec, argv []string) (oci.SpecModifier, error) { +func newSpecModifier(logger logger.Interface, cfg *config.Config, ociSpec oci.Spec, argv []string) (oci.SpecModifier, error) { mode := info.ResolveAutoMode(logger, cfg.NVIDIAContainerRuntimeConfig.Mode) modeModifier, err := newModeModifier(logger, mode, cfg, ociSpec, argv) if err != nil { @@ -95,7 +95,7 @@ func newSpecModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec return modifiers, nil } -func newModeModifier(logger *logrus.Logger, mode string, cfg *config.Config, ociSpec oci.Spec, argv []string) (oci.SpecModifier, error) { +func newModeModifier(logger logger.Interface, mode string, cfg *config.Config, ociSpec oci.Spec, argv []string) (oci.SpecModifier, error) { switch mode { case "legacy": return modifier.NewStableRuntimeModifier(logger, cfg.NVIDIAContainerRuntimeHookConfig.Path), nil diff --git a/internal/runtime/runtime_factory_test.go b/internal/runtime/runtime_factory_test.go index 7f443e82..2b783aa0 100644 --- a/internal/runtime/runtime_factory_test.go +++ b/internal/runtime/runtime_factory_test.go @@ -18,6 +18,7 @@ package runtime import ( "encoding/json" + "log" "os" "os/exec" "path/filepath" @@ -26,7 +27,6 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/config" "github.com/NVIDIA/nvidia-container-toolkit/internal/test" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/sirupsen/logrus" testlog "github.com/sirupsen/logrus/hooks/test" "github.com/stretchr/testify/require" ) @@ -41,7 +41,7 @@ func TestMain(m *testing.M) { var err error moduleRoot, err := test.GetModuleRoot() if err != nil { - logrus.Fatalf("error in test setup: could not get module root: %v", err) + log.Fatalf("error in test setup: could not get module root: %v", err) } testBinPath := filepath.Join(moduleRoot, "test", "bin") @@ -51,7 +51,7 @@ func TestMain(m *testing.M) { // Confirm that the environment is configured correctly runcPath, err := exec.LookPath(runcExecutableName) if err != nil || filepath.Join(testBinPath, runcExecutableName) != runcPath { - logrus.Fatalf("error in test setup: mock runc path set incorrectly in TestMain(): %v", err) + log.Fatalf("error in test setup: mock runc path set incorrectly in TestMain(): %v", err) } // RUN TESTS diff --git a/internal/system/options.go b/internal/system/options.go index de3bf21d..5d261f0d 100644 --- a/internal/system/options.go +++ b/internal/system/options.go @@ -16,13 +16,13 @@ package system -import "github.com/sirupsen/logrus" +import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" // Option is a functional option for the system command type Option func(*Interface) // WithLogger sets the logger for the system command -func WithLogger(logger *logrus.Logger) Option { +func WithLogger(logger logger.Interface) Option { return func(i *Interface) { i.logger = logger } diff --git a/internal/system/system.go b/internal/system/system.go index fe745160..df39de9d 100644 --- a/internal/system/system.go +++ b/internal/system/system.go @@ -24,13 +24,13 @@ import ( "strings" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc/devices" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "golang.org/x/sys/unix" ) // Interface is the interface for the system command type Interface struct { - logger *logrus.Logger + logger logger.Interface dryRun bool loadKernelModules bool nvidiaDevices nvidiaDevices @@ -39,7 +39,7 @@ type Interface struct { // New constructs a system command with the specified options func New(opts ...Option) (*Interface, error) { i := &Interface{ - logger: logrus.StandardLogger(), + logger: logger.New(), } for _, opt := range opts { opt(i) diff --git a/pkg/config/engine/crio/option.go b/pkg/config/engine/crio/option.go index af4e7ef7..82d3af32 100644 --- a/pkg/config/engine/crio/option.go +++ b/pkg/config/engine/crio/option.go @@ -20,12 +20,14 @@ import ( "fmt" "os" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/pelletier/go-toml" log "github.com/sirupsen/logrus" ) type builder struct { - path string + logger logger.Interface + path string } // Option defines a function that can be used to configure the config builder @@ -43,13 +45,16 @@ func (b *builder) build() (*Config, error) { empty := toml.Tree{} return (*Config)(&empty), nil } + if b.logger == nil { + b.logger = logger.New() + } - return loadConfig(b.path) + return b.loadConfig(b.path) } // loadConfig loads the cri-o config from disk -func loadConfig(config string) (*Config, error) { - log.Infof("Loading config: %v", config) +func (b *builder) loadConfig(config string) (*Config, error) { + b.logger.Infof("Loading config: %v", config) info, err := os.Stat(config) if os.IsExist(err) && info.IsDir() { @@ -67,7 +72,7 @@ func loadConfig(config string) (*Config, error) { return nil, err } - log.Infof("Successfully loaded config") + b.logger.Infof("Successfully loaded config") return (*Config)(cfg), nil } diff --git a/pkg/nvcdi/common-nvml.go b/pkg/nvcdi/common-nvml.go index 88ebec7d..7768f54e 100644 --- a/pkg/nvcdi/common-nvml.go +++ b/pkg/nvcdi/common-nvml.go @@ -20,15 +20,15 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml" ) // newCommonNVMLDiscoverer returns a discoverer for entities that are not associated with a specific CDI device. // This includes driver libraries and meta devices, for example. -func newCommonNVMLDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, nvmllib nvml.Interface) (discover.Discover, error) { +func newCommonNVMLDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, nvmllib nvml.Interface) (discover.Discover, error) { metaDevices := discover.NewDeviceDiscoverer( logger, lookup.NewCharDeviceLocator( diff --git a/pkg/nvcdi/device-wsl.go b/pkg/nvcdi/device-wsl.go index 6acbb4b4..418016b5 100644 --- a/pkg/nvcdi/device-wsl.go +++ b/pkg/nvcdi/device-wsl.go @@ -18,7 +18,7 @@ package nvcdi import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) const ( @@ -26,7 +26,7 @@ const ( ) // newDXGDeviceDiscoverer returns a Discoverer for DXG devices under WSL2. -func newDXGDeviceDiscoverer(logger *logrus.Logger, driverRoot string) discover.Discover { +func newDXGDeviceDiscoverer(logger logger.Interface, driverRoot string) discover.Discover { deviceNodes := discover.NewCharDeviceDiscoverer( logger, []string{dxgDeviceNode}, diff --git a/pkg/nvcdi/driver-nvml.go b/pkg/nvcdi/driver-nvml.go index c0dc1445..17456779 100644 --- a/pkg/nvcdi/driver-nvml.go +++ b/pkg/nvcdi/driver-nvml.go @@ -22,15 +22,15 @@ import ( "strings" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml" ) // NewDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation. // The supplied NVML Library is used to query the expected driver version. -func NewDriverDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, nvmllib nvml.Interface) (discover.Discover, error) { +func NewDriverDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, nvmllib nvml.Interface) (discover.Discover, error) { if r := nvmllib.Init(); r != nvml.SUCCESS { return nil, fmt.Errorf("failed to initalize NVML: %v", r) } @@ -44,7 +44,7 @@ func NewDriverDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath return newDriverVersionDiscoverer(logger, driverRoot, nvidiaCTKPath, version) } -func newDriverVersionDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, version string) (discover.Discover, error) { +func newDriverVersionDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, version string) (discover.Discover, error) { libraries, err := NewDriverLibraryDiscoverer(logger, driverRoot, nvidiaCTKPath, version) if err != nil { return nil, fmt.Errorf("failed to create discoverer for driver libraries: %v", err) @@ -70,7 +70,7 @@ func newDriverVersionDiscoverer(logger *logrus.Logger, driverRoot string, nvidia } // NewDriverLibraryDiscoverer creates a discoverer for the libraries associated with the specified driver version. -func NewDriverLibraryDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, version string) (discover.Discover, error) { +func NewDriverLibraryDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, version string) (discover.Discover, error) { libraryPaths, err := getVersionLibs(logger, driverRoot, version) if err != nil { return nil, fmt.Errorf("failed to get libraries for driver version: %v", err) @@ -97,7 +97,7 @@ func NewDriverLibraryDiscoverer(logger *logrus.Logger, driverRoot string, nvidia } // NewDriverFirmwareDiscoverer creates a discoverer for GSP firmware associated with the specified driver version. -func NewDriverFirmwareDiscoverer(logger *logrus.Logger, driverRoot string, version string) discover.Discover { +func NewDriverFirmwareDiscoverer(logger logger.Interface, driverRoot string, version string) discover.Discover { gspFirmwarePath := filepath.Join("/lib/firmware/nvidia", version, "gsp*.bin") return discover.NewMounts( logger, @@ -111,7 +111,7 @@ func NewDriverFirmwareDiscoverer(logger *logrus.Logger, driverRoot string, versi } // NewDriverBinariesDiscoverer creates a discoverer for GSP firmware associated with the GPU driver. -func NewDriverBinariesDiscoverer(logger *logrus.Logger, driverRoot string) discover.Discover { +func NewDriverBinariesDiscoverer(logger logger.Interface, driverRoot string) discover.Discover { return discover.NewMounts( logger, lookup.NewExecutableLocator(logger, driverRoot), @@ -129,7 +129,7 @@ func NewDriverBinariesDiscoverer(logger *logrus.Logger, driverRoot string) disco // getVersionLibs checks the LDCache for libraries ending in the specified driver version. // Although the ldcache at the specified driverRoot is queried, the paths are returned relative to this driverRoot. // This allows the standard mount location logic to be used for resolving the mounts. -func getVersionLibs(logger *logrus.Logger, driverRoot string, version string) ([]string, error) { +func getVersionLibs(logger logger.Interface, driverRoot string, version string) ([]string, error) { logger.Infof("Using driver version %v", version) libCudaPaths, err := cuda.New( diff --git a/pkg/nvcdi/driver-wsl.go b/pkg/nvcdi/driver-wsl.go index fbe0572f..9cf74b0e 100644 --- a/pkg/nvcdi/driver-wsl.go +++ b/pkg/nvcdi/driver-wsl.go @@ -22,8 +22,8 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" "github.com/NVIDIA/nvidia-container-toolkit/internal/dxcore" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" - "github.com/sirupsen/logrus" ) var requiredDriverStoreFiles = []string{ @@ -38,7 +38,7 @@ var requiredDriverStoreFiles = []string{ } // newWSLDriverDiscoverer returns a Discoverer for WSL2 drivers. -func newWSLDriverDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string) (discover.Discover, error) { +func newWSLDriverDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string) (discover.Discover, error) { err := dxcore.Init() if err != nil { return nil, fmt.Errorf("failed to initialize dxcore: %v", err) @@ -55,7 +55,7 @@ func newWSLDriverDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKP } // newWSLDriverStoreDiscoverer returns a Discoverer for WSL2 drivers in the driver store associated with a dxcore adapter. -func newWSLDriverStoreDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, driverStorePaths []string) (discover.Discover, error) { +func newWSLDriverStoreDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, driverStorePaths []string) (discover.Discover, error) { var searchPaths []string seen := make(map[string]bool) for _, path := range driverStorePaths { diff --git a/pkg/nvcdi/full-gpu-nvml.go b/pkg/nvcdi/full-gpu-nvml.go index c588af94..174c5d29 100644 --- a/pkg/nvcdi/full-gpu-nvml.go +++ b/pkg/nvcdi/full-gpu-nvml.go @@ -25,9 +25,9 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" "github.com/NVIDIA/nvidia-container-toolkit/internal/edits" "github.com/NVIDIA/nvidia-container-toolkit/internal/info/drm" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/container-orchestrated-devices/container-device-interface/specs-go" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml" ) @@ -69,7 +69,7 @@ func (l *nvmllib) GetGPUDeviceEdits(d device.Device) (*cdi.ContainerEdits, error // byPathHookDiscoverer discovers the entities required for injecting by-path DRM device links type byPathHookDiscoverer struct { - logger *logrus.Logger + logger logger.Interface driverRoot string nvidiaCTKPath string pciBusID string @@ -79,7 +79,7 @@ type byPathHookDiscoverer struct { var _ discover.Discover = (*byPathHookDiscoverer)(nil) // newFullGPUDiscoverer creates a discoverer for the full GPU defined by the specified device. -func newFullGPUDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, d device.Device) (discover.Discover, error) { +func newFullGPUDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, d device.Device) (discover.Discover, error) { // TODO: The functionality to get device paths should be integrated into the go-nvlib/pkg/device.Device interface. // This will allow reuse here and in other code where the paths are queried such as the NVIDIA device plugin. minor, ret := d.GetMinorNumber() diff --git a/pkg/nvcdi/lib.go b/pkg/nvcdi/lib.go index 7d11a8e2..ad5dd270 100644 --- a/pkg/nvcdi/lib.go +++ b/pkg/nvcdi/lib.go @@ -20,9 +20,9 @@ import ( "fmt" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml" @@ -38,7 +38,7 @@ type wrapper struct { } type nvcdilib struct { - logger *logrus.Logger + logger logger.Interface nvmllib nvml.Interface mode string devicelib device.Interface @@ -66,7 +66,7 @@ func New(opts ...Option) (Interface, error) { l.mode = ModeAuto } if l.logger == nil { - l.logger = logrus.StandardLogger() + l.logger = logger.New() } if l.deviceNamer == nil { l.deviceNamer, _ = NewDeviceNamer(DeviceNameStrategyIndex) diff --git a/pkg/nvcdi/mig-device-nvml.go b/pkg/nvcdi/mig-device-nvml.go index 7864ff91..d5d2bdec 100644 --- a/pkg/nvcdi/mig-device-nvml.go +++ b/pkg/nvcdi/mig-device-nvml.go @@ -21,10 +21,10 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" "github.com/NVIDIA/nvidia-container-toolkit/internal/edits" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/nvcaps" "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi" "github.com/container-orchestrated-devices/container-device-interface/specs-go" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml" ) @@ -75,7 +75,7 @@ func (l *nvmllib) GetMIGDeviceEdits(parent device.Device, mig device.MigDevice) } // GetEditsForComputeInstance returns the CDI edits for a particular compute instance defined by the (gpu, gi, ci) tuple -func GetEditsForComputeInstance(logger *logrus.Logger, driverRoot string, gpu int, gi int, ci int) (*cdi.ContainerEdits, error) { +func GetEditsForComputeInstance(logger logger.Interface, driverRoot string, gpu int, gi int, ci int) (*cdi.ContainerEdits, error) { computeInstance, err := newComputeInstanceDiscoverer(logger, driverRoot, gpu, gi, ci) if err != nil { return nil, fmt.Errorf("failed to create discoverer for Compute Instance: %v", err) @@ -90,7 +90,7 @@ func GetEditsForComputeInstance(logger *logrus.Logger, driverRoot string, gpu in } // newComputeInstanceDiscoverer returns a discoverer for the specified compute instance -func newComputeInstanceDiscoverer(logger *logrus.Logger, driverRoot string, gpu int, gi int, ci int) (discover.Discover, error) { +func newComputeInstanceDiscoverer(logger logger.Interface, driverRoot string, gpu int, gi int, ci int) (discover.Discover, error) { parentPath := fmt.Sprintf("/dev/nvidia%d", gpu) migCaps, err := nvcaps.NewMigCaps() diff --git a/pkg/nvcdi/options.go b/pkg/nvcdi/options.go index 6baa1b52..9ac772ba 100644 --- a/pkg/nvcdi/options.go +++ b/pkg/nvcdi/options.go @@ -17,8 +17,8 @@ package nvcdi import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform" - "github.com/sirupsen/logrus" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/device" "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml" ) @@ -48,7 +48,7 @@ func WithDriverRoot(root string) Option { } // WithLogger sets the logger for the library -func WithLogger(logger *logrus.Logger) Option { +func WithLogger(logger logger.Interface) Option { return func(l *nvcdilib) { l.logger = logger } diff --git a/pkg/nvcdi/workarounds-device-folder-permissions.go b/pkg/nvcdi/workarounds-device-folder-permissions.go index 98276b8a..812bbbaf 100644 --- a/pkg/nvcdi/workarounds-device-folder-permissions.go +++ b/pkg/nvcdi/workarounds-device-folder-permissions.go @@ -21,11 +21,11 @@ import ( "path/filepath" "github.com/NVIDIA/nvidia-container-toolkit/internal/discover" - "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) type deviceFolderPermissions struct { - logger *logrus.Logger + logger logger.Interface driverRoot string nvidiaCTKPath string devices discover.Discover @@ -39,7 +39,7 @@ var _ discover.Discover = (*deviceFolderPermissions)(nil) // The nested devices that are applicable to the NVIDIA GPU devices are: // - DRM devices at /dev/dri/* // - NVIDIA Caps devices at /dev/nvidia-caps/* -func newDeviceFolderPermissionHookDiscoverer(logger *logrus.Logger, driverRoot string, nvidiaCTKPath string, devices discover.Discover) discover.Discover { +func newDeviceFolderPermissionHookDiscoverer(logger logger.Interface, driverRoot string, nvidiaCTKPath string, devices discover.Discover) discover.Discover { d := &deviceFolderPermissions{ logger: logger, driverRoot: driverRoot, From c9b05d8fed270a675d5375daea919c8f2d7d0fb6 Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Fri, 26 May 2023 10:15:27 +0200 Subject: [PATCH 2/4] Use logger Interface in runtime configuration Signed-off-by: Evan Lezar --- cmd/nvidia-ctk/runtime/configure/configure.go | 3 +++ pkg/config/engine/containerd/containerd.go | 5 +++++ pkg/config/engine/containerd/option.go | 20 ++++++++++++----- pkg/config/engine/crio/option.go | 10 +++++++-- pkg/config/engine/docker/docker.go | 5 +++++ pkg/config/engine/docker/option.go | 22 +++++++++++++------ 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/cmd/nvidia-ctk/runtime/configure/configure.go b/cmd/nvidia-ctk/runtime/configure/configure.go index f978b403..cd5a245a 100644 --- a/cmd/nvidia-ctk/runtime/configure/configure.go +++ b/cmd/nvidia-ctk/runtime/configure/configure.go @@ -155,14 +155,17 @@ func (m command) configureWrapper(c *cli.Context, config *config) error { switch config.runtime { case "containerd": cfg, err = containerd.New( + containerd.WithLogger(m.logger), containerd.WithPath(configFilePath), ) case "crio": cfg, err = crio.New( + crio.WithLogger(m.logger), crio.WithPath(configFilePath), ) case "docker": cfg, err = docker.New( + docker.WithLogger(m.logger), docker.WithPath(configFilePath), ) default: diff --git a/pkg/config/engine/containerd/containerd.go b/pkg/config/engine/containerd/containerd.go index ab782ca6..17ba9a0c 100644 --- a/pkg/config/engine/containerd/containerd.go +++ b/pkg/config/engine/containerd/containerd.go @@ -17,6 +17,7 @@ package containerd import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine" "github.com/pelletier/go-toml" ) @@ -36,5 +37,9 @@ func New(opts ...Option) (engine.Interface, error) { opt(b) } + if b.logger == nil { + b.logger = logger.New() + } + return b.build() } diff --git a/pkg/config/engine/containerd/option.go b/pkg/config/engine/containerd/option.go index 400d5925..bb0bda6f 100644 --- a/pkg/config/engine/containerd/option.go +++ b/pkg/config/engine/containerd/option.go @@ -20,9 +20,9 @@ import ( "fmt" "os" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine" "github.com/pelletier/go-toml" - log "github.com/sirupsen/logrus" ) const ( @@ -30,6 +30,7 @@ const ( ) type builder struct { + logger logger.Interface path string runtimeType string useLegacyConfig bool @@ -39,6 +40,13 @@ type builder struct { // Option defines a function that can be used to configure the config builder type Option func(*builder) +// WithLogger sets the logger for the config builder +func WithLogger(logger logger.Interface) Option { + return func(b *builder) { + b.logger = logger + } +} + // WithPath sets the path for the config builder func WithPath(path string) Option { return func(b *builder) { @@ -76,7 +84,7 @@ func (b *builder) build() (engine.Interface, error) { b.runtimeType = defaultRuntimeType } - config, err := loadConfig(b.path) + config, err := b.loadConfig(b.path) if err != nil { return nil, fmt.Errorf("failed to load config: %v", err) } @@ -99,8 +107,8 @@ func (b *builder) build() (engine.Interface, error) { } // loadConfig loads the containerd config from disk -func loadConfig(config string) (*Config, error) { - log.Infof("Loading config: %v", config) +func (b *builder) loadConfig(config string) (*Config, error) { + b.logger.Infof("Loading config: %v", config) info, err := os.Stat(config) if os.IsExist(err) && info.IsDir() { @@ -110,7 +118,7 @@ func loadConfig(config string) (*Config, error) { configFile := config if os.IsNotExist(err) { configFile = "/dev/null" - log.Infof("Config file does not exist, creating new one") + b.logger.Infof("Config file does not exist, creating new one") } tomlConfig, err := toml.LoadFile(configFile) @@ -118,7 +126,7 @@ func loadConfig(config string) (*Config, error) { return nil, err } - log.Infof("Successfully loaded config") + b.logger.Infof("Successfully loaded config") cfg := Config{ Tree: tomlConfig, diff --git a/pkg/config/engine/crio/option.go b/pkg/config/engine/crio/option.go index 82d3af32..f6660f68 100644 --- a/pkg/config/engine/crio/option.go +++ b/pkg/config/engine/crio/option.go @@ -22,7 +22,6 @@ import ( "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/pelletier/go-toml" - log "github.com/sirupsen/logrus" ) type builder struct { @@ -33,6 +32,13 @@ type builder struct { // Option defines a function that can be used to configure the config builder type Option func(*builder) +// WithLogger sets the logger for the config builder +func WithLogger(logger logger.Interface) Option { + return func(b *builder) { + b.logger = logger + } +} + // WithPath sets the path for the config builder func WithPath(path string) Option { return func(b *builder) { @@ -64,7 +70,7 @@ func (b *builder) loadConfig(config string) (*Config, error) { configFile := config if os.IsNotExist(err) { configFile = "/dev/null" - log.Infof("Config file does not exist, creating new one") + b.logger.Infof("Config file does not exist, creating new one") } cfg, err := toml.LoadFile(configFile) diff --git a/pkg/config/engine/docker/docker.go b/pkg/config/engine/docker/docker.go index 260be267..dc64a3c0 100644 --- a/pkg/config/engine/docker/docker.go +++ b/pkg/config/engine/docker/docker.go @@ -21,6 +21,7 @@ import ( "fmt" "os" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine" ) @@ -39,6 +40,10 @@ func New(opts ...Option) (engine.Interface, error) { opt(b) } + if b.logger == nil { + b.logger = logger.New() + } + return b.build() } diff --git a/pkg/config/engine/docker/option.go b/pkg/config/engine/docker/option.go index 238cc3f1..893ed0d1 100644 --- a/pkg/config/engine/docker/option.go +++ b/pkg/config/engine/docker/option.go @@ -23,16 +23,24 @@ import ( "io/ioutil" "os" - log "github.com/sirupsen/logrus" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" ) type builder struct { - path string + logger logger.Interface + path string } // Option defines a function that can be used to configure the config builder type Option func(*builder) +// WithLogger sets the logger for the config builder +func WithLogger(logger logger.Interface) Option { + return func(b *builder) { + b.logger = logger + } +} + // WithPath sets the path for the config builder func WithPath(path string) Option { return func(b *builder) { @@ -46,12 +54,12 @@ func (b *builder) build() (*Config, error) { return &empty, nil } - return loadConfig(b.path) + return b.loadConfig(b.path) } // loadConfig loads the docker config from disk -func loadConfig(configFilePath string) (*Config, error) { - log.Infof("Loading docker config from %v", configFilePath) +func (b *builder) loadConfig(configFilePath string) (*Config, error) { + b.logger.Infof("Loading docker config from %v", configFilePath) info, err := os.Stat(configFilePath) if os.IsExist(err) && info.IsDir() { @@ -61,7 +69,7 @@ func loadConfig(configFilePath string) (*Config, error) { cfg := make(Config) if os.IsNotExist(err) { - log.Infof("Config file does not exist, creating new one") + b.logger.Infof("Config file does not exist, creating new one") return &cfg, nil } @@ -75,6 +83,6 @@ func loadConfig(configFilePath string) (*Config, error) { return nil, err } - log.Infof("Successfully loaded config") + b.logger.Infof("Successfully loaded config") return &cfg, nil } From 94649539243698a3b22ab7a9029d30a25acc13cd Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 6 Jun 2023 21:42:56 +0200 Subject: [PATCH 3/4] Use logger.Interface when resolving auto mode Signed-off-by: Evan Lezar --- cmd/nvidia-container-runtime-hook/main.go | 9 ++++---- internal/info/auto.go | 14 +++++------- internal/logger/lib.go | 26 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/cmd/nvidia-container-runtime-hook/main.go b/cmd/nvidia-container-runtime-hook/main.go index ee8a0397..9e5d4346 100644 --- a/cmd/nvidia-container-runtime-hook/main.go +++ b/cmd/nvidia-container-runtime-hook/main.go @@ -14,6 +14,7 @@ import ( "syscall" "github.com/NVIDIA/nvidia-container-toolkit/internal/info" + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" "github.com/NVIDIA/nvidia-container-toolkit/internal/lookup" ) @@ -188,11 +189,11 @@ func main() { } } -// logInterceptor implements the info.Logger interface to allow for logging from this function. -type logInterceptor struct{} +// logInterceptor implements the logger.Interface to allow for logging from executable. +type logInterceptor struct { + logger.NullLogger +} func (l *logInterceptor) Infof(format string, args ...interface{}) { log.Printf(format, args...) } - -func (l *logInterceptor) Debugf(format string, args ...interface{}) {} diff --git a/internal/info/auto.go b/internal/info/auto.go index c7863b97..7ec8bb86 100644 --- a/internal/info/auto.go +++ b/internal/info/auto.go @@ -16,17 +16,13 @@ package info -import "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info" - -// Logger is a basic interface for logging to allow these functions to be called -// from code where logrus is not used. -type Logger interface { - Infof(string, ...interface{}) - Debugf(string, ...interface{}) -} +import ( + "github.com/NVIDIA/nvidia-container-toolkit/internal/logger" + "gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info" +) // ResolveAutoMode determines the correct mode for the platform if set to "auto" -func ResolveAutoMode(logger Logger, mode string) (rmode string) { +func ResolveAutoMode(logger logger.Interface, mode string) (rmode string) { if mode != "auto" { return mode } diff --git a/internal/logger/lib.go b/internal/logger/lib.go index f9e46b64..075c6ea3 100644 --- a/internal/logger/lib.go +++ b/internal/logger/lib.go @@ -22,3 +22,29 @@ import "github.com/sirupsen/logrus" func New() Interface { return logrus.StandardLogger() } + +// NullLogger is a logger that does nothing +type NullLogger struct{} + +var _ Interface = (*NullLogger)(nil) + +// Debugf is a no-op for the null logger +func (l *NullLogger) Debugf(string, ...interface{}) {} + +// Errorf is a no-op for the null logger +func (l *NullLogger) Errorf(string, ...interface{}) {} + +// Info is a no-op for the null logger +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{}) {} + +// Warningf is a no-op for the null logger +func (l *NullLogger) Warningf(string, ...interface{}) {} From 1d0a733487b5ff433b7814dca842fddc0bd82e6e Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Tue, 6 Jun 2023 21:46:38 +0200 Subject: [PATCH 4/4] 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)