Skip to content

Fix the config option name in the unsupported-capability panic - #2111

Open
v0ropaev wants to merge 1 commit into
NVIDIA:mainfrom
v0ropaev:fix/hook-config-option-name
Open

v0ropaev wants to merge 1 commit into
NVIDIA:mainfrom
v0ropaev:fix/hook-config-option-name

Conversation

@v0ropaev

Copy link
Copy Markdown
Contributor

Description

getConfigOption in cmd/nvidia-container-runtime-hook/hook_config.go reads the toml tag off a struct field so the panic message can name the config option:

func (c *hookConfig) getConfigOption(fieldName string) string {
	t := reflect.TypeFor[**hookConfig]()
	f, ok := t.FieldByName(fieldName)
	...

reflect.Type.FieldByName panics on anything that is not a struct kind, and **hookConfig is a pointer, so the call panics before it can return anything:

reflect: FieldByName of non-struct type **main.hookConfig

Its one caller is the invalid-capability branch in getHookConfig (hook_config.go:61-64), so starting a container with an unsupported supported-driver-capabilities reports that reflection error instead of

Invalid value for config option 'supported-driver-capabilities'; compute,utility,not-compute (supported: ...)

The existing TestGetHookConfig case for that input asserts only require.Panics, so it passes either way and the wrong message went unnoticed.

This is not from the modernize pass, though that pass touched the line. The original was reflect.TypeOf(&c) with c already a *hookConfig, so it was **hookConfig too.

Reflecting over hookConfig fixes it. FieldByName walks the embedded *Config, so the tag comes back as supported-driver-capabilities.

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Unit tests passing (make test)
  • Lint checks passing (make lint) — golangci-lint is not installed here; gofmt -s -l and go vet on the package are clean
  • Test cases are added for new code paths
  • Commits are signed-off — DCO yes, not GPG signed

Testing

Reduced the two versions to a standalone program with the same struct shape (sync.Mutex, embedded *Config with the toml tag, embedded containerConfig):

current  -> "PANIC reflect: FieldByName of non-struct type **main.hookConfig"
proposed -> "supported-driver-capabilities"

TestGetConfigOption is the regression test, two cases: a field with a tag, and a field that does not exist (which must fall back to the field name). It panics on current main and passes with the change.

go test ./cmd/nvidia-container-runtime-hook/...   ok
go build ./...                                     ok

go test ./cmd/... ./internal/... has two pre-existing failures, TestGoodInput and TestDuplicateHook in cmd/nvidia-container-runtime. They fail the same way on unmodified main in a worktree here, so they are not from this change. Run on darwin/arm64 with Go 1.27.1, no GPU.

getConfigOption reflects over **hookConfig to read the toml tag of a field.
FieldByName panics on anything that is not a struct type, so the call that
was meant to name the option in the panic message panics first:

  reflect: FieldByName of non-struct type **main.hookConfig

The one caller is the invalid-capability branch in getHookConfig, so a
container start with a bad supported-driver-capabilities reports a
reflection error instead of naming the option and the value. The existing
test only asserts that something panics, so it stays green either way.

Reflect over hookConfig. FieldByName walks the embedded *Config, so the
tag comes back as supported-driver-capabilities.

Predates the modernize pass: reflect.TypeOf(&c) had the same problem, with
c already a *hookConfig.

Signed-off-by: Dmitry Voropaev <dy.voropaev@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@v0ropaev
v0ropaev force-pushed the fix/hook-config-option-name branch from fe699e5 to 527997c Compare October 1, 2026 21:24
@v0ropaev

v0ropaev commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Signed and force-pushed, the commit shows as verified now. Sign-off is still there, only the signature was added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant