From c31427f14bb1374cb4b10e921ca05fefe94583fc Mon Sep 17 00:00:00 2001 From: Evan Lezar Date: Wed, 19 Mar 2025 17:03:27 +0200 Subject: [PATCH] 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. Signed-off-by: Evan Lezar --- cmd/nvidia-cdi-hook/commands/commands.go | 5 +++++ cmd/nvidia-cdi-hook/main.go | 5 +++++ cmd/nvidia-ctk/hook/hook.go | 3 +++ 3 files changed, 13 insertions(+) diff --git a/cmd/nvidia-cdi-hook/commands/commands.go b/cmd/nvidia-cdi-hook/commands/commands.go index 3f80ba9b..c840f939 100644 --- a/cmd/nvidia-cdi-hook/commands/commands.go +++ b/cmd/nvidia-cdi-hook/commands/commands.go @@ -36,3 +36,8 @@ func New(logger logger.Interface) []*cli.Command { cudacompat.NewCommand(logger), } } + +func WarnOnUnsupportedSubcommand(logger logger.Interface, c *cli.Context) error { + logger.Warningf("Unsupported hook or arguments %v", c.Args()) + return nil +} diff --git a/cmd/nvidia-cdi-hook/main.go b/cmd/nvidia-cdi-hook/main.go index d7b7c271..d5341433 100644 --- a/cmd/nvidia-cdi-hook/main.go +++ b/cmd/nvidia-cdi-hook/main.go @@ -51,6 +51,11 @@ func main() { c.Usage = "Command to structure files for usage inside a container, called as hooks from a container runtime, defined in a CDI yaml file" c.Version = info.GetVersionString() + // We add an action to the hook + c.Action = func(ctx *cli.Context) error { + return commands.WarnOnUnsupportedSubcommand(logger, ctx) + } + // Setup the flags for this command c.Flags = []cli.Flag{ &cli.BoolFlag{ diff --git a/cmd/nvidia-ctk/hook/hook.go b/cmd/nvidia-ctk/hook/hook.go index a638d2a7..f958dc79 100644 --- a/cmd/nvidia-ctk/hook/hook.go +++ b/cmd/nvidia-ctk/hook/hook.go @@ -41,6 +41,9 @@ func (m hookCommand) build() *cli.Command { hook := cli.Command{ Name: "hook", Usage: "A collection of hooks that may be injected into an OCI spec", + Action: func(ctx *cli.Context) error { + return commands.WarnOnUnsupportedSubcommand(m.logger, ctx) + }, } hook.Subcommands = commands.New(m.logger)