cncf-tags / container-device-interface-rs

Rust implementation of the Container Device Interface: https://github.com/cncf-tags/container-device-interface
Apache License 2.0
5 stars 6 forks source link

Handle empty devices in OCI spec #30

Closed zvonkok closed 4 months ago

zvonkok commented 4 months ago

Handle empty devices in OCI spec, if OCI spec has an empty linux.resource.devices entry aka None the CDI injection will fail since we are checking for Some(devices).

If devices is None create an vector with the new device and set it in the resources section.

With

cdiVersion: 0.5.0
containerEdits:
  deviceNodes:
  - path: /dev/nvidia0
  - path: /dev/nvidiactl

we get

    "linux": {
      "resources": {
        "devices": [
          {
            "allow": true,
            "type": "c",
            "major": 195,
            "minor": 0,
            "access": "rwm"
          },
          {
            "allow": true,
            "type": "c",
            "major": 195,
            "minor": 0,
            "access": "rwm"
          },
          {
            "allow": true,
            "type": "c",
            "major": 242,
            "minor": 0,
            "access": "rwm"
          }
        ]
      },

Without the patch we got

   "linux": {
      "resources": {},
zvonkok commented 4 months ago

@Apokleos PTAL