Skip to content

Commit

Permalink
vhost-vdpa support on secondary network
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Milleri <lmilleri@redhat.com>
  • Loading branch information
lmilleri committed Oct 12, 2023
1 parent 8ea6d19 commit 589b345
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 43 deletions.
2 changes: 1 addition & 1 deletion go-controller/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/j-keck/arping v1.0.2
github.com/k8snetworkplumbingwg/govdpa v0.1.4
github.com/k8snetworkplumbingwg/govdpa v0.1.5-0.20230926073613-07c1031aea47
github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0
github.com/k8snetworkplumbingwg/sriovnet v1.2.1-0.20230427090635-4929697df2dc
Expand Down
4 changes: 2 additions & 2 deletions go-controller/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ github.com/juju/testing v0.0.0-20200706033705-4c23f9c453cd/go.mod h1:hpGvhGHPVbN
github.com/juju/utils v0.0.0-20180808125547-9dfc6dbfb02b/go.mod h1:6/KLg8Wz/y2KVGWEpkK9vMNGkOnu4k/cqs8Z1fKjTOk=
github.com/juju/version v0.0.0-20161031051906-1f41e27e54f2/go.mod h1:kE8gK5X0CImdr7qpSKl3xB2PmpySSmfj7zVbkZFs81U=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/k8snetworkplumbingwg/govdpa v0.1.4 h1:e6mM7JFZkLVJeMQw3px96EigHAhnb4VUlqhNub/2Psk=
github.com/k8snetworkplumbingwg/govdpa v0.1.4/go.mod h1:UQR1xu7A+nnRK1dkLEi12OnNL0OiBPpIKOYDuaQQkck=
github.com/k8snetworkplumbingwg/govdpa v0.1.5-0.20230926073613-07c1031aea47 h1:iSncnlC+rtlNOIpPa3fbqQMhpTscGJIlkiWaPl1VcS4=
github.com/k8snetworkplumbingwg/govdpa v0.1.5-0.20230926073613-07c1031aea47/go.mod h1:SPaDIyUmwN03Bgn0u/mhoiE4o/+koeKh11VUsdsUX0U=
github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170 h1:rtPle+U5e7Fia0j44gm+p5QMgOIXXB3A8GtFeCCh8Kk=
github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170/go.mod h1:CF9uYILB8GY25A/6Hhi1AWKc29qbyLu8r7Gs+uINGZE=
github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.4.0 h1:VzM3TYHDgqPkettiP6I6q2jOeQFL4nrJM+UcAc4f6Fs=
Expand Down
2 changes: 1 addition & 1 deletion go-controller/pkg/cni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (pr *PodRequest) cmdAdd(kubeAuth *KubeAPIAuth, clientset *ClientSet) (*Resp
if pr.CNIConf.DeviceID != "" {
var err error

netdevName, err = util.GetNetdevNameFromDeviceId(pr.CNIConf.DeviceID)
netdevName, err = util.GetNetdevNameFromDeviceId(pr.CNIConf.DeviceID, pr.deviceInfo)
if err != nil {
return nil, fmt.Errorf("failed in cmdAdd while getting Netdevice name: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion go-controller/pkg/node/default_node_network_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"k8s.io/klog/v2"
utilnet "k8s.io/utils/net"

v1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
honode "github.com/ovn-org/ovn-kubernetes/go-controller/hybrid-overlay/pkg/controller"
houtil "github.com/ovn-org/ovn-kubernetes/go-controller/hybrid-overlay/pkg/util"
"github.com/ovn-org/ovn-kubernetes/go-controller/pkg/cni"
Expand Down Expand Up @@ -460,7 +461,7 @@ func handleNetdevResources(resourceName string) (string, error) {
} else {
return "", fmt.Errorf("insufficient device IDs for resource: %s", resourceName)
}
netdevice, err := util.GetNetdevNameFromDeviceId(deviceId)
netdevice, err := util.GetNetdevNameFromDeviceId(deviceId, v1.DeviceInfo{})
if err != nil {
return "", err
}
Expand Down
18 changes: 16 additions & 2 deletions go-controller/pkg/util/sriovnet_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"net"

"github.com/k8snetworkplumbingwg/govdpa/pkg/kvdpa"
nadapi "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/k8snetworkplumbingwg/sriovnet"
"k8s.io/klog/v2"
)

type SriovnetOps interface {
Expand Down Expand Up @@ -136,17 +138,29 @@ func GetFunctionRepresentorName(deviceID string) (string, error) {
}

// GetNetdevNameFromDeviceId returns the netdevice name from the passed device ID.
func GetNetdevNameFromDeviceId(deviceId string) (string, error) {
func GetNetdevNameFromDeviceId(deviceId string, deviceInfo nadapi.DeviceInfo) (string, error) {
var netdevices []string
var err error

if IsPCIDeviceName(deviceId) {
// If a vDPA device exists, it takes preference over the vendor device, steering-wize
if deviceInfo.Vdpa != nil {
if deviceInfo.Vdpa.Driver == "vhost" {
klog.V(2).Info("deviceInfo.Vdpa.Driver is vhost, returning empty netdev")
return "", nil
}
}

// If a virtio/vDPA device exists, it takes preference over the vendor device, steering-wize
var vdpaDevice kvdpa.VdpaDevice
vdpaDevice, err = GetVdpaOps().GetVdpaDeviceByPci(deviceId)
if err == nil && vdpaDevice.Driver() == kvdpa.VirtioVdpaDriver {
klog.V(2).Infof("deviceInfo.Vdpa.Driver is virtio, returning netdev %s", vdpaDevice.VirtioNet().NetDev())
return vdpaDevice.VirtioNet().NetDev(), nil
}
if err != nil {
klog.Errorf("Error when searching for the virtio/vdpa netdev: ", err)
return "", err
}

netdevices, err = GetSriovnetOps().GetNetDevicesFromPci(deviceId)
} else { // Auxiliary network device
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go-controller/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ github.com/json-iterator/go
github.com/juju/errors
# github.com/juju/testing v0.0.0-20200706033705-4c23f9c453cd
## explicit; go 1.14
# github.com/k8snetworkplumbingwg/govdpa v0.1.4
# github.com/k8snetworkplumbingwg/govdpa v0.1.5-0.20230926073613-07c1031aea47
## explicit; go 1.17
github.com/k8snetworkplumbingwg/govdpa/pkg/kvdpa
# github.com/k8snetworkplumbingwg/multi-networkpolicy v0.0.0-20200914073308-0f33b9190170
Expand Down

0 comments on commit 589b345

Please sign in to comment.