Skip to content

Commit

Permalink
Pass DeviceID to each plugin in configuration list
Browse files Browse the repository at this point in the history
Until today, it was hardcoded that DeviceID will only be
injected for the first CNI in the chain.

This commit modifies multus to pass DeviceID to each network
configuration element in a network configuration list.
This will  allow multiple CNI's to act on DeviceID when CNI
plugins are being chained for a specific network.

The change is required to allow CNI's to ensure network
isolation (introduced in kernel >= 5.2.0 see [1]) for RDMA devices
when exist.

e.g for SR-IOV network:
sriov-cni moves network device associated with the provided DeviceID
to to the container's network namespace.
An "RDMA cni" would do the same for the corresponding RDMA device when
RDMA traffic is desired on the network.

[1] https://patchwork.kernel.org/cover/10810451/
  • Loading branch information
adrianchiris authored and s1061123 committed Mar 12, 2020
1 parent 32fe803 commit 5577822
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
14 changes: 8 additions & 6 deletions types/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,15 @@ func addDeviceIDInConfList(inBytes []byte, deviceID string) ([]byte, error) {
return nil, logging.Errorf("addDeviceIDInConfList: unable to typecast plugin list")
}

firstPlugin, ok := pMap[0].(map[string]interface{})
if !ok {
return nil, logging.Errorf("addDeviceIDInConfList: unable to typecast pMap")
for idx, plugin := range pMap {
currentPlugin, ok := plugin.(map[string]interface{})
if !ok {
return nil, logging.Errorf("addDeviceIDInConfList: unable to typecast plugin #%d", idx)
}
// Inject deviceID
currentPlugin["deviceID"] = deviceID
currentPlugin["pciBusID"] = deviceID
}
// Inject deviceID
firstPlugin["deviceID"] = deviceID
firstPlugin["pciBusID"] = deviceID

configBytes, err := json.Marshal(rawConfig)
if err != nil {
Expand Down
62 changes: 62 additions & 0 deletions types/conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,37 @@ var _ = Describe("config operations", func() {
Expect(sriovConfList.Plugins[0].DeviceID).To(Equal("0000:00:00.1"))
})

It("assigns deviceID in delegated conf list multiple plugins", func() {
conf := `{
"name": "second-network",
"plugins": [
{
"type": "sriov"
},
{
"type": "other-cni"
}
]
}`
type sriovNetConf struct {
Name string `json:"name"`
Type string `json:"type"`
DeviceID string `json:"deviceID"`
}
type sriovNetConfList struct {
Plugins []*sriovNetConf `json:"plugins"`
}
sriovConfList := &sriovNetConfList{}
delegateNetConf, err := LoadDelegateNetConf([]byte(conf), nil, "0000:00:00.1")
Expect(err).NotTo(HaveOccurred())

err = json.Unmarshal(delegateNetConf.Bytes, &sriovConfList)
Expect(err).NotTo(HaveOccurred())
for _, plugin := range sriovConfList.Plugins {
Expect(plugin.DeviceID).To(Equal("0000:00:00.1"))
}
})

It("assigns pciBusID in delegated conf", func() {
conf := `{
"name": "second-network",
Expand Down Expand Up @@ -359,6 +390,37 @@ var _ = Describe("config operations", func() {
Expect(hostDeviceConfList.Plugins[0].PCIBusID).To(Equal("0000:00:00.3"))
})

It("assigns pciBusID in delegated conf list multiple plugins", func() {
conf := `{
"name": "second-network",
"plugins": [
{
"type": "host-device"
},
{
"type": "other-cni"
}
]
}`
type hostDeviceNetConf struct {
Name string `json:"name"`
Type string `json:"type"`
PCIBusID string `json:"pciBusID"`
}
type hostDeviceNetConfList struct {
Plugins []*hostDeviceNetConf `json:"plugins"`
}
hostDeviceConfList := &hostDeviceNetConfList{}
delegateNetConf, err := LoadDelegateNetConf([]byte(conf), nil, "0000:00:00.3")
Expect(err).NotTo(HaveOccurred())

err = json.Unmarshal(delegateNetConf.Bytes, &hostDeviceConfList)
Expect(err).NotTo(HaveOccurred())
for _, plugin := range hostDeviceConfList.Plugins {
Expect(plugin.PCIBusID).To(Equal("0000:00:00.3"))
}
})

It("add cni-args in config", func() {
var args map[string]interface{}
conf := `{
Expand Down

0 comments on commit 5577822

Please sign in to comment.