mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-22 17:57:21 +00:00
Define a basic logger interface
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
parent
6a04e97bca
commit
a02bc27c3e
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -13,7 +14,7 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/modifier"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/modifier"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ func TestMain(m *testing.M) {
|
|||||||
var err error
|
var err error
|
||||||
moduleRoot, err := test.GetModuleRoot()
|
moduleRoot, err := test.GetModuleRoot()
|
||||||
if err != nil {
|
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")
|
testBinPath := filepath.Join(moduleRoot, "test", "bin")
|
||||||
testInputPath := filepath.Join(moduleRoot, "test", "input")
|
testInputPath := filepath.Join(moduleRoot, "test", "input")
|
||||||
@ -54,11 +55,11 @@ func TestMain(m *testing.M) {
|
|||||||
// Confirm that the environment is configured correctly
|
// Confirm that the environment is configured correctly
|
||||||
runcPath, err := exec.LookPath(runcExecutableName)
|
runcPath, err := exec.LookPath(runcExecutableName)
|
||||||
if err != nil || filepath.Join(testBinPath, runcExecutableName) != runcPath {
|
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)
|
hookPath, err := exec.LookPath(nvidiaHook)
|
||||||
if err != nil || filepath.Join(testBinPath, nvidiaHook) != hookPath {
|
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
|
// 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
|
// addNVIDIAHook is a basic wrapper for an addHookModifier that is used for
|
||||||
// testing.
|
// testing.
|
||||||
func addNVIDIAHook(spec *specs.Spec) error {
|
func addNVIDIAHook(spec *specs.Spec) error {
|
||||||
m := modifier.NewStableRuntimeModifier(logrus.StandardLogger(), nvidiaHook)
|
logger, _ := testlog.NewNullLogger()
|
||||||
|
m := modifier.NewStableRuntimeModifier(logger, nvidiaHook)
|
||||||
return m.Modify(spec)
|
return m.Modify(spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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/generate"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/list"
|
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/list"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/transform"
|
"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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs an info command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -24,11 +24,11 @@ import (
|
|||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv"
|
"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"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/spec"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type options struct {
|
type options struct {
|
||||||
@ -56,7 +56,7 @@ type options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a generate-cdi command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -19,19 +19,19 @@ package list
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"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/pkg/cdi"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct{}
|
type config struct{}
|
||||||
|
|
||||||
// NewCommand constructs a cdi list command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -21,10 +21,10 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"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/spec"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ type loadSaver interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type transformOptions struct {
|
type transformOptions struct {
|
||||||
@ -49,7 +49,7 @@ type options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a generate-cdi command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ package transform
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/cdi/transform/root"
|
"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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a command with the specified logger
|
// NewCommand constructs a command with the specified logger
|
||||||
func NewCommand(logger *logrus.Logger) *cli.Command {
|
func NewCommand(logger logger.Interface) *cli.Command {
|
||||||
c := command{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
createdefault "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/config/create-default"
|
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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs an config command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
nvctkConfig "github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// options stores the subcommand options
|
// options stores the subcommand options
|
||||||
@ -36,7 +36,7 @@ type options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a default command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
@ -40,7 +40,7 @@ type config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a chmod command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,15 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv"
|
"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"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
@ -42,7 +42,7 @@ type config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a hook command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -18,19 +18,19 @@ package hook
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
chmod "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/hook/chmod"
|
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"
|
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"
|
ldcache "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/hook/update-ldcache"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type hookCommand struct {
|
type hookCommand struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a hook command with the specified logger
|
// 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{
|
c := hookCommand{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -22,13 +22,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
@ -37,7 +37,7 @@ type config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs an update-ldcache command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -17,16 +17,16 @@
|
|||||||
package info
|
package info
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs an info command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -26,13 +26,11 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/runtime"
|
"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/cmd/nvidia-ctk/system"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
cli "github.com/urfave/cli/v2"
|
cli "github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger = log.New()
|
|
||||||
|
|
||||||
// options defines the options that can be set for the CLI through config files,
|
// options defines the options that can be set for the CLI through config files,
|
||||||
// environment variables, or command line flags
|
// environment variables, or command line flags
|
||||||
type options struct {
|
type options struct {
|
||||||
@ -41,6 +39,8 @@ type options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
logger := logrus.New()
|
||||||
|
|
||||||
// Create a options struct to hold the parsed environment variables or command line flags
|
// Create a options struct to hold the parsed environment variables or command line flags
|
||||||
opts := options{}
|
opts := options{}
|
||||||
|
|
||||||
@ -65,9 +65,9 @@ func main() {
|
|||||||
|
|
||||||
// Set log-level for all subcommands
|
// Set log-level for all subcommands
|
||||||
c.Before = func(c *cli.Context) error {
|
c.Before = func(c *cli.Context) error {
|
||||||
logLevel := log.InfoLevel
|
logLevel := logrus.InfoLevel
|
||||||
if opts.Debug {
|
if opts.Debug {
|
||||||
logLevel = log.DebugLevel
|
logLevel = logrus.DebugLevel
|
||||||
}
|
}
|
||||||
logger.SetLevel(logLevel)
|
logger.SetLevel(logLevel)
|
||||||
return nil
|
return nil
|
||||||
@ -86,7 +86,7 @@ func main() {
|
|||||||
// Run the CLI
|
// Run the CLI
|
||||||
err := c.Run(os.Args)
|
err := c.Run(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("%v", err)
|
logger.Errorf("%v", err)
|
||||||
log.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"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"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/containerd"
|
"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/crio"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/docker"
|
"github.com/NVIDIA/nvidia-container-toolkit/pkg/config/engine/docker"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -43,11 +43,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs an configure command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -18,16 +18,16 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/runtime/configure"
|
"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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type runtimeCommand struct {
|
type runtimeCommand struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a runtime command with the specified logger
|
// 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{
|
c := runtimeCommand{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc/devices"
|
"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/NVIDIA/nvidia-container-toolkit/internal/nvcaps"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvpci"
|
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvpci"
|
||||||
)
|
)
|
||||||
|
|
||||||
type allPossible struct {
|
type allPossible struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
driverRoot string
|
driverRoot string
|
||||||
deviceMajors devices.Devices
|
deviceMajors devices.Devices
|
||||||
migCaps nvcaps.MigCaps
|
migCaps nvcaps.MigCaps
|
||||||
@ -35,7 +35,7 @@ type allPossible struct {
|
|||||||
|
|
||||||
// newAllPossible returns a new allPossible device node lister.
|
// newAllPossible returns a new allPossible device node lister.
|
||||||
// This lister lists all possible device nodes for NVIDIA GPUs, control devices, and capability devices.
|
// 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()
|
deviceMajors, err := devices.GetNVIDIADevices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed reading device majors: %v", err)
|
return nil, fmt.Errorf("failed reading device majors: %v", err)
|
||||||
|
@ -24,9 +24,9 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/system"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/system"
|
||||||
"github.com/fsnotify/fsnotify"
|
"github.com/fsnotify/fsnotify"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
@ -49,7 +49,7 @@ type config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a command sub-command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
@ -213,7 +213,7 @@ create:
|
|||||||
}
|
}
|
||||||
|
|
||||||
type linkCreator struct {
|
type linkCreator struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
lister nodeLister
|
lister nodeLister
|
||||||
driverRoot string
|
driverRoot string
|
||||||
devCharPath string
|
devCharPath string
|
||||||
@ -238,7 +238,7 @@ func NewSymlinkCreator(opts ...Option) (Creator, error) {
|
|||||||
opt(&c)
|
opt(&c)
|
||||||
}
|
}
|
||||||
if c.logger == nil {
|
if c.logger == nil {
|
||||||
c.logger = logrus.StandardLogger()
|
c.logger = logger.New()
|
||||||
}
|
}
|
||||||
if c.driverRoot == "" {
|
if c.driverRoot == "" {
|
||||||
c.driverRoot = "/"
|
c.driverRoot = "/"
|
||||||
@ -313,7 +313,7 @@ func WithDryRun(dryRun bool) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithLogger sets the logger.
|
// WithLogger sets the logger.
|
||||||
func WithLogger(logger *logrus.Logger) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(c *linkCreator) {
|
return func(c *linkCreator) {
|
||||||
c.logger = logger
|
c.logger = logger
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ type nodeLister interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type existing struct {
|
type existing struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
driverRoot string
|
driverRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,13 @@ package createdevicenodes
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/system"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/system"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type options struct {
|
type options struct {
|
||||||
@ -39,7 +39,7 @@ type options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a command sub-command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache"
|
"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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
type options struct {
|
type options struct {
|
||||||
@ -33,7 +33,7 @@ type options struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a command sub-command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,16 @@ import (
|
|||||||
devchar "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-ctk/system/create-dev-char-symlinks"
|
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"
|
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"
|
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"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCommand constructs a runtime command with the specified logger
|
// 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{
|
c := command{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -249,7 +249,7 @@ func getDistIDLike() []string {
|
|||||||
// This executable is used in hooks and needs to be an absolute path.
|
// 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
|
// If the path is specified as an absolute path, it is used directly
|
||||||
// without checking for existence of an executable at that path.
|
// 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(
|
return resolveWithDefault(
|
||||||
logger,
|
logger,
|
||||||
"NVIDIA Container Toolkit CLI",
|
"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.
|
// 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(
|
return resolveWithDefault(
|
||||||
logger,
|
logger,
|
||||||
"NVIDIA Container Runtime Hook",
|
"NVIDIA Container Runtime Hook",
|
||||||
@ -271,7 +271,7 @@ func ResolveNVIDIAContainerRuntimeHookPath(logger *logrus.Logger, nvidiaContaine
|
|||||||
// resolveWithDefault resolves the path to the specified binary.
|
// resolveWithDefault resolves the path to the specified binary.
|
||||||
// If an absolute path is specified, it is used directly without searching for the 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.
|
// 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) {
|
if filepath.IsAbs(path) {
|
||||||
logger.Debugf("Using specified %v path %v", label, path)
|
logger.Debugf("Using specified %v path %v", label, path)
|
||||||
return path
|
return path
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
package discover
|
package discover
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// charDevices is a discover for a list of character devices
|
// charDevices is a discover for a list of character devices
|
||||||
@ -27,7 +27,7 @@ type charDevices mounts
|
|||||||
var _ Discover = (*charDevices)(nil)
|
var _ Discover = (*charDevices)(nil)
|
||||||
|
|
||||||
// NewCharDeviceDiscoverer creates a discoverer which locates the specified set of device nodes.
|
// 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(
|
locator := lookup.NewCharDeviceLocator(
|
||||||
lookup.WithLogger(logger),
|
lookup.WithLogger(logger),
|
||||||
lookup.WithRoot(root),
|
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.
|
// 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)
|
m := NewMounts(logger, locator, root, devices).(*mounts)
|
||||||
|
|
||||||
return (*charDevices)(m)
|
return (*charDevices)(m)
|
||||||
|
@ -20,14 +20,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv"
|
"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"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewFromCSVFiles creates a discoverer for the specified CSV files. A logger is also supplied.
|
// 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
|
// The constructed discoverer is comprised of a list, with each element in the list being associated with a
|
||||||
// single CSV files.
|
// 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 {
|
if len(files) == 0 {
|
||||||
logger.Warnf("No CSV files specified")
|
logger.Warnf("No CSV files specified")
|
||||||
return None{}, nil
|
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
|
// 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
|
// Create a discoverer for each file-kind combination
|
||||||
targets, err := csv.NewCSVFileParser(logger, filename).Parse()
|
targets, err := csv.NewCSVFileParser(logger, filename).Parse()
|
||||||
if err != nil {
|
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.
|
// 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.
|
// 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 {
|
if len(targets) == 0 {
|
||||||
return &None{}, nil
|
return &None{}, nil
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -103,12 +103,12 @@ type Parser interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type csv struct {
|
type csv struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
filename string
|
filename string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCSVFileParser creates a new parser for reading MountSpecs from the specified CSV file
|
// 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{
|
p := csv{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
filename: filename,
|
filename: filename,
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package discover
|
package discover
|
||||||
|
|
||||||
import "github.com/sirupsen/logrus"
|
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
|
|
||||||
// Filter defines an interface for filtering discovered entities
|
// Filter defines an interface for filtering discovered entities
|
||||||
type Filter interface {
|
type Filter interface {
|
||||||
@ -26,12 +26,12 @@ type Filter interface {
|
|||||||
// filtered represents a filtered discoverer
|
// filtered represents a filtered discoverer
|
||||||
type filtered struct {
|
type filtered struct {
|
||||||
Discover
|
Discover
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
filter Filter
|
filter Filter
|
||||||
}
|
}
|
||||||
|
|
||||||
// newFilteredDisoverer creates a discoverer that applies the specified filter to the returned entities of the discoverer
|
// 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{
|
return filtered{
|
||||||
Discover: applyTo,
|
Discover: applyTo,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
|
@ -17,19 +17,19 @@
|
|||||||
package discover
|
package discover
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type gdsDeviceDiscoverer struct {
|
type gdsDeviceDiscoverer struct {
|
||||||
None
|
None
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
devices Discover
|
devices Discover
|
||||||
mounts Discover
|
mounts Discover
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewGDSDiscoverer creates a discoverer for GPUDirect Storage devices and mounts.
|
// 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(
|
devices := NewCharDeviceDiscoverer(
|
||||||
logger,
|
logger,
|
||||||
[]string{"/dev/nvidia-fs*"},
|
[]string{"/dev/nvidia-fs*"},
|
||||||
|
@ -25,13 +25,13 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
"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/drm"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc"
|
"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"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewGraphicsDiscoverer returns the discoverer for graphics tools such as Vulkan.
|
// 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)
|
mounts, err := NewGraphicsMountsDiscoverer(logger, driverRoot, nvidiaCTKPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create mounts discoverer: %v", err)
|
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.
|
// 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)
|
locator, err := lookup.NewLibraryLocator(logger, driverRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to construct library locator: %v", err)
|
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 {
|
type drmDevicesByPath struct {
|
||||||
None
|
None
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
nvidiaCTKPath string
|
nvidiaCTKPath string
|
||||||
driverRoot string
|
driverRoot string
|
||||||
devicesFrom Discover
|
devicesFrom Discover
|
||||||
}
|
}
|
||||||
|
|
||||||
// newCreateDRMByPathSymlinks creates a discoverer for a hook to create the by-path symlinks for DRM devices discovered by the specified devices discoverer
|
// 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{
|
d := drmDevicesByPath{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaCTKPath: nvidiaCTKPath,
|
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.
|
// 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(
|
allDevices := NewDeviceDiscoverer(
|
||||||
logger,
|
logger,
|
||||||
lookup.NewCharDeviceLocator(
|
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.
|
// 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)
|
gpuInformationPaths, err := proc.GetInformationFilePaths(driverRoot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read GPU information: %v", err)
|
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.
|
// optionalXorgDiscoverer creates a discoverer for Xorg libraries.
|
||||||
// If the creation of the discoverer fails, a None discoverer is returned.
|
// 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)
|
xorg, err := newXorgDiscoverer(logger, driverRoot, nvidiaCTKPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Warnf("Failed to create Xorg discoverer: %v; skipping xorg libraries", err)
|
logger.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
|
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(
|
libCudaPaths, err := cuda.New(
|
||||||
cuda.WithLogger(logger),
|
cuda.WithLogger(logger),
|
||||||
cuda.WithDriverRoot(driverRoot),
|
cuda.WithDriverRoot(driverRoot),
|
||||||
|
@ -20,14 +20,15 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIPCMounts(t *testing.T) {
|
func TestIPCMounts(t *testing.T) {
|
||||||
|
logger, _ := testlog.NewNullLogger()
|
||||||
l := ipcMounts(
|
l := ipcMounts(
|
||||||
mounts{
|
mounts{
|
||||||
logger: logrus.New(),
|
logger: logger,
|
||||||
lookup: &lookup.LocatorMock{
|
lookup: &lookup.LocatorMock{
|
||||||
LocateFunc: func(path string) ([]string, error) {
|
LocateFunc: func(path string) ([]string, error) {
|
||||||
return []string{"/host/path"}, nil
|
return []string{"/host/path"}, nil
|
||||||
|
@ -17,14 +17,14 @@
|
|||||||
package discover
|
package discover
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ipcMounts mounts
|
type ipcMounts mounts
|
||||||
|
|
||||||
// NewIPCDiscoverer creats a discoverer for NVIDIA IPC sockets.
|
// 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(
|
sockets := newMounts(
|
||||||
logger,
|
logger,
|
||||||
lookup.NewFileLocator(
|
lookup.NewFileLocator(
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"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
|
// 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{
|
d := ldconfig{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaCTKPath: nvidiaCTKPath,
|
nvidiaCTKPath: nvidiaCTKPath,
|
||||||
@ -37,7 +37,7 @@ func NewLDCacheUpdateHook(logger *logrus.Logger, mounts Discover, nvidiaCTKPath
|
|||||||
|
|
||||||
type ldconfig struct {
|
type ldconfig struct {
|
||||||
None
|
None
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
nvidiaCTKPath string
|
nvidiaCTKPath string
|
||||||
mountsFrom Discover
|
mountsFrom Discover
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,10 @@
|
|||||||
|
|
||||||
package discover
|
package discover
|
||||||
|
|
||||||
import (
|
import "github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewMOFEDDiscoverer creates a discoverer for MOFED devices.
|
// 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(
|
devices := NewCharDeviceDiscoverer(
|
||||||
logger,
|
logger,
|
||||||
[]string{
|
[]string{
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"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
|
// 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.
|
// based on the entry in the list.
|
||||||
type mounts struct {
|
type mounts struct {
|
||||||
None
|
None
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
lookup lookup.Locator
|
lookup lookup.Locator
|
||||||
root string
|
root string
|
||||||
required []string
|
required []string
|
||||||
@ -42,12 +42,12 @@ type mounts struct {
|
|||||||
var _ Discover = (*mounts)(nil)
|
var _ Discover = (*mounts)(nil)
|
||||||
|
|
||||||
// NewMounts creates a discoverer for the required mounts using the specified locator.
|
// 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)
|
return newMounts(logger, lookup, root, required)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newMounts creates a discoverer for the required mounts using the specified locator.
|
// 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{
|
return &mounts{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
lookup: lookup,
|
lookup: lookup,
|
||||||
|
@ -22,14 +22,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv"
|
"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"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type symlinkHook struct {
|
type symlinkHook struct {
|
||||||
None
|
None
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
driverRoot string
|
driverRoot string
|
||||||
nvidiaCTKPath string
|
nvidiaCTKPath string
|
||||||
csvFiles []string
|
csvFiles []string
|
||||||
@ -37,7 +37,7 @@ type symlinkHook struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewCreateSymlinksHook creates a discoverer for a hook that creates required symlinks in the container
|
// 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{
|
d := symlinkHook{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaCTKPath: nvidiaCTKPath,
|
nvidiaCTKPath: nvidiaCTKPath,
|
||||||
|
@ -20,12 +20,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tegraOptions struct {
|
type tegraOptions struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
csvFiles []string
|
csvFiles []string
|
||||||
driverRoot string
|
driverRoot string
|
||||||
nvidiaCTKPath string
|
nvidiaCTKPath string
|
||||||
@ -78,7 +78,7 @@ func New(opts ...Option) (discover.Discover, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithLogger sets the logger for the discoverer.
|
// WithLogger sets the logger for the discoverer.
|
||||||
func WithLogger(logger *logrus.Logger) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(o *tegraOptions) {
|
return func(o *tegraOptions) {
|
||||||
o.logger = logger
|
o.logger = logger
|
||||||
}
|
}
|
||||||
|
@ -20,21 +20,21 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/specs-go"
|
"github.com/container-orchestrated-devices/container-device-interface/specs-go"
|
||||||
ociSpecs "github.com/opencontainers/runtime-spec/specs-go"
|
ociSpecs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type edits struct {
|
type edits struct {
|
||||||
cdi.ContainerEdits
|
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
|
// NewSpecEdits creates a SpecModifier that defines the required OCI spec edits (as CDI ContainerEdits) from the specified
|
||||||
// discoverer.
|
// 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)
|
c, err := FromDiscoverer(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error constructing container edits: %v", err)
|
return nil, fmt.Errorf("error constructing container edits: %v", err)
|
||||||
|
@ -29,8 +29,8 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const ldcachePath = "/etc/ld.so.cache"
|
const ldcachePath = "/etc/ld.so.cache"
|
||||||
@ -94,11 +94,11 @@ type ldcache struct {
|
|||||||
entries []entry2
|
entries []entry2
|
||||||
|
|
||||||
root string
|
root string
|
||||||
logger *log.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new LDCache with the specified logger and root.
|
// 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)
|
path := filepath.Join(root, ldcachePath)
|
||||||
|
|
||||||
logger.Debugf("Opening ld.conf at %v", path)
|
logger.Debugf("Opening ld.conf at %v", path)
|
||||||
|
28
internal/logger/api.go
Normal file
28
internal/logger/api.go
Normal file
@ -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{})
|
||||||
|
}
|
24
internal/logger/lib.go
Normal file
24
internal/logger/lib.go
Normal file
@ -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()
|
||||||
|
}
|
@ -19,12 +19,12 @@ package cuda
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cudaLocator struct {
|
type cudaLocator struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
driverRoot string
|
driverRoot string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ type cudaLocator struct {
|
|||||||
type Options func(*cudaLocator)
|
type Options func(*cudaLocator)
|
||||||
|
|
||||||
// WithLogger is an option that configures the logger used by the locator.
|
// 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) {
|
return func(c *cudaLocator) {
|
||||||
c.logger = logger
|
c.logger = logger
|
||||||
}
|
}
|
||||||
@ -53,7 +53,7 @@ func New(opts ...Options) lookup.Locator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.logger == nil {
|
if c.logger == nil {
|
||||||
c.logger = logrus.StandardLogger()
|
c.logger = logger.New()
|
||||||
}
|
}
|
||||||
if c.driverRoot == "" {
|
if c.driverRoot == "" {
|
||||||
c.driverRoot = "/"
|
c.driverRoot = "/"
|
||||||
|
@ -20,12 +20,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"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
|
// NewDirectoryLocator creates a Locator that can be used to find directories at the specified root. A logger
|
||||||
// is also specified.
|
// is also specified.
|
||||||
func NewDirectoryLocator(logger *log.Logger, root string) Locator {
|
func NewDirectoryLocator(logger logger.Interface, root string) Locator {
|
||||||
return NewFileLocator(
|
return NewFileLocator(
|
||||||
WithLogger(logger),
|
WithLogger(logger),
|
||||||
WithRoot(root),
|
WithRoot(root),
|
||||||
|
@ -21,7 +21,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type executable struct {
|
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.
|
// 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)
|
paths := GetPaths(root)
|
||||||
|
|
||||||
return newExecutableLocator(logger, root, paths...)
|
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(
|
f := newFileLocator(
|
||||||
WithLogger(logger),
|
WithLogger(logger),
|
||||||
WithRoot(root),
|
WithRoot(root),
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"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
|
// 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.
|
// prefixes. The validity of a file is determined by a filter function.
|
||||||
type file struct {
|
type file struct {
|
||||||
logger *log.Logger
|
logger logger.Interface
|
||||||
root string
|
root string
|
||||||
prefixes []string
|
prefixes []string
|
||||||
filter func(string) error
|
filter func(string) error
|
||||||
@ -46,7 +46,7 @@ func WithRoot(root string) Option {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithLogger sets the logger for the file locator
|
// WithLogger sets the logger for the file locator
|
||||||
func WithLogger(logger *log.Logger) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(f *file) {
|
return func(f *file) {
|
||||||
f.logger = logger
|
f.logger = logger
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ func newFileLocator(opts ...Option) *file {
|
|||||||
opt(f)
|
opt(f)
|
||||||
}
|
}
|
||||||
if f.logger == nil {
|
if f.logger == nil {
|
||||||
f.logger = log.StandardLogger()
|
f.logger = logger.New()
|
||||||
}
|
}
|
||||||
if f.filter == nil {
|
if f.filter == nil {
|
||||||
f.filter = assertFile
|
f.filter = assertFile
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/ldcache"
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type library struct {
|
type library struct {
|
||||||
logger *log.Logger
|
logger logger.Interface
|
||||||
symlink Locator
|
symlink Locator
|
||||||
cache ldcache.LDCache
|
cache ldcache.LDCache
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ type library struct {
|
|||||||
var _ Locator = (*library)(nil)
|
var _ Locator = (*library)(nil)
|
||||||
|
|
||||||
// NewLibraryLocator creates a library locator using the specified logger.
|
// 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)
|
cache, err := ldcache.New(logger, root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error loading ldcache: %v", err)
|
return nil, fmt.Errorf("error loading ldcache: %v", err)
|
||||||
|
@ -20,8 +20,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type symlinkChain struct {
|
type symlinkChain struct {
|
||||||
@ -34,7 +34,7 @@ type symlink struct {
|
|||||||
|
|
||||||
// NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
|
// NewSymlinkChainLocator creats a locator that can be used for locating files through symlinks.
|
||||||
// A logger can also be specified.
|
// 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))
|
f := newFileLocator(WithLogger(logger), WithRoot(root))
|
||||||
l := symlinkChain{
|
l := symlinkChain{
|
||||||
file: *f,
|
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.
|
// NewSymlinkLocator creats a locator that can be used for locating files through symlinks.
|
||||||
// A logger can also be specified.
|
// 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))
|
f := newFileLocator(WithLogger(logger), WithRoot(root))
|
||||||
l := symlink{
|
l := symlink{
|
||||||
file: *f,
|
file: *f,
|
||||||
|
@ -22,14 +22,14 @@ import (
|
|||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
"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"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
cdi "github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cdiModifier struct {
|
type cdiModifier struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
specDirs []string
|
specDirs []string
|
||||||
devices []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
|
// 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
|
// CDI specifications available on the system. The NVIDIA_VISIBLE_DEVICES enviroment variable is
|
||||||
// used to select the devices to include.
|
// 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)
|
devices, err := getDevicesFromSpec(logger, ociSpec, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get required devices from OCI specification: %v", err)
|
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
|
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()
|
rawSpec, err := ociSpec.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
||||||
|
@ -25,14 +25,14 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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/csv"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/tegra"
|
"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/oci"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/requirements"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/requirements"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// csvMode represents the modifications as performed by the csv runtime mode
|
// csvMode represents the modifications as performed by the csv runtime mode
|
||||||
type csvMode struct {
|
type csvMode struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
discoverer discover.Discover
|
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.
|
// NewCSVModifier creates a modifier that applies modications to an OCI spec if required by the runtime wrapper.
|
||||||
// The modifications are defined by CSV MountSpecs.
|
// 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()
|
rawSpec, err := ociSpec.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
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
|
return modifiers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkRequirements(logger *logrus.Logger, image image.CUDA) error {
|
func checkRequirements(logger logger.Interface, image image.CUDA) error {
|
||||||
if image.HasDisableRequire() {
|
if image.HasDisableRequire() {
|
||||||
// TODO: We could print the real value here instead
|
// TODO: We could print the real value here instead
|
||||||
logger.Debugf("NVIDIA_DISABLE_REQUIRE=%v; skipping requirement checks", true)
|
logger.Debugf("NVIDIA_DISABLE_REQUIRE=%v; skipping requirement checks", true)
|
||||||
|
@ -21,19 +21,19 @@ import (
|
|||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/edits"
|
"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/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type discoverModifier struct {
|
type discoverModifier struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
discoverer discover.Discover
|
discoverer discover.Discover
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewModifierFromDiscoverer creates a modifier that applies the discovered
|
// NewModifierFromDiscoverer creates a modifier that applies the discovered
|
||||||
// modifications to an OCI spec if required by the runtime wrapper.
|
// 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{
|
m := discoverModifier{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
discoverer: d,
|
discoverer: d,
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -32,7 +32,7 @@ const (
|
|||||||
|
|
||||||
// NewGDSModifier creates the modifiers for GDS devices.
|
// NewGDSModifier creates the modifiers for GDS devices.
|
||||||
// If the spec does not contain the NVIDIA_GDS=enabled environment variable no changes are made.
|
// 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()
|
rawSpec, err := ociSpec.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
||||||
|
@ -22,13 +22,13 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewGraphicsModifier constructs a modifier that injects graphics-related modifications into an OCI runtime specification.
|
// 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.
|
// 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()
|
rawSpec, err := ociSpec.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
||||||
|
@ -20,14 +20,14 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"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/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"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
|
// nvidiaContainerRuntimeHookRemover is a spec modifer that detects and removes inserted nvidia-container-runtime hooks
|
||||||
type nvidiaContainerRuntimeHookRemover struct {
|
type nvidiaContainerRuntimeHookRemover struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ oci.SpecModifier = (*nvidiaContainerRuntimeHookRemover)(nil)
|
var _ oci.SpecModifier = (*nvidiaContainerRuntimeHookRemover)(nil)
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config/image"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -32,7 +32,7 @@ const (
|
|||||||
|
|
||||||
// NewMOFEDModifier creates the modifiers for MOFED devices.
|
// NewMOFEDModifier creates the modifiers for MOFED devices.
|
||||||
// If the spec does not contain the NVIDIA_MOFED=enabled environment variable no changes are made.
|
// 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()
|
rawSpec, err := ociSpec.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
||||||
|
@ -19,14 +19,14 @@ package modifier
|
|||||||
import (
|
import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"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
|
// 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.
|
// 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{
|
m := stableRuntimeModifier{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
nvidiaContainerRuntimeHookPath: nvidiaContainerRuntimeHookPath,
|
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
|
// 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.
|
// prestart hook. If the hook is already present, no modification is made.
|
||||||
type stableRuntimeModifier struct {
|
type stableRuntimeModifier struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
nvidiaContainerRuntimeHookPath string
|
nvidiaContainerRuntimeHookPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
package modifier
|
package modifier
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
testlog "github.com/sirupsen/logrus/hooks/test"
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
|
|||||||
var err error
|
var err error
|
||||||
moduleRoot, err := test.GetModuleRoot()
|
moduleRoot, err := test.GetModuleRoot()
|
||||||
if err != nil {
|
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")
|
testBinPath := filepath.Join(moduleRoot, "test", "bin")
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ package oci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewLowLevelRuntime creates a Runtime that wraps a low-level runtime executable.
|
// 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
|
// 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.
|
// 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)
|
runtimePath, err := findRuntime(logger, candidates)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error locating runtime: %v", err)
|
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.
|
// 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.
|
// 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 {
|
if len(candidates) == 0 {
|
||||||
return "", fmt.Errorf("at least one runtime candidate must be specified")
|
return "", fmt.Errorf("at least one runtime candidate must be specified")
|
||||||
}
|
}
|
||||||
|
@ -19,11 +19,11 @@ package oci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type modifyingRuntimeWrapper struct {
|
type modifyingRuntimeWrapper struct {
|
||||||
logger *log.Logger
|
logger logger.Interface
|
||||||
runtime Runtime
|
runtime Runtime
|
||||||
ociSpec Spec
|
ociSpec Spec
|
||||||
modifier SpecModifier
|
modifier SpecModifier
|
||||||
@ -33,7 +33,7 @@ var _ Runtime = (*modifyingRuntimeWrapper)(nil)
|
|||||||
|
|
||||||
// NewModifyingRuntimeWrapper creates a runtime wrapper that applies the specified modifier to the OCI specification
|
// 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.
|
// 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 {
|
if modifier == nil {
|
||||||
logger.Infof("Using low-level runtime with no modification")
|
logger.Infof("Using low-level runtime with no modification")
|
||||||
return runtime
|
return runtime
|
||||||
|
@ -20,14 +20,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"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.
|
// 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
|
// This can be used to wrap an OCI-compliant low-level runtime binary, allowing it to be used through the
|
||||||
// Runtime internface.
|
// Runtime internface.
|
||||||
type pathRuntime struct {
|
type pathRuntime struct {
|
||||||
logger *log.Logger
|
logger logger.Interface
|
||||||
path string
|
path string
|
||||||
execRuntime Runtime
|
execRuntime Runtime
|
||||||
}
|
}
|
||||||
@ -35,7 +35,7 @@ type pathRuntime struct {
|
|||||||
var _ Runtime = (*pathRuntime)(nil)
|
var _ Runtime = (*pathRuntime)(nil)
|
||||||
|
|
||||||
// NewRuntimeForPath creates a Runtime for the specified logger and path
|
// 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)
|
info, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("invalid path '%v': %v", path, err)
|
return nil, fmt.Errorf("invalid path '%v': %v", path, err)
|
||||||
|
@ -19,8 +19,8 @@ package oci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SpecModifier defines an interace for modifying a (raw) OCI spec
|
// 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
|
// NewSpec creates fileSpec based on the command line arguments passed to the
|
||||||
// application using the specified logger.
|
// 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)
|
bundleDir, err := GetBundleDir(args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error getting bundle directory: %v", err)
|
return nil, fmt.Errorf("error getting bundle directory: %v", err)
|
||||||
|
@ -20,16 +20,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type factory struct {
|
type factory struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
properties map[string]Property
|
properties map[string]Property
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new constraint for the supplied requirements and properties
|
// 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 {
|
if len(requirements) == 0 {
|
||||||
return &always{}, nil
|
return &always{}, nil
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,19 @@
|
|||||||
package requirements
|
package requirements
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/requirements/constraints"
|
"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
|
// Requirements represents a collection of requirements that can be compared to properties
|
||||||
type Requirements struct {
|
type Requirements struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
requirements []string
|
requirements []string
|
||||||
properties map[string]constraints.Property
|
properties map[string]constraints.Property
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new set of requirements
|
// 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{
|
r := Requirements{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
requirements: requirements,
|
requirements: requirements,
|
||||||
|
@ -26,20 +26,21 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger adds a way to manage output to a log file to a logrus.Logger
|
// Logger adds a way to manage output to a log file to a logrus.Logger
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
*logrus.Logger
|
logger.Interface
|
||||||
previousLogger *logrus.Logger
|
previousLogger logger.Interface
|
||||||
logFiles []*os.File
|
logFiles []*os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLogger creates an empty logger
|
// NewLogger creates an empty logger
|
||||||
func NewLogger() *Logger {
|
func NewLogger() *Logger {
|
||||||
return &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{
|
*l = Logger{
|
||||||
Logger: newLogger,
|
Interface: newLogger,
|
||||||
previousLogger: l.Logger,
|
previousLogger: l.Interface,
|
||||||
logFiles: logFiles,
|
logFiles: logFiles,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,7 +131,7 @@ func (l *Logger) Reset() error {
|
|||||||
if previous == nil {
|
if previous == nil {
|
||||||
previous = logrus.New()
|
previous = logrus.New()
|
||||||
}
|
}
|
||||||
l.Logger = previous
|
l.Interface = previous
|
||||||
l.previousLogger = nil
|
l.previousLogger = nil
|
||||||
l.logFiles = nil
|
l.logFiles = nil
|
||||||
}()
|
}()
|
||||||
|
@ -28,7 +28,9 @@ func TestLogger(t *testing.T) {
|
|||||||
|
|
||||||
l.Update("", "debug", nil)
|
l.Update("", "debug", nil)
|
||||||
|
|
||||||
require.Equal(t, logrus.DebugLevel, l.Logger.Level)
|
ll := l.Interface.(*logrus.Logger)
|
||||||
require.Equal(t, logrus.InfoLevel, l.previousLogger.Level)
|
require.Equal(t, logrus.DebugLevel, ll.Level)
|
||||||
|
|
||||||
|
lp := l.previousLogger.(*logrus.Logger)
|
||||||
|
require.Equal(t, logrus.InfoLevel, lp.Level)
|
||||||
}
|
}
|
||||||
|
@ -61,8 +61,8 @@ func (r rt) Run(argv []string) (rerr error) {
|
|||||||
if r.modeOverride != "" {
|
if r.modeOverride != "" {
|
||||||
cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride
|
cfg.NVIDIAContainerRuntimeConfig.Mode = r.modeOverride
|
||||||
}
|
}
|
||||||
cfg.NVIDIACTKConfig.Path = config.ResolveNVIDIACTKPath(r.logger.Logger, cfg.NVIDIACTKConfig.Path)
|
cfg.NVIDIACTKConfig.Path = config.ResolveNVIDIACTKPath(r.logger, cfg.NVIDIACTKConfig.Path)
|
||||||
cfg.NVIDIAContainerRuntimeHookConfig.Path = config.ResolveNVIDIAContainerRuntimeHookPath(r.logger.Logger, cfg.NVIDIAContainerRuntimeHookConfig.Path)
|
cfg.NVIDIAContainerRuntimeHookConfig.Path = config.ResolveNVIDIAContainerRuntimeHookPath(r.logger, cfg.NVIDIAContainerRuntimeHookConfig.Path)
|
||||||
|
|
||||||
// Print the config to the output.
|
// Print the config to the output.
|
||||||
configJSON, err := json.MarshalIndent(cfg, "", " ")
|
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)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err)
|
return fmt.Errorf("failed to create NVIDIA Container Runtime: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ import (
|
|||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
|
"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/modifier"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
|
"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
|
// 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)
|
lowLevelRuntime, err := oci.NewLowLevelRuntime(logger, cfg.NVIDIAContainerRuntimeConfig.Runtimes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error constructing low-level runtime: %v", err)
|
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.
|
// 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)
|
mode := info.ResolveAutoMode(logger, cfg.NVIDIAContainerRuntimeConfig.Mode)
|
||||||
modeModifier, err := newModeModifier(logger, mode, cfg, ociSpec, argv)
|
modeModifier, err := newModeModifier(logger, mode, cfg, ociSpec, argv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -95,7 +95,7 @@ func newSpecModifier(logger *logrus.Logger, cfg *config.Config, ociSpec oci.Spec
|
|||||||
return modifiers, nil
|
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 {
|
switch mode {
|
||||||
case "legacy":
|
case "legacy":
|
||||||
return modifier.NewStableRuntimeModifier(logger, cfg.NVIDIAContainerRuntimeHookConfig.Path), nil
|
return modifier.NewStableRuntimeModifier(logger, cfg.NVIDIAContainerRuntimeHookConfig.Path), nil
|
||||||
|
@ -18,6 +18,7 @@ package runtime
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -26,7 +27,6 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/config"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/test"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
testlog "github.com/sirupsen/logrus/hooks/test"
|
testlog "github.com/sirupsen/logrus/hooks/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@ -41,7 +41,7 @@ func TestMain(m *testing.M) {
|
|||||||
var err error
|
var err error
|
||||||
moduleRoot, err := test.GetModuleRoot()
|
moduleRoot, err := test.GetModuleRoot()
|
||||||
if err != nil {
|
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")
|
testBinPath := filepath.Join(moduleRoot, "test", "bin")
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ func TestMain(m *testing.M) {
|
|||||||
// Confirm that the environment is configured correctly
|
// Confirm that the environment is configured correctly
|
||||||
runcPath, err := exec.LookPath(runcExecutableName)
|
runcPath, err := exec.LookPath(runcExecutableName)
|
||||||
if err != nil || filepath.Join(testBinPath, runcExecutableName) != runcPath {
|
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
|
// RUN TESTS
|
||||||
|
@ -16,13 +16,13 @@
|
|||||||
|
|
||||||
package system
|
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
|
// Option is a functional option for the system command
|
||||||
type Option func(*Interface)
|
type Option func(*Interface)
|
||||||
|
|
||||||
// WithLogger sets the logger for the system command
|
// WithLogger sets the logger for the system command
|
||||||
func WithLogger(logger *logrus.Logger) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(i *Interface) {
|
return func(i *Interface) {
|
||||||
i.logger = logger
|
i.logger = logger
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/proc/devices"
|
"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"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface is the interface for the system command
|
// Interface is the interface for the system command
|
||||||
type Interface struct {
|
type Interface struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
dryRun bool
|
dryRun bool
|
||||||
loadKernelModules bool
|
loadKernelModules bool
|
||||||
nvidiaDevices nvidiaDevices
|
nvidiaDevices nvidiaDevices
|
||||||
@ -39,7 +39,7 @@ type Interface struct {
|
|||||||
// New constructs a system command with the specified options
|
// New constructs a system command with the specified options
|
||||||
func New(opts ...Option) (*Interface, error) {
|
func New(opts ...Option) (*Interface, error) {
|
||||||
i := &Interface{
|
i := &Interface{
|
||||||
logger: logrus.StandardLogger(),
|
logger: logger.New(),
|
||||||
}
|
}
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(i)
|
opt(i)
|
||||||
|
@ -20,12 +20,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/pelletier/go-toml"
|
"github.com/pelletier/go-toml"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
type builder struct {
|
type builder struct {
|
||||||
path string
|
logger logger.Interface
|
||||||
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option defines a function that can be used to configure the config builder
|
// 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{}
|
empty := toml.Tree{}
|
||||||
return (*Config)(&empty), nil
|
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
|
// loadConfig loads the cri-o config from disk
|
||||||
func loadConfig(config string) (*Config, error) {
|
func (b *builder) loadConfig(config string) (*Config, error) {
|
||||||
log.Infof("Loading config: %v", config)
|
b.logger.Infof("Loading config: %v", config)
|
||||||
|
|
||||||
info, err := os.Stat(config)
|
info, err := os.Stat(config)
|
||||||
if os.IsExist(err) && info.IsDir() {
|
if os.IsExist(err) && info.IsDir() {
|
||||||
@ -67,7 +72,7 @@ func loadConfig(config string) (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Successfully loaded config")
|
b.logger.Infof("Successfully loaded config")
|
||||||
|
|
||||||
return (*Config)(cfg), nil
|
return (*Config)(cfg), nil
|
||||||
}
|
}
|
||||||
|
@ -20,15 +20,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// newCommonNVMLDiscoverer returns a discoverer for entities that are not associated with a specific CDI device.
|
// newCommonNVMLDiscoverer returns a discoverer for entities that are not associated with a specific CDI device.
|
||||||
// This includes driver libraries and meta devices, for example.
|
// 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(
|
metaDevices := discover.NewDeviceDiscoverer(
|
||||||
logger,
|
logger,
|
||||||
lookup.NewCharDeviceLocator(
|
lookup.NewCharDeviceLocator(
|
||||||
|
@ -18,7 +18,7 @@ package nvcdi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -26,7 +26,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// newDXGDeviceDiscoverer returns a Discoverer for DXG devices under WSL2.
|
// 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(
|
deviceNodes := discover.NewCharDeviceDiscoverer(
|
||||||
logger,
|
logger,
|
||||||
[]string{dxgDeviceNode},
|
[]string{dxgDeviceNode},
|
||||||
|
@ -22,15 +22,15 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"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"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/cuda"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDriverDiscoverer creates a discoverer for the libraries and binaries associated with a driver installation.
|
// 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.
|
// 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 {
|
if r := nvmllib.Init(); r != nvml.SUCCESS {
|
||||||
return nil, fmt.Errorf("failed to initalize NVML: %v", r)
|
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)
|
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)
|
libraries, err := NewDriverLibraryDiscoverer(logger, driverRoot, nvidiaCTKPath, version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create discoverer for driver libraries: %v", err)
|
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.
|
// 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)
|
libraryPaths, err := getVersionLibs(logger, driverRoot, version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get libraries for driver version: %v", err)
|
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.
|
// 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")
|
gspFirmwarePath := filepath.Join("/lib/firmware/nvidia", version, "gsp*.bin")
|
||||||
return discover.NewMounts(
|
return discover.NewMounts(
|
||||||
logger,
|
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.
|
// 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(
|
return discover.NewMounts(
|
||||||
logger,
|
logger,
|
||||||
lookup.NewExecutableLocator(logger, driverRoot),
|
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.
|
// 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.
|
// 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.
|
// 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)
|
logger.Infof("Using driver version %v", version)
|
||||||
|
|
||||||
libCudaPaths, err := cuda.New(
|
libCudaPaths, err := cuda.New(
|
||||||
|
@ -22,8 +22,8 @@ import (
|
|||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/dxcore"
|
"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/NVIDIA/nvidia-container-toolkit/internal/lookup"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var requiredDriverStoreFiles = []string{
|
var requiredDriverStoreFiles = []string{
|
||||||
@ -38,7 +38,7 @@ var requiredDriverStoreFiles = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// newWSLDriverDiscoverer returns a Discoverer for WSL2 drivers.
|
// 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()
|
err := dxcore.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to initialize dxcore: %v", err)
|
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.
|
// 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
|
var searchPaths []string
|
||||||
seen := make(map[string]bool)
|
seen := make(map[string]bool)
|
||||||
for _, path := range driverStorePaths {
|
for _, path := range driverStorePaths {
|
||||||
|
@ -25,9 +25,9 @@ import (
|
|||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/edits"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/edits"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/info/drm"
|
"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/pkg/cdi"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/specs-go"
|
"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/nvlib/device"
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
"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
|
// byPathHookDiscoverer discovers the entities required for injecting by-path DRM device links
|
||||||
type byPathHookDiscoverer struct {
|
type byPathHookDiscoverer struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
driverRoot string
|
driverRoot string
|
||||||
nvidiaCTKPath string
|
nvidiaCTKPath string
|
||||||
pciBusID string
|
pciBusID string
|
||||||
@ -79,7 +79,7 @@ type byPathHookDiscoverer struct {
|
|||||||
var _ discover.Discover = (*byPathHookDiscoverer)(nil)
|
var _ discover.Discover = (*byPathHookDiscoverer)(nil)
|
||||||
|
|
||||||
// newFullGPUDiscoverer creates a discoverer for the full GPU defined by the specified device.
|
// 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.
|
// 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.
|
// This will allow reuse here and in other code where the paths are queried such as the NVIDIA device plugin.
|
||||||
minor, ret := d.GetMinorNumber()
|
minor, ret := d.GetMinorNumber()
|
||||||
|
@ -20,9 +20,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover/csv"
|
"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/spec"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
|
"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/device"
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvlib/info"
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
||||||
@ -38,7 +38,7 @@ type wrapper struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type nvcdilib struct {
|
type nvcdilib struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
nvmllib nvml.Interface
|
nvmllib nvml.Interface
|
||||||
mode string
|
mode string
|
||||||
devicelib device.Interface
|
devicelib device.Interface
|
||||||
@ -66,7 +66,7 @@ func New(opts ...Option) (Interface, error) {
|
|||||||
l.mode = ModeAuto
|
l.mode = ModeAuto
|
||||||
}
|
}
|
||||||
if l.logger == nil {
|
if l.logger == nil {
|
||||||
l.logger = logrus.StandardLogger()
|
l.logger = logger.New()
|
||||||
}
|
}
|
||||||
if l.deviceNamer == nil {
|
if l.deviceNamer == nil {
|
||||||
l.deviceNamer, _ = NewDeviceNamer(DeviceNameStrategyIndex)
|
l.deviceNamer, _ = NewDeviceNamer(DeviceNameStrategyIndex)
|
||||||
|
@ -21,10 +21,10 @@ import (
|
|||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/edits"
|
"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/NVIDIA/nvidia-container-toolkit/internal/nvcaps"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
"github.com/container-orchestrated-devices/container-device-interface/pkg/cdi"
|
||||||
"github.com/container-orchestrated-devices/container-device-interface/specs-go"
|
"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/nvlib/device"
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
"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
|
// 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)
|
computeInstance, err := newComputeInstanceDiscoverer(logger, driverRoot, gpu, gi, ci)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to create discoverer for Compute Instance: %v", err)
|
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
|
// 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)
|
parentPath := fmt.Sprintf("/dev/nvidia%d", gpu)
|
||||||
|
|
||||||
migCaps, err := nvcaps.NewMigCaps()
|
migCaps, err := nvcaps.NewMigCaps()
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
package nvcdi
|
package nvcdi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/pkg/nvcdi/transform"
|
"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/device"
|
||||||
"gitlab.com/nvidia/cloud-native/go-nvlib/pkg/nvml"
|
"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
|
// WithLogger sets the logger for the library
|
||||||
func WithLogger(logger *logrus.Logger) Option {
|
func WithLogger(logger logger.Interface) Option {
|
||||||
return func(l *nvcdilib) {
|
return func(l *nvcdilib) {
|
||||||
l.logger = logger
|
l.logger = logger
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,11 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/discover"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type deviceFolderPermissions struct {
|
type deviceFolderPermissions struct {
|
||||||
logger *logrus.Logger
|
logger logger.Interface
|
||||||
driverRoot string
|
driverRoot string
|
||||||
nvidiaCTKPath string
|
nvidiaCTKPath string
|
||||||
devices discover.Discover
|
devices discover.Discover
|
||||||
@ -39,7 +39,7 @@ var _ discover.Discover = (*deviceFolderPermissions)(nil)
|
|||||||
// The nested devices that are applicable to the NVIDIA GPU devices are:
|
// The nested devices that are applicable to the NVIDIA GPU devices are:
|
||||||
// - DRM devices at /dev/dri/*
|
// - DRM devices at /dev/dri/*
|
||||||
// - NVIDIA Caps devices at /dev/nvidia-caps/*
|
// - 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{
|
d := &deviceFolderPermissions{
|
||||||
logger: logger,
|
logger: logger,
|
||||||
driverRoot: driverRoot,
|
driverRoot: driverRoot,
|
||||||
|
Loading…
Reference in New Issue
Block a user