Skip to content

Commit

Permalink
Merge pull request #564 from SchSeba/support_vhost_ocp
Browse files Browse the repository at this point in the history
Bug 1983964: Support vhost ocp
  • Loading branch information
openshift-merge-robot authored Sep 14, 2021
2 parents f5555db + 1a9878c commit 104db73
Show file tree
Hide file tree
Showing 23 changed files with 209 additions and 846 deletions.
2 changes: 2 additions & 0 deletions api/v1/sriovnetworknodepolicy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type SriovNetworkNodePolicySpec struct {
DeviceType string `json:"deviceType,omitempty"`
// RDMA mode. Defaults to false.
IsRdma bool `json:"isRdma,omitempty"`
// mount vhost-net device. Defaults to false.
NeedVhostNet bool `json:"needVhostNet,omitempty"`
// +kubebuilder:validation:Enum=eth;ETH;ib;IB
// NIC Link Type. Allowed value "eth", "ETH", "ib", and "IB".
LinkType string `json:"linkType,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions api/v1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ spec:
description: MTU of VF
minimum: 1
type: integer
needVhostNet:
description: mount vhost-net device. Defaults to false.
type: boolean
nicSelector:
description: NicSelector selects the NICs to be configured
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ spec:
description: MTU of VF
minimum: 1
type: integer
needVhostNet:
description: mount vhost-net device. Defaults to false.
type: boolean
nicSelector:
description: NicSelector selects the NICs to be configured
properties:
Expand Down
1 change: 1 addition & 0 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(pl *srio
ResourceName: p.Spec.ResourceName,
}
netDeviceSelectors.IsRdma = p.Spec.IsRdma
netDeviceSelectors.NeedVhostNet = p.Spec.NeedVhostNet

if p.Spec.NicSelector.Vendor != "" {
netDeviceSelectors.Vendors = append(netDeviceSelectors.Vendors, p.Spec.NicSelector.Vendor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ spec:
description: MTU of VF
minimum: 1
type: integer
needVhostNet:
description: mount vhost-net device. Defaults to false.
type: boolean
nicSelector:
description: NicSelector selects the NICs to be configured
properties:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/Masterminds/sprig/v3 v3.2.2
github.com/blang/semver v3.5.1+incompatible
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-systemd/v22 v22.0.0
github.com/fsnotify/fsnotify v1.4.9
github.com/go-logr/logr v0.4.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chai2010/gettext-go v0.0.0-20160711120539-c6fed771bfd5/go.mod h1:/iP1qXHoty45bqomnu2LM+VVyAEdWN+vtSHGlQgyxbw=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
Expand Down
1 change: 1 addition & 0 deletions hack/tools.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build tools
// +build tools

// This package imports things required by build scripts, to force `go mod` to see them as dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ spec:
description: MTU of VF
minimum: 1
type: integer
needVhostNet:
description: mount vhost-net device. Defaults to false.
type: boolean
nicSelector:
description: NicSelector selects the NICs to be configured
properties:
Expand Down
120 changes: 120 additions & 0 deletions test/conformance/tests/sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1572,6 +1572,126 @@ var _ = Describe("[sriov] operator", func() {

})

Context("vhost-net device Validation", func() {
var node string
resourceName := "vhostresource"
vhostnetwork := "test-vhostnetwork"
numVfs := 5
var intf *sriovv1.InterfaceExt
var err error

execute.BeforeAll(func() {
if discovery.Enabled() {
node, resourceName, numVfs, intf, err = discovery.DiscoveredResources(clients,
sriovInfos, operatorNamespace,
func(policy sriovv1.SriovNetworkNodePolicy) bool {
if !defaultFilterPolicy(policy) {
return false
}
if !policy.Spec.NeedVhostNet {
return false
}
return true
},
func(node string, sriovDeviceList []*sriovv1.InterfaceExt) (*sriovv1.InterfaceExt, bool) {
if len(sriovDeviceList) == 0 {
return nil, false
}
return sriovDeviceList[0], true
},
)
Expect(err).ToNot(HaveOccurred())
if node == "" || resourceName == "" || numVfs < 5 || intf == nil {
Skip("Insufficient resources to run test in discovery mode")
}
} else {
node = sriovInfos.Nodes[0]
sriovDeviceList, err := sriovInfos.FindSriovDevices(node)
Expect(err).ToNot(HaveOccurred())
unusedSriovDevices, err := findUnusedSriovDevices(node, sriovDeviceList)
if err != nil {
Skip(err.Error())
}
intf = unusedSriovDevices[0]

mtuPolicy := &sriovv1.SriovNetworkNodePolicy{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-vhostpolicy",
Namespace: operatorNamespace,
},

Spec: sriovv1.SriovNetworkNodePolicySpec{
NodeSelector: map[string]string{
"kubernetes.io/hostname": node,
},
NumVfs: 5,
ResourceName: resourceName,
Priority: 99,
NicSelector: sriovv1.SriovNetworkNicSelector{
PfNames: []string{intf.Name},
},
DeviceType: "netdevice",
NeedVhostNet: true,
},
}

err = clients.Create(context.Background(), mtuPolicy)
Expect(err).ToNot(HaveOccurred())

WaitForSRIOVStable()
By("waiting for the resources to be available")
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), node, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(5)))
}

sriovNetwork := &sriovv1.SriovNetwork{
ObjectMeta: metav1.ObjectMeta{
Name: vhostnetwork,
Namespace: operatorNamespace,
},
Spec: sriovv1.SriovNetworkSpec{
ResourceName: resourceName,
IPAM: `{"type":"host-local","subnet":"10.10.10.0/24","rangeStart":"10.10.10.171","rangeEnd":"10.10.10.181","routes":[{"dst":"0.0.0.0/0"}],"gateway":"10.10.10.1"}`,
NetworkNamespace: namespaces.Test,
LinkState: "enable",
}}

// We need this to be able to run the connectivity checks on Mellanox cards
if intf.DeviceID == "1015" {
sriovNetwork.Spec.SpoofChk = "off"
}

err = clients.Create(context.Background(), sriovNetwork)

Expect(err).ToNot(HaveOccurred())

Eventually(func() error {
netAttDef := &netattdefv1.NetworkAttachmentDefinition{}
return clients.Get(context.Background(), runtimeclient.ObjectKey{Name: vhostnetwork, Namespace: namespaces.Test}, netAttDef)
}, (10+snoTimeoutMultiplier*110)*time.Second, 1*time.Second).ShouldNot(HaveOccurred())

})

It("Should have the vhost-net device inside the container", func() {
By("creating a pod")
podObj := createTestPod(node, []string{vhostnetwork})
ips, err := network.GetSriovNicIPs(podObj, "net1")
Expect(err).ToNot(HaveOccurred())
Expect(ips).NotTo(BeNil(), "No sriov network interface found.")
Expect(len(ips)).Should(Equal(1))

By("check the /dev/vhost device exist inside the container")
output, errOutput, err := pod.ExecCommand(clients, podObj, "ls", "/dev/vhost-net")
Expect(err).ToNot(HaveOccurred())
Expect(errOutput).To(Equal(""))
Expect(output).ToNot(ContainSubstring("cannot access"))
})
})
})
})

Expand Down
8 changes: 0 additions & 8 deletions vendor/github.com/cespare/xxhash/v2/.travis.yml

This file was deleted.

6 changes: 4 additions & 2 deletions vendor/github.com/cespare/xxhash/v2/README.md

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

1 change: 0 additions & 1 deletion vendor/github.com/cespare/xxhash/v2/xxhash.go

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

Loading

0 comments on commit 104db73

Please sign in to comment.