[Carry #2280] Add support for CDI devices to device flag#4170
Merged
AkihiroSuda merged 1 commit intocontainerd:mainfrom May 1, 2025
Merged
[Carry #2280] Add support for CDI devices to device flag#4170AkihiroSuda merged 1 commit intocontainerd:mainfrom
AkihiroSuda merged 1 commit intocontainerd:mainfrom
Conversation
548458e to
449537e
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for Container Device Interface (CDI) by introducing new functions to obtain CDI specification directories across supported platforms, updating configuration and CLI flags accordingly, and integrating CDI device injection into container creation.
- Adds CDISpecDirs functions in the defaults package for Windows, Linux, FreeBSD, and Darwin.
- Updates the config structure, CLI flags, and tests to support CDI device injection.
- Integrates CDI devices handling into container run and create commands.
Reviewed Changes
Copilot reviewed 16 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/defaults/defaults_windows.go | Adds a stub CDISpecDirs function returning an empty slice for Windows. |
| pkg/defaults/defaults_linux.go | Implements CDISpecDirs with distinct behavior based on rootless mode. |
| pkg/defaults/defaults_freebsd.go | Provides a CDISpecDirs function returning default CDI spec directories. |
| pkg/defaults/defaults_darwin.go | Provides a CDISpecDirs function returning default CDI spec directories. |
| pkg/config/config.go | Introduces a new field for CDI spec directories in the configuration. |
| pkg/cmd/container/run_cdi.go | Adds a function to configure CDI devices during container run. |
| pkg/cmd/container/create.go | Injects the CDI devices option into the container creation process. |
| pkg/api/types/container_types.go | Adds a CDIDevices field to the container create options structure. |
| docs/config.md | Documents the new --cdi-spec-dirs CLI flag and configuration. |
| cmd/nerdctl/testdata/cdi/vendor1.yaml | Provides an example CDI vendor file for testing purposes. |
| cmd/nerdctl/main.go | Introduces the CLI flag for CDI spec directories. |
| cmd/nerdctl/helpers/flagutil.go | Processes the new cdi-spec-dirs flag and integrates it into global options. |
| cmd/nerdctl/container/container_run_linux_test.go | Adds tests to verify the CDI device injection functionality. |
| cmd/nerdctl/container/container_create.go | Differentiates between standard devices and CDI devices during creation. |
| .github/workflows/test.yml | Temporarily enables CDI support in the Docker daemon for integration tests. |
Files not reviewed (1)
- go.mod: Language not supported
9af8317 to
efe0417
Compare
apostasie
reviewed
Apr 27, 2025
apostasie
reviewed
Apr 27, 2025
apostasie
reviewed
Apr 27, 2025
efe0417 to
8e649bd
Compare
AkihiroSuda
reviewed
Apr 28, 2025
AkihiroSuda
reviewed
Apr 28, 2025
AkihiroSuda
reviewed
Apr 28, 2025
| | `host_gateway_ip` | `--host-gateway-ip` | `NERDCTL_HOST_GATEWAY_IP` | IP address that the special 'host-gateway' string in --add-host resolves to. Defaults to the IP address of the host. It has no effect without setting --add-host | Since 1.3.0 | | ||
| | `bridge_ip` | `--bridge-ip` | `NERDCTL_BRIDGE_IP` | IP address for the default nerdctl bridge network, e.g., 10.1.100.1/24 | Since 2.0.1 | | ||
| | `kube_hide_dupe` | `--kube-hide-dupe` | | Deduplicate images for Kubernetes with namespace k8s.io, no more redundant <none> ones are displayed | Since 2.0.3 | | ||
| | `cdi_spec_dirs` | `--cdi-spec-dirs` | | The folders to use when searching for CDI specifications. | Since 2.0.5 | |
8e649bd to
c34d651
Compare
apostasie
approved these changes
Apr 28, 2025
Contributor
apostasie
left a comment
There was a problem hiding this comment.
@djdongjin one minor nit on help
| helpers.AddPersistentStringFlag(rootCmd, "host-gateway-ip", nil, nil, nil, aliasToBeInherited, cfg.HostGatewayIP, "NERDCTL_HOST_GATEWAY_IP", "IP address that the special 'host-gateway' string in --add-host resolves to. Defaults to the IP address of the host. It has no effect without setting --add-host") | ||
| helpers.AddPersistentStringFlag(rootCmd, "bridge-ip", nil, nil, nil, aliasToBeInherited, cfg.BridgeIP, "NERDCTL_BRIDGE_IP", "IP address for the default nerdctl bridge network") | ||
| rootCmd.PersistentFlags().Bool("kube-hide-dupe", cfg.KubeHideDupe, "Deduplicate images for Kubernetes with namespace k8s.io") | ||
| rootCmd.PersistentFlags().StringSlice("cdi-spec-dirs", cfg.CDISpecDirs, "The directories to search for CDI spec files. Defaults to /etc/cdi,/var/run/cdi") |
Contributor
There was a problem hiding this comment.
We do not mention the defaults for CNI for eg - maybe we can remove them here as well? (or alternatively, mention the rootless defaults as well)
mikebrow
reviewed
Apr 29, 2025
| | `host_gateway_ip` | `--host-gateway-ip` | `NERDCTL_HOST_GATEWAY_IP` | IP address that the special 'host-gateway' string in --add-host resolves to. Defaults to the IP address of the host. It has no effect without setting --add-host | Since 1.3.0 | | ||
| | `bridge_ip` | `--bridge-ip` | `NERDCTL_BRIDGE_IP` | IP address for the default nerdctl bridge network, e.g., 10.1.100.1/24 | Since 2.0.1 | | ||
| | `kube_hide_dupe` | `--kube-hide-dupe` | | Deduplicate images for Kubernetes with namespace k8s.io, no more redundant <none> ones are displayed | Since 2.0.3 | | ||
| | `cdi_spec_dirs` | `--cdi-spec-dirs` | | The folders to use when searching for CDI ([container-device-interface](https://github.com/cncf-tags/container-device-interface)) specifications. | Since 2.1.0 | |
AkihiroSuda
approved these changes
Apr 29, 2025
Member
AkihiroSuda
left a comment
There was a problem hiding this comment.
Thanks, will merge after releasing v2.0.5
Member
|
Needs rebase |
This change adds support for specifying fully-qualified CDI device names in the --device flag. This allows the Container Device Interface (CDI) to be used to inject devices into container being run. Signed-off-by: Evan Lezar <[email protected]> Enable cdi feature for Docker Signed-off-by: Evan Lezar <[email protected]> Update go mod Signed-off-by: Evan Lezar <[email protected]> Signed-off-by: Jin Dong <[email protected]> use containerd cdi.WithCDIDevices Signed-off-by: Jin Dong <[email protected]>
c34d651 to
71c646f
Compare
AkihiroSuda
approved these changes
May 1, 2025
This was referenced May 2, 2025
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.
Carry #2280