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

Hooks are not properly injected #28

Closed zvonkok closed 4 months ago

zvonkok commented 4 months ago

Hooks are not properly injected. There are global edits and local edits for the device. It looks like that Hooks are applied with the first round of edits but deleted by the second round of applying the containeredits merge.

---
cdiVersion: 0.5.0
containerEdits:
  env:
  - NVIDIA_VISIBLE_DEVICES=void
  hooks:
  - args:
    - nvidia-ctk
    - hook
    - update-ldcache
    - --folder
    - /ib/x86_64-linux-gnu
    hookName: createContainer
    path: /bin/nvidia-ctk
devices:
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/39
  name: "0"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/78
  name: "1"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/90
  name: "2"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/102
  name: "3"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/288
  name: "4"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/327
  name: "5"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/339
  name: "6"
- containerEdits:
    deviceNodes:
    - path: /dev/vfio/351
  name: "7"
kind: nvidia.com/pgpu
zvonkok commented 4 months ago

env works but hooks does not.

zvonkok commented 4 months ago

Reproducer: cdi inject config.json nvidia.com/pgpu=0 -o json

Apokleos commented 4 months ago

Let me fix it !

Apokleos commented 4 months ago

Hi @zvonkok my error for the hooks. I have caught the bug, is that when there's no existing hooks, we need directly set the start_container hook with the argument hook: Hook. Please see the PR#29 for details.

zvonkok commented 4 months ago

I can see that hooks are now applied

    "hooks": {
      "createContainer": [
        {
          "path": "/bin/nvidia-ctk",
          "args": [
            "nvidia-ctk",
            "hook",
            "update-ldcache",
            "--folder",
            "/ib/x86_64-linux-gnu"
          ]
        }
      ]
    },