Skip to content

Commit b306ca9

Browse files
[no-relnote] Fix typo on nvidia-ctk-hook cmd
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 62f28e7 commit b306ca9

File tree

9 files changed

+157
-175
lines changed

9 files changed

+157
-175
lines changed

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,25 @@ func (m command) build() *cli.Command {
6464
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
6565
return ctx, m.validateFlags(cmd, &cfg)
6666
},
67-
Action: func(ctx context.Context, cmd *cli.Command) error {
68-
return m.run(cmd, &cfg)
67+
Action: func(_ context.Context, _ *cli.Command) error {
68+
return m.run(nil, &cfg)
6969
},
70-
}
71-
72-
c.Flags = []cli.Flag{
73-
&cli.StringSliceFlag{
74-
Name: "path",
75-
Usage: "Specify a path to apply the specified mode to",
76-
Destination: &cfg.paths,
77-
},
78-
&cli.StringFlag{
79-
Name: "mode",
80-
Usage: "Specify the file mode",
81-
Destination: &cfg.modeStr,
82-
},
83-
&cli.StringFlag{
84-
Name: "container-spec",
85-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
86-
Destination: &cfg.containerSpec,
70+
Flags: []cli.Flag{
71+
&cli.StringSliceFlag{
72+
Name: "path",
73+
Usage: "Specify a path to apply the specified mode to",
74+
Destination: &cfg.paths,
75+
},
76+
&cli.StringFlag{
77+
Name: "mode",
78+
Usage: "Specify the file mode",
79+
Destination: &cfg.modeStr,
80+
},
81+
&cli.StringFlag{
82+
Name: "container-spec",
83+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
84+
Destination: &cfg.containerSpec,
85+
},
8786
},
8887
}
8988

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,26 @@ func (m command) build() *cli.Command {
7474
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
7575
return ctx, m.validateFlags(cmd, &cfg)
7676
},
77-
Action: func(ctx context.Context, cmd *cli.Command) error {
78-
return m.run(cmd, &cfg)
77+
Action: func(_ context.Context, _ *cli.Command) error {
78+
return m.run(nil, &cfg)
7979
},
80-
}
81-
82-
c.Flags = []cli.Flag{
83-
&cli.StringSliceFlag{
84-
Name: "folder",
85-
Usage: "Specify a directory to generate soname symlinks in. Can be specified multiple times",
86-
Destination: &cfg.folders,
87-
},
88-
&cli.StringFlag{
89-
Name: "ldconfig-path",
90-
Usage: "Specify the path to ldconfig on the host",
91-
Destination: &cfg.ldconfigPath,
92-
Value: "/sbin/ldconfig",
93-
},
94-
&cli.StringFlag{
95-
Name: "container-spec",
96-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
97-
Destination: &cfg.containerSpec,
80+
Flags: []cli.Flag{
81+
&cli.StringSliceFlag{
82+
Name: "folder",
83+
Usage: "Specify a directory to generate soname symlinks in. Can be specified multiple times",
84+
Destination: &cfg.folders,
85+
},
86+
&cli.StringFlag{
87+
Name: "ldconfig-path",
88+
Usage: "Specify the path to ldconfig on the host",
89+
Destination: &cfg.ldconfigPath,
90+
Value: "/sbin/ldconfig",
91+
},
92+
&cli.StringFlag{
93+
Name: "container-spec",
94+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
95+
Destination: &cfg.containerSpec,
96+
},
9897
},
9998
}
10099

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,19 @@ func (m command) build() *cli.Command {
6161
Action: func(_ context.Context, cmd *cli.Command) error {
6262
return m.run(cmd, &cfg)
6363
},
64-
}
65-
66-
c.Flags = []cli.Flag{
67-
&cli.StringSliceFlag{
68-
Name: "link",
69-
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.",
70-
Destination: &cfg.links,
71-
},
72-
// The following flags are testing-only flags.
73-
&cli.StringFlag{
74-
Name: "container-spec",
75-
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.",
76-
Destination: &cfg.containerSpec,
77-
Hidden: true,
64+
Flags: []cli.Flag{
65+
&cli.StringSliceFlag{
66+
Name: "link",
67+
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.",
68+
Destination: &cfg.links,
69+
},
70+
// The following flags are testing-only flags.
71+
&cli.StringFlag{
72+
Name: "container-spec",
73+
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.",
74+
Destination: &cfg.containerSpec,
75+
Hidden: true,
76+
},
7877
},
7978
}
8079

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,29 @@ func (m command) build() *cli.Command {
6969
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
7070
return ctx, m.validateFlags(cmd, &cfg)
7171
},
72-
Action: func(ctx context.Context, cmd *cli.Command) error {
73-
return m.run(cmd, &cfg)
72+
Action: func(_ context.Context, _ *cli.Command) error {
73+
return m.run(nil, &cfg)
7474
},
75-
}
76-
77-
c.Flags = []cli.Flag{
78-
&cli.StringFlag{
79-
Name: "host-driver-version",
80-
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.",
81-
Destination: &cfg.hostDriverVersion,
82-
},
83-
&cli.StringFlag{
84-
Name: "container-spec",
85-
Hidden: true,
86-
Category: "testing-only",
87-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
88-
Destination: &cfg.containerSpec,
75+
Flags: []cli.Flag{
76+
&cli.StringFlag{
77+
Name: "host-driver-version",
78+
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.",
79+
Destination: &cfg.hostDriverVersion,
80+
},
81+
&cli.StringFlag{
82+
Name: "container-spec",
83+
Hidden: true,
84+
Category: "testing-only",
85+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
86+
Destination: &cfg.containerSpec,
87+
},
8988
},
9089
}
9190

9291
return &c
9392
}
9493

95-
func (m command) validateFlags(cmd *cli.Command, cfg *options) error {
94+
func (m command) validateFlags(_ *cli.Command, _ *options) error {
9695
return nil
9796
}
9897

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,27 @@ func NewCommand(logger logger.Interface) *cli.Command {
5353
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
5454
return ctx, validateFlags(cmd, &cfg)
5555
},
56-
Action: func(ctx context.Context, cmd *cli.Command) error {
57-
return run(ctx, cmd, &cfg)
56+
Action: func(_ context.Context, _ *cli.Command) error {
57+
return run(nil, &cfg)
5858
},
59-
}
60-
61-
c.Flags = []cli.Flag{
62-
&cli.StringFlag{
63-
Name: "container-spec",
64-
Hidden: true,
65-
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
66-
Destination: &cfg.containerSpec,
59+
Flags: []cli.Flag{
60+
&cli.StringFlag{
61+
Name: "container-spec",
62+
Hidden: true,
63+
Usage: "Specify the path to the OCI container spec. If empty or '-' the spec will be read from STDIN",
64+
Destination: &cfg.containerSpec,
65+
},
6766
},
6867
}
6968

7069
return &c
7170
}
7271

73-
func validateFlags(c *cli.Command, cfg *options) error {
72+
func validateFlags(_ *cli.Command, _ *options) error {
7473
return nil
7574
}
7675

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

cmd/nvidia-cdi-hook/main.go

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ import (
2121
"os"
2222

2323
"github.com/sirupsen/logrus"
24-
25-
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
26-
2724
cli "github.com/urfave/cli/v3"
2825

2926
"github.com/NVIDIA/nvidia-container-toolkit/cmd/nvidia-cdi-hook/commands"
27+
"github.com/NVIDIA/nvidia-container-toolkit/internal/info"
3028
)
3129

3230
// options defines the options that can be set for the CLI through config files,
@@ -51,55 +49,51 @@ func main() {
5149
EnableShellCompletion: true,
5250
Usage: "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file",
5351
Version: info.GetVersionString(),
54-
}
55-
56-
// We set the default action for the `nvidia-cdi-hook` command to issue a
57-
// warning and exit with no error.
58-
// This means that if an unsupported hook is run, a container will not fail
59-
// to launch. An unsupported hook could be the result of a CDI specification
60-
// referring to a new hook that is not yet supported by an older NVIDIA
61-
// Container Toolkit version or a hook that has been removed in newer
62-
// version.
63-
c.Action = func(ctx context.Context, cmd *cli.Command) error {
64-
commands.IssueUnsupportedHookWarning(logger, cmd)
65-
return nil
66-
}
67-
68-
// Setup the flags for this command
69-
c.Flags = []cli.Flag{
70-
&cli.BoolFlag{
71-
Name: "debug",
72-
Aliases: []string{"d"},
73-
Usage: "Enable debug-level logging",
74-
Destination: &opts.Debug,
75-
// TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
76-
Sources: cli.EnvVars("NVIDIA_CTK_DEBUG", "NVIDIA_CDI_DEBUG"),
52+
Commands: commands.New(logger),
53+
Flags: []cli.Flag{
54+
&cli.BoolFlag{
55+
Name: "debug",
56+
Aliases: []string{"d"},
57+
Usage: "Enable debug-level logging",
58+
Destination: &opts.Debug,
59+
// TODO: Support for NVIDIA_CDI_DEBUG is deprecated and NVIDIA_CTK_DEBUG should be used instead.
60+
Sources: cli.EnvVars("NVIDIA_CTK_DEBUG", "NVIDIA_CDI_DEBUG"),
61+
},
62+
&cli.BoolFlag{
63+
Name: "quiet",
64+
Usage: "Suppress all output except for errors; overrides --debug",
65+
Destination: &opts.Quiet,
66+
// TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
67+
Sources: cli.EnvVars("NVIDIA_CTK_QUIET", "NVIDIA_CDI_QUIET"),
68+
},
7769
},
78-
&cli.BoolFlag{
79-
Name: "quiet",
80-
Usage: "Suppress all output except for errors; overrides --debug",
81-
Destination: &opts.Quiet,
82-
// TODO: Support for NVIDIA_CDI_QUIET is deprecated and NVIDIA_CTK_QUIET should be used instead.
83-
Sources: cli.EnvVars("NVDIA_CTK_QUIET", "NVIDIA_CDI_QUIET"),
70+
71+
// We set the default action for the `nvidia-cdi-hook` command to issue a
72+
// warning and exit with no error.
73+
// This means that if an unsupported hook is run, a container will not fail
74+
// to launch. An unsupported hook could be the result of a CDI specification
75+
// referring to a new hook that is not yet supported by an older NVIDIA
76+
// Container Toolkit version or a hook that has been removed in newer
77+
// version.
78+
Action: func(ctx context.Context, cmd *cli.Command) error {
79+
commands.IssueUnsupportedHookWarning(logger, cmd)
80+
return nil
8481
},
85-
}
8682

87-
// Set log-level for all subcommands
88-
c.Before = func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
89-
logLevel := logrus.InfoLevel
90-
if opts.Debug {
91-
logLevel = logrus.DebugLevel
92-
}
93-
if opts.Quiet {
94-
logLevel = logrus.ErrorLevel
95-
}
96-
logger.SetLevel(logLevel)
97-
return ctx, nil
83+
// Set log-level for all subcommands
84+
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
85+
logLevel := logrus.InfoLevel
86+
if opts.Debug {
87+
logLevel = logrus.DebugLevel
88+
}
89+
if opts.Quiet {
90+
logLevel = logrus.ErrorLevel
91+
}
92+
logger.SetLevel(logLevel)
93+
return ctx, nil
94+
},
9895
}
9996

100-
// Define the subcommands
101-
c.Commands = commands.New(logger)
102-
10397
// Run the CLI
10498
err := c.Run(context.Background(), os.Args)
10599
if err != nil {

cmd/nvidia-cdi-hook/update-ldcache/update-ldcache.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ type command struct {
4040
}
4141

4242
type options struct {
43-
folders []string
4443
ldconfigPath string
4544
containerSpec string
4645
}
@@ -73,16 +72,15 @@ func (m command) build() *cli.Command {
7372
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {
7473
return ctx, m.validateFlags(cmd, &cfg)
7574
},
76-
Action: func(_ context.Context, cmd *cli.Command) error {
75+
Action: func(ctx context.Context, cmd *cli.Command) error {
7776
return m.run(cmd, &cfg)
7877
},
7978
}
8079

8180
c.Flags = []cli.Flag{
8281
&cli.StringSliceFlag{
83-
Name: "folder",
84-
Usage: "Specify a folder to add to /etc/ld.so.conf before updating the ld cache",
85-
Destination: &cfg.folders,
82+
Name: "folder",
83+
Usage: "Specify a folder to add to /etc/ld.so.conf before updating the ld cache",
8684
},
8785
&cli.StringFlag{
8886
Name: "ldconfig-path",
@@ -100,14 +98,14 @@ func (m command) build() *cli.Command {
10098
return &c
10199
}
102100

103-
func (m command) validateFlags(_ *cli.Command, cfg *options) error {
101+
func (m command) validateFlags(cmd *cli.Command, cfg *options) error {
104102
if cfg.ldconfigPath == "" {
105103
return errors.New("ldconfig-path must be specified")
106104
}
107105
return nil
108106
}
109107

110-
func (m command) run(_ *cli.Command, cfg *options) error {
108+
func (m command) run(cmd *cli.Command, cfg *options) error {
111109
s, err := oci.LoadContainerState(cfg.containerSpec)
112110
if err != nil {
113111
return fmt.Errorf("failed to load container state: %v", err)
@@ -122,7 +120,7 @@ func (m command) run(_ *cli.Command, cfg *options) error {
122120
reexecUpdateLdCacheCommandName,
123121
cfg.ldconfigPath,
124122
containerRootDir,
125-
cfg.folders...,
123+
cmd.StringSlice("folder")...,
126124
)
127125
if err != nil {
128126
return err

cmd/nvidia-ctk/cdi/generate/generate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ import (
3838
)
3939

4040
const (
41-
allDeviceName = "all"
42-
defaultNvidiaCTKPath = "/usr/bin/nvidia-ctk"
41+
allDeviceName = "all"
4342
)
4443

4544
type command struct {

0 commit comments

Comments
 (0)