Conversation
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>
v0ropaev
requested review from
cdesiniotis,
henry118 and
tariq1890
as code owners
September 28, 2026 19:13
v0ropaev
force-pushed
the
fix/hook-config-option-name
branch
from
October 1, 2026 21:24
fe699e5 to
527997c
Compare
Contributor
Author
|
Signed and force-pushed, the commit shows as verified now. Sign-off is still there, only the signature was added. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
getConfigOptionincmd/nvidia-container-runtime-hook/hook_config.goreads the toml tag off a struct field so the panic message can name the config option:reflect.Type.FieldByNamepanics on anything that is not a struct kind, and**hookConfigis a pointer, so the call panics before it can return anything:Its one caller is the invalid-capability branch in
getHookConfig(hook_config.go:61-64), so starting a container with an unsupportedsupported-driver-capabilitiesreports that reflection error instead ofThe existing
TestGetHookConfigcase for that input asserts onlyrequire.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)withcalready a*hookConfig, so it was**hookConfigtoo.Reflecting over
hookConfigfixes it.FieldByNamewalks the embedded*Config, so the tag comes back assupported-driver-capabilities.Checklist
make test)make lint) — golangci-lint is not installed here;gofmt -s -landgo veton the package are cleanTesting
Reduced the two versions to a standalone program with the same struct shape (
sync.Mutex, embedded*Configwith the toml tag, embeddedcontainerConfig):TestGetConfigOptionis 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/... ./internal/...has two pre-existing failures,TestGoodInputandTestDuplicateHookincmd/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.