Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions cmd/nvidia-cdi-hook/chmod/chmod.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package chmod

import (
"context"
"errors"
"fmt"
"io/fs"
Expand All @@ -25,7 +26,7 @@ import (
"strconv"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
Expand All @@ -36,7 +37,7 @@ type command struct {
}

type config struct {
paths cli.StringSlice
paths []string
modeStr string
mode fs.FileMode
containerSpec string
Expand All @@ -58,36 +59,35 @@ func (m command) build() *cli.Command {
c := cli.Command{
Name: "chmod",
Usage: "Set the permissions of folders in the container by running chmod. The container root is prefixed to the specified paths.",
Before: func(c *cli.Context) error {
return validateFlags(c, &cfg)
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
return ctx, m.validateFlags(cmd, &cfg)
},
Action: func(c *cli.Context) error {
return m.run(c, &cfg)
Action: func(ctx context.Context, cmd *cli.Command) error {
return m.run(cmd, &cfg)
},
}

c.Flags = []cli.Flag{
&cli.StringSliceFlag{
Name: "path",
Usage: "Specify a path to apply the specified mode to",
Destination: &cfg.paths,
},
&cli.StringFlag{
Name: "mode",
Usage: "Specify the file mode",
Destination: &cfg.modeStr,
},
&cli.StringFlag{
Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
Destination: &cfg.containerSpec,
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "path",
Usage: "Specify a path to apply the specified mode to",
Destination: &cfg.paths,
},
&cli.StringFlag{
Name: "mode",
Usage: "Specify the file mode",
Destination: &cfg.modeStr,
},
&cli.StringFlag{
Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
Destination: &cfg.containerSpec,
},
},
}

return &c
}

func validateFlags(c *cli.Context, cfg *config) error {
func (m command) validateFlags(_ *cli.Command, cfg *config) error {
if strings.TrimSpace(cfg.modeStr) == "" {
return fmt.Errorf("a non-empty mode must be specified")
}
Expand All @@ -98,7 +98,7 @@ func validateFlags(c *cli.Context, cfg *config) error {
}
cfg.mode = fs.FileMode(modeInt)

for _, p := range cfg.paths.Value() {
for _, p := range cfg.paths {
if strings.TrimSpace(p) == "" {
return fmt.Errorf("paths must not be empty")
}
Expand All @@ -107,7 +107,7 @@ func validateFlags(c *cli.Context, cfg *config) error {
return nil
}

func (m command) run(c *cli.Context, cfg *config) error {
func (m command) run(_ *cli.Command, cfg *config) error {
s, err := oci.LoadContainerState(cfg.containerSpec)
if err != nil {
return fmt.Errorf("failed to load container state: %v", err)
Expand All @@ -121,7 +121,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
return fmt.Errorf("empty container root detected")
}

paths := m.getPaths(containerRoot, cfg.paths.Value(), cfg.mode)
paths := m.getPaths(containerRoot, cfg.paths, cfg.mode)
if len(paths) == 0 {
m.logger.Debugf("No paths specified; exiting")
return nil
Expand Down
4 changes: 2 additions & 2 deletions cmd/nvidia-cdi-hook/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package commands

import (
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/chmod"
createsonamesymlinks "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/create-soname-symlinks"
Expand Down Expand Up @@ -45,7 +45,7 @@ func New(logger logger.Interface) []*cli.Command {
// hook has been specified.
// This happens if a subcommand is provided that does not match one of the
// subcommands that has been explicitly specified.
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Context) {
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Command) {
args := c.Args().Slice()
if len(args) == 0 {
logger.Warningf("No CDI hook specified")
Expand Down
54 changes: 27 additions & 27 deletions cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
package create_soname_symlinks

import (
"context"
"errors"
"fmt"
"log"
"os"

"github.com/moby/sys/reexec"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/NVIDIA/nvidia-container-toolkit/internal/ldconfig"
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
Expand All @@ -40,7 +41,7 @@ type command struct {
}

type options struct {
folders cli.StringSlice
folders []string
ldconfigPath string
containerSpec string
}
Expand Down Expand Up @@ -68,44 +69,43 @@ func (m command) build() *cli.Command {
c := cli.Command{
Name: "create-soname-symlinks",
Usage: "Create soname symlinks libraries in specified directories",
Before: func(c *cli.Context) error {
return m.validateFlags(c, &cfg)
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
return ctx, m.validateFlags(cmd, &cfg)
},
Action: func(c *cli.Context) error {
return m.run(c, &cfg)
Action: func(ctx context.Context, cmd *cli.Command) error {
return m.run(cmd, &cfg)
},
}

c.Flags = []cli.Flag{
&cli.StringSliceFlag{
Name: "folder",
Usage: "Specify a directory to generate soname symlinks in. Can be specified multiple times",
Destination: &cfg.folders,
},
&cli.StringFlag{
Name: "ldconfig-path",
Usage: "Specify the path to ldconfig on the host",
Destination: &cfg.ldconfigPath,
Value: "/sbin/ldconfig",
},
&cli.StringFlag{
Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
Destination: &cfg.containerSpec,
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "folder",
Usage: "Specify a directory to generate soname symlinks in. Can be specified multiple times",
Destination: &cfg.folders,
},
&cli.StringFlag{
Name: "ldconfig-path",
Usage: "Specify the path to ldconfig on the host",
Destination: &cfg.ldconfigPath,
Value: "/sbin/ldconfig",
},
&cli.StringFlag{
Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
Destination: &cfg.containerSpec,
},
},
}

return &c
}

func (m command) validateFlags(c *cli.Context, cfg *options) error {
func (m command) validateFlags(_ *cli.Command, cfg *options) error {
if cfg.ldconfigPath == "" {
return errors.New("ldconfig-path must be specified")
}
return nil
}

func (m command) run(c *cli.Context, cfg *options) error {
func (m command) run(_ *cli.Command, cfg *options) error {
s, err := oci.LoadContainerState(cfg.containerSpec)
if err != nil {
return fmt.Errorf("failed to load container state: %v", err)
Expand All @@ -120,7 +120,7 @@ func (m command) run(c *cli.Context, cfg *options) error {
reexecUpdateLdCacheCommandName,
cfg.ldconfigPath,
containerRootDir,
cfg.folders.Value()...,
cfg.folders...,
)
if err != nil {
return err
Expand Down
40 changes: 20 additions & 20 deletions cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package symlinks

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/moby/sys/symlink"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/internal/lookup/symlinks"
Expand All @@ -36,7 +37,7 @@ type command struct {
}

type config struct {
links cli.StringSlice
links []string
containerSpec string
}

Expand All @@ -55,30 +56,29 @@ func (m command) build() *cli.Command {
c := cli.Command{
Name: "create-symlinks",
Usage: "A hook to create symlinks in the container.",
Action: func(c *cli.Context) error {
return m.run(c, &cfg)
Action: func(_ context.Context, cmd *cli.Command) error {
return m.run(cmd, &cfg)
},
}

c.Flags = []cli.Flag{
&cli.StringSliceFlag{
Name: "link",
Usage: "Specify a specific link to create. The link is specified as target::link. If the link exists in the container root, it is removed.",
Destination: &cfg.links,
},
// The following flags are testing-only flags.
&cli.StringFlag{
Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.",
Destination: &cfg.containerSpec,
Hidden: true,
Flags: []cli.Flag{
&cli.StringSliceFlag{
Name: "link",
Usage: "Specify a specific link to create. The link is specified as target::link. If the link exists in the container root, it is removed.",
Destination: &cfg.links,
},
// The following flags are testing-only flags.
&cli.StringFlag{
Name: "container-spec",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN. This is only intended for testing.",
Destination: &cfg.containerSpec,
Hidden: true,
},
},
}

return &c
}

func (m command) run(c *cli.Context, cfg *config) error {
func (m command) run(_ *cli.Command, cfg *config) error {
s, err := oci.LoadContainerState(cfg.containerSpec)
if err != nil {
return fmt.Errorf("failed to load container state: %v", err)
Expand All @@ -90,7 +90,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
}

created := make(map[string]bool)
for _, l := range cfg.links.Value() {
for _, l := range cfg.links {
if created[l] {
m.logger.Debugf("Link %v already processed", l)
continue
Expand Down
42 changes: 21 additions & 21 deletions cmd/nvidia-cdi-hook/cudacompat/cudacompat.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
package cudacompat

import (
"context"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
Expand Down Expand Up @@ -63,37 +64,36 @@ func (m command) build() *cli.Command {
c := cli.Command{
Name: "enable-cuda-compat",
Usage: "This hook ensures that the folder containing the CUDA compat libraries is added to the ldconfig search path if required.",
Before: func(c *cli.Context) error {
return m.validateFlags(c, &cfg)
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
return ctx, m.validateFlags(cmd, &cfg)
},
Action: func(c *cli.Context) error {
return m.run(c, &cfg)
Action: func(ctx context.Context, cmd *cli.Command) error {
return m.run(cmd, &cfg)
},
}

c.Flags = []cli.Flag{
&cli.StringFlag{
Name: "host-driver-version",
Usage: "Specify the host driver version. If the CUDA compat libraries detected in the container do not have a higher MAJOR version, the hook is a no-op.",
Destination: &cfg.hostDriverVersion,
},
&cli.StringFlag{
Name: "container-spec",
Hidden: true,
Category: "testing-only",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
Destination: &cfg.containerSpec,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host-driver-version",
Usage: "Specify the host driver version. If the CUDA compat libraries detected in the container do not have a higher MAJOR version, the hook is a no-op.",
Destination: &cfg.hostDriverVersion,
},
&cli.StringFlag{
Name: "container-spec",
Hidden: true,
Category: "testing-only",
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
Destination: &cfg.containerSpec,
},
},
}

return &c
}

func (m command) validateFlags(_ *cli.Context, cfg *options) error {
func (m command) validateFlags(cmd *cli.Command, cfg *options) error {
return nil
}

func (m command) run(_ *cli.Context, cfg *options) error {
func (m command) run(_ *cli.Command, cfg *options) error {
if cfg.hostDriverVersion == "" {
return nil
}
Expand Down
Loading