Skip to content

Commit

Permalink
Support device id in host device plugin (#471)
Browse files Browse the repository at this point in the history
* Add support for `deviceID` runtime config attribute

Signed-off-by: Adrian Chiris <[email protected]>
  • Loading branch information
adrianchiris authored Apr 15, 2020
1 parent f4332fe commit a78853f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
26 changes: 26 additions & 0 deletions plugins/main/host-device/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ The device can be specified with any one of four properties:

For this plugin, `CNI_IFNAME` will be ignored. Upon DEL, the device will be moved back.

The plugin also supports the following [capability argument](https://github.com/containernetworking/cni/blob/master/CONVENTIONS.md):
* `deviceID`: A PCI address of the network device, e.g `0000:00:1f.6`

## Example configuration

A sample configuration with `device` property looks like:
Expand All @@ -38,3 +41,26 @@ A sample configuration with `pciBusID` property looks like:
"pciBusID": "0000:3d:00.1"
}
```

A sample configuration utilizing `deviceID` runtime configuration looks like:

1. From operator perspective:
```json
{
"cniVersion": "0.3.1",
"type": "host-device",
"capabilities": {
"deviceID": true
}
}
```
2. From plugin perspective:
```json
{
"cniVersion": "0.3.1",
"type": "host-device",
"runtimeConfig": {
"deviceID": "0000:3d:00.1"
}
}
```
18 changes: 14 additions & 4 deletions plugins/main/host-device/host-device.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ const (
//NetConf for host-device config, look the README to learn how to use those parameters
type NetConf struct {
types.NetConf
Device string `json:"device"` // Device-Name, something like eth0 or can0 etc.
HWAddr string `json:"hwaddr"` // MAC Address of target network interface
KernelPath string `json:"kernelpath"` // Kernelpath of the device
PCIAddr string `json:"pciBusID"` // PCI Address of target network device
Device string `json:"device"` // Device-Name, something like eth0 or can0 etc.
HWAddr string `json:"hwaddr"` // MAC Address of target network interface
KernelPath string `json:"kernelpath"` // Kernelpath of the device
PCIAddr string `json:"pciBusID"` // PCI Address of target network device
RuntimeConfig struct {
DeviceID string `json:"deviceID,omitempty"`
} `json:"runtimeConfig,omitempty"`
}

func init() {
Expand All @@ -64,9 +67,16 @@ func loadConf(bytes []byte) (*NetConf, error) {
if err := json.Unmarshal(bytes, n); err != nil {
return nil, fmt.Errorf("failed to load netconf: %v", err)
}

if n.RuntimeConfig.DeviceID != "" {
// Override PCI device with the standardized DeviceID provided in Runtime Config.
n.PCIAddr = n.RuntimeConfig.DeviceID
}

if n.Device == "" && n.HWAddr == "" && n.KernelPath == "" && n.PCIAddr == "" {
return nil, fmt.Errorf(`specify either "device", "hwaddr", "kernelpath" or "pciBusID"`)
}

return n, nil
}

Expand Down

0 comments on commit a78853f

Please sign in to comment.