Skip to content

[Carry #2280] Add support for CDI devices to device flag #4170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025

Conversation

djdongjin
Copy link
Member

@djdongjin djdongjin commented Apr 27, 2025

Carry #2280

@djdongjin djdongjin force-pushed the carry-8525-add-cdi-support branch 4 times, most recently from 548458e to 449537e Compare April 27, 2025 02:47
@djdongjin djdongjin requested a review from Copilot April 27, 2025 02:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

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

@djdongjin djdongjin changed the title [Carry 8525] add cdi support [Carry 8525] Add support for CDI devices to device flag Apr 27, 2025
@djdongjin djdongjin changed the title [Carry 8525] Add support for CDI devices to device flag [Carry #8525] Add support for CDI devices to device flag Apr 27, 2025
@djdongjin djdongjin changed the title [Carry #8525] Add support for CDI devices to device flag [Carry #2280] Add support for CDI devices to device flag Apr 27, 2025
@djdongjin djdongjin marked this pull request as ready for review April 27, 2025 02:58
@djdongjin djdongjin force-pushed the carry-8525-add-cdi-support branch 4 times, most recently from 9af8317 to efe0417 Compare April 27, 2025 16:06
@djdongjin djdongjin force-pushed the carry-8525-add-cdi-support branch from efe0417 to 8e649bd Compare April 27, 2025 19:07
@djdongjin djdongjin requested a review from apostasie April 27, 2025 19:58
docs/config.md Outdated
@@ -47,6 +47,7 @@ experimental = true
| `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 |
Copy link
Member

Choose a reason for hiding this comment

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

CDI needs explanation

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@djdongjin djdongjin force-pushed the carry-8525-add-cdi-support branch from 8e649bd to c34d651 Compare April 28, 2025 13:38
@djdongjin djdongjin requested a review from AkihiroSuda April 28, 2025 13:39
@djdongjin djdongjin added this to the v2.1.0 (tentative) milestone Apr 28, 2025
Copy link
Contributor

@apostasie apostasie left a comment

Choose a reason for hiding this comment

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

@djdongjin one minor nit on help

@@ -186,6 +186,7 @@ func initRootCmdFlags(rootCmd *cobra.Command, tomlPath string) (*pflag.FlagSet,
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")
Copy link
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Member

Choose a reason for hiding this comment

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

perhaps another pr..

@@ -47,6 +47,7 @@ experimental = true
| `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 |
Copy link
Member

Choose a reason for hiding this comment

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

folders :-)

Copy link
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks, will merge after releasing v2.0.5

@AkihiroSuda
Copy link
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 <elezar@nvidia.com>

Enable cdi feature for Docker

Signed-off-by: Evan Lezar <elezar@nvidia.com>

Update go mod

Signed-off-by: Evan Lezar <elezar@nvidia.com>
Signed-off-by: Jin Dong <djdongjin95@gmail.com>

use containerd cdi.WithCDIDevices

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
@djdongjin djdongjin force-pushed the carry-8525-add-cdi-support branch from c34d651 to 71c646f Compare May 1, 2025 14:18
@AkihiroSuda AkihiroSuda merged commit 8d7539a into containerd:main May 1, 2025
83 of 87 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.

5 participants