Skip to content

Commit

Permalink
Add vlanProto parameter
Browse files Browse the repository at this point in the history
The sriov-cni has a new parameter to set the vlan protocol
assign to the vf.

Signed-off-by: Marcelo Guerrero <marguerr@redhat.com>
  • Loading branch information
mlguerrero12 committed Oct 9, 2023
1 parent 44afc00 commit bcfa74a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
data.Data["VlanQoSConfigured"] = false
}

data.Data["VlanProtoConfigured"] = false
if cr.Spec.VlanProto != "" {
data.Data["VlanProtoConfigured"] = true
data.Data["SriovCniVlanProto"] = cr.Spec.VlanProto
}

if cr.Spec.Capabilities == "" {
data.Data["CapabilitiesConfigured"] = false
} else {
Expand Down
3 changes: 3 additions & 0 deletions api/v1/sriovnetwork_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ type SriovNetworkSpec struct {
// +kubebuilder:validation:Maximum=7
// VLAN QoS ID to assign for the VF. Defaults to 0.
VlanQoS int `json:"vlanQoS,omitempty"`
// +kubebuilder:validation:Enum={"802.1q","802.1Q", "802.1ad", "802.1AD"}
// VLAN proto to assign for the VF. Defaults to 802.1q.
VlanProto string `json:"vlanProto,omitempty"`
// VF spoof check, (on|off)
// +kubebuilder:validation:Enum={"on","off"}
SpoofChk string `json:"spoofChk,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions bindata/manifests/cni-config/sriov-cni-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ spec:
{{- if .VlanQoSConfigured -}}
"vlanQoS":{{.SriovCniVlanQoS}},
{{- end -}}
{{- if .VlanProtoConfigured -}}
"vlanProto":"{{.SriovCniVlanProto}}",
{{- end -}}
{{- if .MinTxRateConfigured -}}
"min_tx_rate":{{.SriovCniMinTxRate}},
{{- end -}}
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ spec:
maximum: 4096
minimum: 0
type: integer
vlanProto:
description: VLAN proto to assign for the VF. Defaults to 802.1q.
enum:
- 802.1q
- 802.1Q
- 802.1ad
- 802.1AD
type: string
vlanQoS:
description: VLAN QoS ID to assign for the VF. Defaults to 0.
maximum: 7
Expand Down
15 changes: 12 additions & 3 deletions controllers/sriovnetwork_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ var _ = Describe("SriovNetwork Controller", func() {
ResourceName: "resource_1",
IPAM: `{"type":"host-local","subnet":"10.56.217.0/24","rangeStart":"10.56.217.171","rangeEnd":"10.56.217.181","routes":[{"dst":"0.0.0.0/0"}],"gateway":"10.56.217.1"}`,
Vlan: 100,
VlanQoS: 5,
VlanProto: "802.1ad",
},
"test-1": {
ResourceName: "resource_1",
Expand Down Expand Up @@ -89,7 +91,7 @@ var _ = Describe("SriovNetwork Controller", func() {
err = util.WaitForNamespacedObjectDeleted(netAttDef, k8sClient, ns, cr.GetName(), util.RetryInterval, util.Timeout)
Expect(err).NotTo(HaveOccurred())
},
Entry("with vlan flag", sriovnets["test-0"]),
Entry("with vlan, vlanQoS and vlanProto flag", sriovnets["test-0"]),
Entry("with networkNamespace flag", sriovnets["test-1"]),
Entry("with SpoofChk flag on", sriovnets["test-2"]),
Entry("with Trust flag on", sriovnets["test-3"]),
Expand All @@ -100,6 +102,7 @@ var _ = Describe("SriovNetwork Controller", func() {
ResourceName: "resource_1",
IPAM: `{"type":"dhcp"}`,
Vlan: 200,
VlanProto: "802.1q",
},
"new-1": {
ResourceName: "resource_1",
Expand Down Expand Up @@ -163,7 +166,7 @@ var _ = Describe("SriovNetwork Controller", func() {
Expect(anno["k8s.v1.cni.cncf.io/resourceName"]).To(Equal("openshift.io/" + new.Spec.ResourceName))
Expect(strings.TrimSpace(netAttDef.Spec.Config)).To(Equal(expect))
},
Entry("with vlan flag and ipam updated", sriovnets["test-4"], newsriovnets["new-0"]),
Entry("with vlan and proto flag and ipam updated", sriovnets["test-4"], newsriovnets["new-0"]),
Entry("with networkNamespace flag", sriovnets["test-4"], newsriovnets["new-1"]),
Entry("with SpoofChk flag on", sriovnets["test-4"], newsriovnets["new-2"]),
Entry("with Trust flag on", sriovnets["test-4"], newsriovnets["new-3"]),
Expand Down Expand Up @@ -270,6 +273,7 @@ var _ = Describe("SriovNetwork Controller", func() {
func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string {
spoofchk := ""
trust := ""
vlanProto := ""
ipam := emptyCurls

if cr.Spec.Trust == sriovnetworkv1.SriovCniStateOn {
Expand All @@ -291,7 +295,12 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string {
}
vlanQoS := cr.Spec.VlanQoS

configStr, err := formatJSON(fmt.Sprintf(`{ "cniVersion":"0.3.1", "name":"%s","type":"sriov","vlan":%d,%s%s%s"vlanQoS":%d,"ipam":%s }`, cr.GetName(), cr.Spec.Vlan, spoofchk, trust, state, vlanQoS, ipam))
if cr.Spec.VlanProto != "" {
vlanProto = fmt.Sprintf(`"vlanProto": "%s",`, cr.Spec.VlanProto)
}

configStr, err := formatJSON(fmt.Sprintf(`{ "cniVersion":"0.3.1", "name":"%s","type":"sriov","vlan":%d,%s%s"vlanQoS":%d,%s%s"ipam":%s }`,
cr.GetName(), cr.Spec.Vlan, spoofchk, trust, vlanQoS, vlanProto, state, ipam))
if err != nil {
panic(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ spec:
maximum: 4096
minimum: 0
type: integer
vlanProto:
description: VLAN proto to assign for the VF. Defaults to 802.1q.
enum:
- 802.1q
- 802.1Q
- 802.1ad
- 802.1AD
type: string
vlanQoS:
description: VLAN QoS ID to assign for the VF. Defaults to 0.
maximum: 7
Expand Down

0 comments on commit bcfa74a

Please sign in to comment.