From bd7fae55e7f3a884a109d060ae5b54e34810a7bd Mon Sep 17 00:00:00 2001 From: Sebastian Sch Date: Mon, 3 Jul 2023 15:08:36 +0300 Subject: [PATCH] Support externally created virtual functions this commit add the new API allow the operator to use virtual functions that the user configure manually on the system this will allow new use-cases like using a VF as the SDN primary nic. the nic will be created before the operator start by the user, for example using nmstate or NetworkManager and the operator will allocate all the remaining vfs to pods. Signed-off-by: Sebastian Sch --- api/v1/helper.go | 13 ++--- api/v1/sriovnetworknodepolicy_types.go | 2 + api/v1/sriovnetworknodestate_types.go | 48 ++++++++++--------- ...openshift.io_sriovnetworknodepolicies.yaml | 4 ++ ...k.openshift.io_sriovnetworknodestates.yaml | 4 ++ ...openshift.io_sriovnetworknodepolicies.yaml | 4 ++ ...k.openshift.io_sriovnetworknodestates.yaml | 4 ++ 7 files changed, 50 insertions(+), 29 deletions(-) diff --git a/api/v1/helper.go b/api/v1/helper.go index 6479b4c0a..36aadfa00 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -271,12 +271,13 @@ func (p *SriovNetworkNodePolicy) Apply(state *SriovNetworkNodeState, equalPriori if s.Selected(&iface) { log.Info("Update interface", "name:", iface.Name) result := Interface{ - PciAddress: iface.PciAddress, - Mtu: p.Spec.Mtu, - Name: iface.Name, - LinkType: p.Spec.LinkType, - EswitchMode: p.Spec.EswitchMode, - NumVfs: p.Spec.NumVfs, + PciAddress: iface.PciAddress, + Mtu: p.Spec.Mtu, + Name: iface.Name, + LinkType: p.Spec.LinkType, + EswitchMode: p.Spec.EswitchMode, + NumVfs: p.Spec.NumVfs, + ExternallyCreated: p.Spec.ExternallyCreated, } if p.Spec.NumVfs > 0 { group, err := p.generateVfGroup(&iface) diff --git a/api/v1/sriovnetworknodepolicy_types.go b/api/v1/sriovnetworknodepolicy_types.go index 8955c300d..a400ddcee 100644 --- a/api/v1/sriovnetworknodepolicy_types.go +++ b/api/v1/sriovnetworknodepolicy_types.go @@ -59,6 +59,8 @@ type SriovNetworkNodePolicySpec struct { VdpaType string `json:"vdpaType,omitempty"` // Exclude device's NUMA node when advertising this resource by SRIOV network device plugin. Default to false. ExcludeTopology bool `json:"excludeTopology,omitempty"` + // don't create the virtual function only allocated them to the device plugin. Defaults to false. + ExternallyCreated bool `json:"externallyCreated,omitempty"` } type SriovNetworkNicSelector struct { diff --git a/api/v1/sriovnetworknodestate_types.go b/api/v1/sriovnetworknodestate_types.go index 1203abdf2..6c1eba7eb 100644 --- a/api/v1/sriovnetworknodestate_types.go +++ b/api/v1/sriovnetworknodestate_types.go @@ -29,14 +29,17 @@ type SriovNetworkNodeStateSpec struct { Interfaces Interfaces `json:"interfaces,omitempty"` } +type Interfaces []Interface + type Interface struct { - PciAddress string `json:"pciAddress"` - NumVfs int `json:"numVfs,omitempty"` - Mtu int `json:"mtu,omitempty"` - Name string `json:"name,omitempty"` - LinkType string `json:"linkType,omitempty"` - EswitchMode string `json:"eSwitchMode,omitempty"` - VfGroups []VfGroup `json:"vfGroups,omitempty"` + PciAddress string `json:"pciAddress"` + NumVfs int `json:"numVfs,omitempty"` + Mtu int `json:"mtu,omitempty"` + Name string `json:"name,omitempty"` + LinkType string `json:"linkType,omitempty"` + EswitchMode string `json:"eSwitchMode,omitempty"` + VfGroups []VfGroup `json:"vfGroups,omitempty"` + ExternallyCreated bool `json:"externallyCreated,omitempty"` } type VfGroup struct { @@ -49,23 +52,22 @@ type VfGroup struct { VdpaType string `json:"vdpaType,omitempty"` } -type Interfaces []Interface - type InterfaceExt struct { - Name string `json:"name,omitempty"` - Mac string `json:"mac,omitempty"` - Driver string `json:"driver,omitempty"` - PciAddress string `json:"pciAddress"` - Vendor string `json:"vendor,omitempty"` - DeviceID string `json:"deviceID,omitempty"` - NetFilter string `json:"netFilter,omitempty"` - Mtu int `json:"mtu,omitempty"` - NumVfs int `json:"numVfs,omitempty"` - LinkSpeed string `json:"linkSpeed,omitempty"` - LinkType string `json:"linkType,omitempty"` - EswitchMode string `json:"eSwitchMode,omitempty"` - TotalVfs int `json:"totalvfs,omitempty"` - VFs []VirtualFunction `json:"Vfs,omitempty"` + Name string `json:"name,omitempty"` + Mac string `json:"mac,omitempty"` + Driver string `json:"driver,omitempty"` + PciAddress string `json:"pciAddress"` + Vendor string `json:"vendor,omitempty"` + DeviceID string `json:"deviceID,omitempty"` + NetFilter string `json:"netFilter,omitempty"` + Mtu int `json:"mtu,omitempty"` + NumVfs int `json:"numVfs,omitempty"` + LinkSpeed string `json:"linkSpeed,omitempty"` + LinkType string `json:"linkType,omitempty"` + EswitchMode string `json:"eSwitchMode,omitempty"` + ExternallyCreated bool `json:"externallyCreated,omitempty"` + TotalVfs int `json:"totalvfs,omitempty"` + VFs []VirtualFunction `json:"Vfs,omitempty"` } type InterfaceExts []InterfaceExt diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml index 5bebf01e0..f9b28fd65 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml @@ -53,6 +53,10 @@ spec: description: Exclude device's NUMA node when advertising this resource by SRIOV network device plugin. Default to false. type: boolean + externallyCreated: + description: don't create the virtual function only allocated them + to the device plugin. Defaults to false. + type: boolean isRdma: description: RDMA mode. Defaults to false. type: boolean diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml index 1e7ef32b0..e57247359 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworknodestates.yaml @@ -50,6 +50,8 @@ spec: properties: eSwitchMode: type: string + externallyCreated: + type: boolean linkType: type: string mtu: @@ -125,6 +127,8 @@ spec: type: string eSwitchMode: type: string + externallyCreated: + type: boolean linkSpeed: type: string linkType: diff --git a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml index 5bebf01e0..f9b28fd65 100644 --- a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml +++ b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml @@ -53,6 +53,10 @@ spec: description: Exclude device's NUMA node when advertising this resource by SRIOV network device plugin. Default to false. type: boolean + externallyCreated: + description: don't create the virtual function only allocated them + to the device plugin. Defaults to false. + type: boolean isRdma: description: RDMA mode. Defaults to false. type: boolean diff --git a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml index 1e7ef32b0..e57247359 100644 --- a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml +++ b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworknodestates.yaml @@ -50,6 +50,8 @@ spec: properties: eSwitchMode: type: string + externallyCreated: + type: boolean linkType: type: string mtu: @@ -125,6 +127,8 @@ spec: type: string eSwitchMode: type: string + externallyCreated: + type: boolean linkSpeed: type: string linkType: