You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+97-36Lines changed: 97 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,64 +4,85 @@
4
4
5
5
## What is CDI?
6
6
7
-
CDI (Container Device Interface), is a [specification](SPEC.md), for container runtimes, to support third party devices.
7
+
CDI (Container Device Interface), is a [specification](SPEC.md), for container-
8
+
runtimes, to support third-party devices.
8
9
9
-
It introduces an abstract notion of a device as a resource. Such devices are uniquely specified by a fully-qualified name that is constructed from a vendor ID, a device class, and a name that is unique per vendor ID-device class pair.
10
+
It introduces an abstract notion of a device as a resource. Such devices are
11
+
uniquely specified by a fully-qualified name that is constructed from a vendor
12
+
ID, a device class, and a name that is unique per vendor ID-device class pair.
10
13
11
14
```
12
15
vendor.com/class=unique_name
13
16
```
14
17
15
-
The combination of vendor ID and device class (`vendor.com/class` in the above example) is referred to as the device kind.
18
+
The combination of vendor ID and device class (`vendor.com/class` in the above
19
+
example) is referred to as the device kind.
16
20
17
-
CDI concerns itself only with enabling container to be device aware. Areas like resource management are explicitly left out of CDI (and is expected to be handled by the orchestrator). Because of this focus, the CDI specification is simple to implement and allows great flexibility to runtimes and orchestrators.
21
+
CDI concerns itself only with enabling containers to be device aware. Areas like
22
+
resource management are explicitly left out of CDI (and are expected to be
23
+
handled by the orchestrator). Because of this focus, the CDI specification is
24
+
simple to implement and allows great flexibility for runtimes and orchestrators.
18
25
19
-
Note: The CDI model is based on the Container Networking Interface (CNI) model and specification.
26
+
Note: The CDI model is based on the Container Networking Interface (CNI) model
27
+
and specification.
20
28
21
29
## Why is CDI needed?
22
30
23
-
On Linux, enabling a container to be device aware used to be as simple as exposing a device node in that container.
24
-
However, as devices and software grows more complex, vendors want to perform more operations, such as:
25
-
26
-
- Exposing a device to a container can require exposing more than one device node, mounting files from the runtime namespace or hide procfs entries.
27
-
- Performing compatibility checks between the container and the device (e.g: Can this container run on this device).
28
-
- Performing runtime specific operations (e.g: VM vs linux containers based runtimes).
29
-
- Performing device specific operations (e.g: scrubbing the memory of a GPU or reconfiguring an FPGA).
30
-
31
-
In the absence of a standard for third party devices, vendors often have to write and maintain multiple plugins for different runtimes or even directly contribute vendor specific code in the runtime.
32
-
Additionally runtimes don't uniformly expose a plugin system (or even expose a plugin system at all) leading to duplication of the functionality in higher level abstractions (such as Kubernetes device plugins).
31
+
On Linux, enabling a container to be device aware used to be as simple as
32
+
exposing a device node in that container. However, as devices and software grows
33
+
more complex, vendors want to perform more operations, such as:
34
+
35
+
- Exposing a device to a container can require exposing more than one device
36
+
node, mounting files from the runtime namespace, or hiding procfs entries.
37
+
- Performing compatibility checks between the container and the device (e.g: Can
38
+
this container run on this device).
39
+
- Performing runtime-specific operations (e.g: VM vs Linux containers-based
40
+
runtimes).
41
+
- Performing device-specific operations (e.g: scrubbing the memory of a GPU or
42
+
reconfiguring an FPGA).
43
+
44
+
In the absence of a standard for third-party devices, vendors often have to
45
+
write and maintain multiple plugins for different runtimes or even directly
46
+
contribute vendor-specific code in the runtime. Additionally, runtimes don't
47
+
uniformly expose a plugin system (or even expose a plugin system at all) leading
48
+
to duplication of the functionality in higher-level abstractions (such as
49
+
Kubernetes device plugins).
33
50
34
51
## How does CDI work?
35
52
36
53
For CDI to work the following needs to be done:
37
54
38
-
- CDI file containing update for the OCI spec in JSON format should be present in the CDI
39
-
spec directory. Default directories are /etc/cdi and /var/run/cdi
40
-
41
-
- Fully qualified device name should be passed to the runtime either
42
-
using command line parameters for podman or using container annotations
43
-
for CRI-O and Containerd
44
-
45
-
- Container runtime should be able to find CDI file by the device name
46
-
and update container config using CDI file content.
55
+
- CDI file containing updates for the OCI spec in JSON format should be present
56
+
in the CDI spec directory. Default directories are `/etc/cdi` and
57
+
`/var/run/cdi`
58
+
- Fully qualified device name should be passed to the runtime either using
59
+
command line parameters for podman or using container annotations for CRI-O
60
+
and containerd
61
+
- Container runtime should be able to find the CDI file by the device name and
62
+
update the container config using CDI file content.
47
63
48
64
## How to configure CDI?
49
65
50
66
### CRI-O configuration
51
67
52
-
In CRI-O CDI support is enabled by default. It is configured with the default `/etc/cdi, /var/run/cdi`
53
-
CDI directory locations. Therefore you can start using CDI simply by dropping CDI configuration files
54
-
in either of those directories, static configuration into `/etc/cdi` and dynamically updated one into
55
-
`/var/run/cdi`. If you are unsure of the configured directories you can run this command to find them
56
-
out:
68
+
In CRI-O CDI support is enabled by default. It is configured with the default
69
+
`/etc/cdi, /var/run/cdi` CDI directory locations. Therefore you can start using
70
+
CDI simply by dropping CDI configuration files in either of those directories,
71
+
static configuration into `/etc/cdi` and dynamically updated one into
72
+
`/var/run/cdi`. If you are unsure of the configured directories you can run this
73
+
command to find them out:
57
74
58
75
```bash
59
76
$ crio config |& grep -B1 -A5 cdi_spec_dirs
60
77
```
61
78
62
79
### Containerd configuration
63
80
64
-
To enable and configure CDI support in the [containerd runtime](https://github.com/containerd/containerd) 2 configuration options `enable_cdi` and `cdi_spec_dirs` should be set in the `plugins."io.containerd.grpc.v1.cri` section of the containerd configuration file (`/etc/containerd/config.toml` by default):
81
+
To enable and configure CDI support in the [containerd
`enable_cdi` and `cdi_spec_dirs` should be set in the
84
+
`plugins."io.containerd.grpc.v1.cri` section of the containerd configuration
85
+
file (`/etc/containerd/config.toml` by default):
65
86
66
87
```
67
88
[plugins."io.containerd.grpc.v1.cri"]
@@ -70,19 +91,29 @@ To enable and configure CDI support in the [containerd runtime](https://github.c
70
91
```
71
92
72
93
Remember to restart containerd for any configuration changes to take effect.
73
-
74
94
### Podman configuration
75
95
76
-
[podman](https://github.com/containers/podman) does not require any specific configuration to enable CDI support and processes specified `--device` flags directly. If fully-qualified device selectors (e.g. `vendor.com/device=myDevice`) are included the CDI specifications at the default location (`/etc/cdi` and `/var/run/cdi`) are checked for matching devices.
96
+
[podman](https://github.com/containers/podman) does not require any specific
97
+
configuration to enable CDI support and processes specified `--device` flags
98
+
directly. If fully-qualified device selectors (e.g.
99
+
`vendor.com/device=myDevice`) are included the CDI specifications at the default
100
+
location (`/etc/cdi` and `/var/run/cdi`) are checked for matching devices.
77
101
78
-
*Note:* Although initial support was added in [`v3.2.0`](https://github.com/containers/podman/releases/tag/v3.2.0) this was updated for the tagged `v0.3.0` CDI spec in [`v4.1.0-rc.1`](https://github.com/containers/podman/releases/tag/v4.1.0-rc1) with [commit a234e4e](https://github.com/containers/podman/commit/a234e4e19662e172472877ce69523f4afea5c12e).
102
+
*Note:* Although initial support was added in
103
+
[`v3.2.0`](https://github.com/containers/podman/releases/tag/v3.2.0) this was
Assuming this specification has been generated and is available in either `/etc/cdi` or `/var/run/cdi` (or whereever a CDI-enabled consumer is configured to read CDI specifications from), the devices can be accessed through their fully-qualified device names.
151
+
Assuming this specification has been generated and is available in either
152
+
`/etc/cdi` or `/var/run/cdi` (or whereever a CDI-enabled consumer is configured
153
+
to read CDI specifications from), the devices can be accessed through their
154
+
fully-qualified device names.
121
155
122
156
For example, in the case of `podman` the CLI for accessing the device would be:
123
157
```
124
158
$ podman run --device vendor.com/device=myDevice ...
125
159
```
126
160
161
+
### Using Annotations per device to add meta-information
162
+
163
+
```bash
164
+
$ mkdir /etc/cdi
165
+
$ cat > /etc/cdi/vendor-annotations.json <<EOF
166
+
{
167
+
"cdiVersion": "0.6.0",
168
+
"kind": "vendor.com/device",
169
+
"devices": [
170
+
{
171
+
"name": "myDevice",
172
+
"annotations": {
173
+
"whatever": "false"
174
+
"whenever": "true"
175
+
}
176
+
"containerEdits": {
177
+
"deviceNodes": [
178
+
{"path": "/dev/vfio/71"}
179
+
]
180
+
}
181
+
}
182
+
]
183
+
}
184
+
EOF
185
+
```
186
+
187
+
127
188
## Issues and Contributing
128
189
129
-
[Checkout the Contributing document!](CONTRIBUTING.md)
190
+
[Check out the Contributing document!](CONTRIBUTING.md)
130
191
131
192
* Please let us know by [filing a new issue](https://github.com/container-orchestrated-devices/container-device-interface/issues/new)
132
193
* You can contribute by opening a [pull request](https://help.github.com/articles/using-pull-requests/)
0 commit comments