Skip to content

Commit b3ad04d

Browse files
committed
Issue warning on unsupported CDI hook
To allow for CDI hooks to be added gradually we provide a generic no-op hook for unrecognised subcommands. This will log a warning instead of erroring out. An unsupported hook could be the result of a CDI specification referring to a new hook that is not yet supported by an older NVIDIA Container Toolkit version or a hook that has been removed in newer version. Signed-off-by: Evan Lezar <[email protected]>
1 parent 50a7e2f commit b3ad04d

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,16 @@ func New(logger logger.Interface) []*cli.Command {
3636
cudacompat.NewCommand(logger),
3737
}
3838
}
39+
40+
// IssueUnsupportedHookWarning logs a warning that no hook or an unsupported
41+
// hook has been specified.
42+
// This happens if a subcommand is provided that does not match one of the
43+
// subcommands that has been explicitly specified.
44+
func IssueUnsupportedHookWarning(logger logger.Interface, c *cli.Context) {
45+
args := c.Args().Slice()
46+
if len(args) == 0 {
47+
logger.Warningf("No CDI hook specified")
48+
} else {
49+
logger.Warningf("Unsupported CDI hook: %v", c.Args().Slice()[0])
50+
}
51+
}

cmd/nvidia-cdi-hook/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ func main() {
5151
c.Usage = "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file"
5252
c.Version = info.GetVersionString()
5353

54+
// We set the default action for the `nvidia-cdi-hook` command to issue a
55+
// warning and exit with no error.
56+
// This means that if an unsupported hook is run, a container will not fail
57+
// to launch. An unsupported hook could be the result of a CDI specification
58+
// referring to a new hook that is not yet supported by an older NVIDIA
59+
// Container Toolkit version or a hook that has been removed in newer
60+
// version.
61+
c.Action = func(ctx *cli.Context) error {
62+
commands.IssueUnsupportedHookWarning(logger, ctx)
63+
return nil
64+
}
65+
5466
// Setup the flags for this command
5567
c.Flags = []cli.Flag{
5668
&cli.BoolFlag{

cmd/nvidia-ctk/hook/hook.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type hookCommand struct {
2727
logger logger.Interface
2828
}
2929

30-
// NewCommand constructs a hook command with the specified logger
30+
// NewCommand constructs CLI subcommand for handling CDI hooks.
3131
func NewCommand(logger logger.Interface) *cli.Command {
3232
c := hookCommand{
3333
logger: logger,
@@ -37,10 +37,21 @@ func NewCommand(logger logger.Interface) *cli.Command {
3737

3838
// build
3939
func (m hookCommand) build() *cli.Command {
40-
// Create the 'hook' command
40+
// Create the 'hook' subcommand
4141
hook := cli.Command{
4242
Name: "hook",
4343
Usage: "A collection of hooks that may be injected into an OCI spec",
44+
// We set the default action for the `hook` subcommand to issue a
45+
// warning and exit with no error.
46+
// This means that if an unsupported hook is run, a container will not fail
47+
// to launch. An unsupported hook could be the result of a CDI specification
48+
// referring to a new hook that is not yet supported by an older NVIDIA
49+
// Container Toolkit version or a hook that has been removed in newer
50+
// version.
51+
Action: func(ctx *cli.Context) error {
52+
commands.IssueUnsupportedHookWarning(m.logger, ctx)
53+
return nil
54+
},
4455
}
4556

4657
hook.Subcommands = commands.New(m.logger)

0 commit comments

Comments
 (0)