Skip to content

fix: handle null Docker runtimes - #2109

Merged
henry118 merged 2 commits into
NVIDIA:mainfrom
git-jxj:git-jxj/fix-docker-null-runtimes
Oct 1, 2026
Merged

henry118 merged 2 commits into
NVIDIA:mainfrom
git-jxj:git-jxj/fix-docker-null-runtimes

Conversation

@git-jxj

@git-jxj git-jxj commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

nvidia-ctk runtime configure --runtime=docker --config=daemon.json panics when the file contains {"runtimes":null}. Docker configuration methods also panic when removing or unsetting a null default-runtime, or looking up a null runtime definition.

Use checked type assertions for the runtime map, default runtime, and individual runtime definitions. Null entries are handled like missing entries. File-based regressions cover these paths and verify the saved configuration preserves unrelated settings.

Checklist

  • No secrets, sensitive information, or unrelated changes
  • Unit tests passing (make test) — the same four packages and nine subtests fail on unchanged main; see below
  • Lint checks passing (make lint)
  • Test cases are added for new code paths
  • Commits are signed-off and cryptographically signed

Testing

  • The three added regressions for null default-runtime and null runtime definitions each panic on the previous PR head and pass with the checked assertions. All Docker configuration package tests pass.
  • A freshly built baseline CLI exits 2 for a temporary file containing {"runtimes":null,"log-driver":"json-file"}. The updated CLI exits successfully, preserves log-driver, and produces the same configuration on a second run.
  • make build, make fmt, and make lint completed; lint reported 0 issues. go test -race ./pkg/config/... ./cmd/nvidia-ctk/runtime/... -count=1 passed.
  • make test was rerun on this change and an unchanged checkout of main (84e2c2c182bfa0b2edab4fdca27e5197faba0ca7). Both fail the same nine subtests in cmd/nvidia-ctk-installer, cmd/nvidia-ctk-installer/toolkit, internal/modifier, and pkg/nvcdi, involving driver-library discovery in test fixtures and CSV hook expectations. All other packages pass.

A JSON null runtimes entry decodes to a nil interface. Adding, removing,
or looking up a runtime currently asserts that value to a map and panics.
Treat a null runtimes entry like an absent entry before the assertion.

Cover all three operations using a configuration loaded from a file and
verify unrelated settings survive saving the updated configuration.

Signed-off-by: xinjun.jiang <xinjun.jiang@daocloud.io>
@copy-pr-bot

copy-pr-bot Bot commented Sep 22, 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.

@henry118 henry118 self-assigned this Sep 30, 2026
Comment thread pkg/config/engine/docker/docker.go Outdated
// Read the existing runtimes
runtimes := make(map[string]any)
if _, exists := config["runtimes"]; exists {
if config["runtimes"] != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if config["runtimes"] != nil {
rt, ok := config["runtimes"].(map[string]any); ok {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 8884e35: AddRuntime now uses the checked rt, ok := config["runtimes"].(map[string]any) assertion to reuse the map. The null-runtimes add regression passes.

Comment thread pkg/config/engine/docker/docker.go Outdated
}

if _, exists := config["runtimes"]; exists {
if config["runtimes"] != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as L77

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 8884e35: RemoveRuntime now uses the checked runtime-map assertion directly. The null-runtimes removal regression passes.

Comment thread pkg/config/engine/docker/docker.go Outdated

var runtimes map[string]any
if _, ok := cfg["runtimes"]; ok {
if cfg["runtimes"] != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as L77

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 8884e35: GetRuntimeConfig now uses a checked runtime-map assertion and keeps the map scoped to that branch. The null-runtimes lookup regression passes.

Comment thread pkg/config/engine/docker/docker.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here requires a fix too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8884e35: RemoveRuntime now checks the default-runtime string assertion. Added a file-based regression for removal with "default-runtime": null; it panics on the previous PR head and passes with this change.

Comment thread pkg/config/engine/docker/docker.go Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same fix required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8884e35: the unset path in UpdateDefaultRuntime now checks the default-runtime string assertion. Added a file-based null-default regression; it panics on the previous PR head and passes with this change.

Comment thread pkg/config/engine/docker/docker.go Outdated
if cfg["runtimes"] != nil {
runtimes = cfg["runtimes"].(map[string]any)
if r, ok := runtimes[name]; ok {
dr := dockerRuntime(r.(map[string]any))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same fix required

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 8884e35: individual runtime definitions now use a checked map assertion, so a null definition returns an empty runtime configuration. Added a file-based "runtimes": {"nvidia": null} lookup regression; it panics on the previous PR head and passes with this change.

Use checked type assertions for runtime maps, default runtime names, and
individual runtime definitions. Null default-runtime values and runtime
entries should not panic during removal, unsetting, or lookup.

Add file-based regressions for each remaining null configuration path.

Signed-off-by: xinjun.jiang <xinjun.jiang@daocloud.io>
@henry118

henry118 commented Oct 1, 2026

Copy link
Copy Markdown
Member

/ok to test 8884e35

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 36838559285

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage increased (+0.2%) to 44.266%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 8 of 8 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 13550
Covered Lines: 5998
Line Coverage: 44.27%
Coverage Strength: 0.44 hits per line

💛 - Coveralls

@henry118
henry118 merged commit faef9c9 into NVIDIA:main Oct 1, 2026
21 checks passed
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.

3 participants