Skip to content

Commit 2453fb2

Browse files
[no-relnote] Migrate to urfave v3
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent ced79e5 commit 2453fb2

File tree

151 files changed

+7200
-19284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+7200
-19284
lines changed

cmd/nvidia-cdi-hook/chmod/chmod.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package chmod
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"io/fs"
@@ -25,7 +26,7 @@ import (
2526
"strconv"
2627
"strings"
2728

28-
"github.com/urfave/cli/v2"
29+
"github.com/urfave/cli/v3"
2930

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

3839
type config struct {
39-
paths cli.StringSlice
40+
paths []string
4041
modeStr string
4142
mode fs.FileMode
4243
containerSpec string
@@ -58,11 +59,11 @@ func (m command) build() *cli.Command {
5859
c := cli.Command{
5960
Name: "chmod",
6061
Usage: "Set the permissions of folders in the container by running chmod. The container root is prefixed to the specified paths.",
61-
Before: func(c *cli.Context) error {
62-
return validateFlags(c, &cfg)
62+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
63+
return ctx, validateFlags(cmd, &cfg)
6364
},
64-
Action: func(c *cli.Context) error {
65-
return m.run(c, &cfg)
65+
Action: func(ctx context.Context, cmd *cli.Command) error {
66+
return m.run(cmd, &cfg)
6667
},
6768
}
6869

@@ -87,7 +88,7 @@ func (m command) build() *cli.Command {
8788
return &c
8889
}
8990

90-
func validateFlags(c *cli.Context, cfg *config) error {
91+
func validateFlags(c *cli.Command, cfg *config) error {
9192
if strings.TrimSpace(cfg.modeStr) == "" {
9293
return fmt.Errorf("a non-empty mode must be specified")
9394
}
@@ -98,7 +99,7 @@ func validateFlags(c *cli.Context, cfg *config) error {
9899
}
99100
cfg.mode = fs.FileMode(modeInt)
100101

101-
for _, p := range cfg.paths.Value() {
102+
for _, p := range cfg.paths {
102103
if strings.TrimSpace(p) == "" {
103104
return fmt.Errorf("paths must not be empty")
104105
}
@@ -107,7 +108,7 @@ func validateFlags(c *cli.Context, cfg *config) error {
107108
return nil
108109
}
109110

110-
func (m command) run(c *cli.Context, cfg *config) error {
111+
func (m command) run(c *cli.Command, cfg *config) error {
111112
s, err := oci.LoadContainerState(cfg.containerSpec)
112113
if err != nil {
113114
return fmt.Errorf("failed to load container state: %v", err)
@@ -121,7 +122,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
121122
return fmt.Errorf("empty container root detected")
122123
}
123124

124-
paths := m.getPaths(containerRoot, cfg.paths.Value(), cfg.mode)
125+
paths := m.getPaths(containerRoot, cfg.paths, cfg.mode)
125126
if len(paths) == 0 {
126127
m.logger.Debugf("No paths specified; exiting")
127128
return nil

cmd/nvidia-cdi-hook/commands/commands.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package commands
1818

1919
import (
20-
"github.com/urfave/cli/v2"
20+
"github.com/urfave/cli/v3"
2121

2222
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/chmod"
2323
createsonamesymlinks "github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/create-soname-symlinks"
@@ -45,7 +45,7 @@ func New(logger logger.Interface) []*cli.Command {
4545
// hook has been specified.
4646
// This happens if a subcommand is provided that does not match one of the
4747
// subcommands that has been explicitly specified.
48-
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Context) {
48+
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Command) {
4949
args := c.Args().Slice()
5050
if len(args) == 0 {
5151
logger.Warningf("No CDI hook specified")

cmd/nvidia-cdi-hook/create-soname-symlinks/soname-symlinks.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
package create_soname_symlinks
1919

2020
import (
21+
"context"
2122
"errors"
2223
"fmt"
2324
"log"
2425
"os"
2526

2627
"github.com/moby/sys/reexec"
27-
"github.com/urfave/cli/v2"
28+
"github.com/urfave/cli/v3"
2829

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

4243
type options struct {
43-
folders cli.StringSlice
44+
folders []string
4445
ldconfigPath string
4546
containerSpec string
4647
}
@@ -68,11 +69,11 @@ func (m command) build() *cli.Command {
6869
c := cli.Command{
6970
Name: "create-soname-symlinks",
7071
Usage: "Create soname symlinks libraries in specified directories",
71-
Before: func(c *cli.Context) error {
72-
return m.validateFlags(c, &cfg)
72+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
73+
return ctx, m.validateFlags(cmd, &cfg)
7374
},
74-
Action: func(c *cli.Context) error {
75-
return m.run(c, &cfg)
75+
Action: func(ctx context.Context, cmd *cli.Command) error {
76+
return m.run(cmd, &cfg)
7677
},
7778
}
7879

@@ -98,14 +99,14 @@ func (m command) build() *cli.Command {
9899
return &c
99100
}
100101

101-
func (m command) validateFlags(c *cli.Context, cfg *options) error {
102+
func (m command) validateFlags(c *cli.Command, cfg *options) error {
102103
if cfg.ldconfigPath == "" {
103104
return errors.New("ldconfig-path must be specified")
104105
}
105106
return nil
106107
}
107108

108-
func (m command) run(c *cli.Context, cfg *options) error {
109+
func (m command) run(c *cli.Command, cfg *options) error {
109110
s, err := oci.LoadContainerState(cfg.containerSpec)
110111
if err != nil {
111112
return fmt.Errorf("failed to load container state: %v", err)
@@ -120,7 +121,7 @@ func (m command) run(c *cli.Context, cfg *options) error {
120121
reexecUpdateLdCacheCommandName,
121122
cfg.ldconfigPath,
122123
containerRootDir,
123-
cfg.folders.Value()...,
124+
cfg.folders...,
124125
)
125126
if err != nil {
126127
return err

cmd/nvidia-cdi-hook/create-symlinks/create-symlinks.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
package symlinks
1818

1919
import (
20+
"context"
2021
"errors"
2122
"fmt"
2223
"os"
2324
"path/filepath"
2425
"strings"
2526

2627
"github.com/moby/sys/symlink"
27-
"github.com/urfave/cli/v2"
28+
"github.com/urfave/cli/v3"
2829

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

3839
type config struct {
39-
links cli.StringSlice
40+
links []string
4041
containerSpec string
4142
}
4243

@@ -55,8 +56,8 @@ func (m command) build() *cli.Command {
5556
c := cli.Command{
5657
Name: "create-symlinks",
5758
Usage: "A hook to create symlinks in the container.",
58-
Action: func(c *cli.Context) error {
59-
return m.run(c, &cfg)
59+
Action: func(ctx context.Context, cmd *cli.Command) error {
60+
return m.run(ctx, cmd, &cfg)
6061
},
6162
}
6263

@@ -78,7 +79,7 @@ func (m command) build() *cli.Command {
7879
return &c
7980
}
8081

81-
func (m command) run(c *cli.Context, cfg *config) error {
82+
func (m command) run(ctx context.Context, cmd *cli.Command, cfg *config) error {
8283
s, err := oci.LoadContainerState(cfg.containerSpec)
8384
if err != nil {
8485
return fmt.Errorf("failed to load container state: %v", err)
@@ -90,7 +91,7 @@ func (m command) run(c *cli.Context, cfg *config) error {
9091
}
9192

9293
created := make(map[string]bool)
93-
for _, l := range cfg.links.Value() {
94+
for _, l := range cfg.links {
9495
if created[l] {
9596
m.logger.Debugf("Link %v already processed", l)
9697
continue

cmd/nvidia-cdi-hook/cudacompat/cudacompat.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package cudacompat
1818

1919
import (
20+
"context"
2021
"fmt"
2122
"os"
2223
"path/filepath"
2324
"strconv"
2425
"strings"
2526

26-
"github.com/urfave/cli/v2"
27+
"github.com/urfave/cli/v3"
2728

2829
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
2930
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
@@ -63,11 +64,11 @@ func (m command) build() *cli.Command {
6364
c := cli.Command{
6465
Name: "enable-cuda-compat",
6566
Usage: "This hook ensures that the folder containing the CUDA compat libraries is added to the ldconfig search path if required.",
66-
Before: func(c *cli.Context) error {
67-
return m.validateFlags(c, &cfg)
67+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
68+
return ctx, m.validateFlags(cmd, &cfg)
6869
},
69-
Action: func(c *cli.Context) error {
70-
return m.run(c, &cfg)
70+
Action: func(ctx context.Context, cmd *cli.Command) error {
71+
return m.run(ctx, cmd, &cfg)
7172
},
7273
}
7374

@@ -89,11 +90,11 @@ func (m command) build() *cli.Command {
8990
return &c
9091
}
9192

92-
func (m command) validateFlags(_ *cli.Context, cfg *options) error {
93+
func (m command) validateFlags(cmd *cli.Command, cfg *options) error {
9394
return nil
9495
}
9596

96-
func (m command) run(_ *cli.Context, cfg *options) error {
97+
func (m command) run(ctx context.Context, cmd *cli.Command, cfg *options) error {
9798
if cfg.hostDriverVersion == "" {
9899
return nil
99100
}

cmd/nvidia-cdi-hook/disable-device-node-modification/disable-device-node-modification.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ package disabledevicenodemodification
2020
import (
2121
"bufio"
2222
"bytes"
23+
"context"
2324
"errors"
2425
"fmt"
2526
"io"
2627
"os"
2728
"strings"
2829

29-
"github.com/urfave/cli/v2"
30+
"github.com/urfave/cli/v3"
3031

3132
"github.com/NVIDIA/nvidia-container-toolkit/internal/logger"
3233
"github.com/NVIDIA/nvidia-container-toolkit/internal/oci"
@@ -47,11 +48,11 @@ func NewCommand(logger logger.Interface) *cli.Command {
4748
c := cli.Command{
4849
Name: "disable-device-node-modification",
4950
Usage: "Ensure that the /proc/driver/nvidia/params file present in the container does not allow device node modifications.",
50-
Before: func(c *cli.Context) error {
51-
return validateFlags(c, &cfg)
51+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
52+
return ctx, validateFlags(cmd, &cfg)
5253
},
53-
Action: func(c *cli.Context) error {
54-
return run(c, &cfg)
54+
Action: func(ctx context.Context, cmd *cli.Command) error {
55+
return run(ctx, cmd, &cfg)
5556
},
5657
}
5758

@@ -67,11 +68,11 @@ func NewCommand(logger logger.Interface) *cli.Command {
6768
return &c
6869
}
6970

70-
func validateFlags(c *cli.Context, cfg *options) error {
71+
func validateFlags(c *cli.Command, cfg *options) error {
7172
return nil
7273
}
7374

74-
func run(_ *cli.Context, cfg *options) error {
75+
func run(ctx context.Context, cmd *cli.Command, cfg *options) error {
7576
modifiedParamsFileContents, err := getModifiedNVIDIAParamsContents()
7677
if err != nil {
7778
return fmt.Errorf("failed to get modified params file contents: %w", err)

cmd/nvidia-cdi-hook/main.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
package main
1818

1919
import (
20+
"context"
2021
"os"
2122

2223
"github.com/sirupsen/logrus"
2324

2425
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
2526

26-
cli "github.com/urfave/cli/v2"
27+
cli "github.com/urfave/cli/v3"
2728

2829
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/commands"
2930
)
@@ -44,10 +45,10 @@ func main() {
4445
opts := options{}
4546

4647
// Create the top-level CLI
47-
c := cli.NewApp()
48+
c := cli.Command{}
4849
c.Name = "NVIDIA CDI Hook"
4950
c.UseShortOptionHandling = true
50-
c.EnableBashCompletion = true
51+
c.EnableShellCompletion = true
5152
c.Usage = "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file"
5253
c.Version = info.GetVersionString()
5354

@@ -58,8 +59,8 @@ func main() {
5859
// referring to a new hook that is not yet supported by an older NVIDIA
5960
// Container Toolkit version or a hook that has been removed in newer
6061
// version.
61-
c.Action = func(ctx *cli.Context) error {
62-
commands.IssueUnsupportedHookWarning(logger, ctx)
62+
c.Action = func(ctx context.Context, cmd *cli.Command) error {
63+
commands.IssueUnsupportedHookWarning(logger, cmd)
6364
return nil
6465
}
6566

@@ -71,19 +72,19 @@ func main() {
7172
Usage: "Enable debug-level logging",
7273
Destination: &opts.Debug,
7374
// TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
74-
EnvVars: []string{"NVIDIA_CTK_DEBUG", "NVIDIA_CDI_DEBUG"},
75+
Sources: cli.EnvVars("NVIDIA_CTK_DEBUG", "NVIDIA_CDI_DEBUG"),
7576
},
7677
&cli.BoolFlag{
7778
Name: "quiet",
7879
Usage: "Suppress all output except for errors; overrides --debug",
7980
Destination: &opts.Quiet,
8081
// TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
81-
EnvVars: []string{"NVDIA_CTK_QUIET", "NVIDIA_CDI_QUIET"},
82+
Sources: cli.EnvVars("NVDIA_CTK_QUIET", "NVIDIA_CDI_QUIET"),
8283
},
8384
}
8485

8586
// Set log-level for all subcommands
86-
c.Before = func(c *cli.Context) error {
87+
c.Before = func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
8788
logLevel := logrus.InfoLevel
8889
if opts.Debug {
8990
logLevel = logrus.DebugLevel
@@ -92,14 +93,14 @@ func main() {
9293
logLevel = logrus.ErrorLevel
9394
}
9495
logger.SetLevel(logLevel)
95-
return nil
96+
return ctx, nil
9697
}
9798

9899
// Define the subcommands
99100
c.Commands = commands.New(logger)
100101

101102
// Run the CLI
102-
err := c.Run(os.Args)
103+
err := c.Run(context.Background(), os.Args)
103104
if err != nil {
104105
logger.Errorf("%v", err)
105106
os.Exit(1)

0 commit comments

Comments
 (0)