diff --git a/api/v1/helper.go b/api/v1/helper.go index 910592c749..614fa45200 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -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 { diff --git a/api/v1/sriovnetwork_types.go b/api/v1/sriovnetwork_types.go index eac7238d8d..40da9fc014 100644 --- a/api/v1/sriovnetwork_types.go +++ b/api/v1/sriovnetwork_types.go @@ -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"` diff --git a/bindata/manifests/cni-config/sriov-cni-config.yaml b/bindata/manifests/cni-config/sriov-cni-config.yaml index cac67c65c5..5886902171 100644 --- a/bindata/manifests/cni-config/sriov-cni-config.yaml +++ b/bindata/manifests/cni-config/sriov-cni-config.yaml @@ -25,6 +25,9 @@ spec: {{- if .VlanQoSConfigured -}} "vlanQoS":{{.SriovCniVlanQoS}}, {{- end -}} +{{- if .VlanProtoConfigured -}} + "vlanProto":{{.SriovCniVlanProto}}, +{{- end -}} {{- if .MinTxRateConfigured -}} "min_tx_rate":{{.SriovCniMinTxRate}}, {{- end -}} diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml index 17cdcb7ce9..f8e48de40f 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml @@ -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 diff --git a/controllers/sriovnetwork_controller_test.go b/controllers/sriovnetwork_controller_test.go index e4123135ec..38fe69e002 100644 --- a/controllers/sriovnetwork_controller_test.go +++ b/controllers/sriovnetwork_controller_test.go @@ -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", @@ -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"]), @@ -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", @@ -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"]), @@ -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 { @@ -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) } diff --git a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml index 17cdcb7ce9..f8e48de40f 100644 --- a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml +++ b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml @@ -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