From fa3061ef1a931632d5ce8301783d5d0976457d55 Mon Sep 17 00:00:00 2001 From: amaslennikov Date: Tue, 17 Sep 2024 14:33:40 +0300 Subject: [PATCH 1/2] Additional validation for NicConfigurationTemplate, fix for NicDevice Signed-off-by: amaslennikov --- api/v1alpha1/nicconfigurationtemplate_types.go | 6 +++++- ...n.net.nvidia.com_nicconfigurationtemplates.yaml | 14 +++++++++++++- .../configuration.net.nvidia.com_nicdevices.yaml | 11 +++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/api/v1alpha1/nicconfigurationtemplate_types.go b/api/v1alpha1/nicconfigurationtemplate_types.go index 0fcb065..7530cd1 100644 --- a/api/v1alpha1/nicconfigurationtemplate_types.go +++ b/api/v1alpha1/nicconfigurationtemplate_types.go @@ -21,9 +21,10 @@ import ( // NicSelectorSpec is a desired configuration for NICs type NicSelectorSpec struct { - // Type of the NIC to be selected, e.g. ConnectX5|ConnectX6|ConnectX7 + // Type of the NIC to be selected, e.g. 101d,1015,a2d6 etc. NicType string `json:"nicType"` // Array of PCI addresses to be selected, e.g. "0000:03:00.0" + // +kubebuilder:validation:items:Pattern=`^0000:[0-9a-fA-F]{2}:[0-9a-fA-F]{2}\.[0-7]$` PciAddresses []string `json:"pciAddresses,omitempty"` // Serial numbers of the NICs to be selected, e.g. MT2116X09299 SerialNumbers []string `json:"serialNumbers,omitempty"` @@ -40,6 +41,7 @@ type PciPerformanceOptimizedSpec struct { // Specifies the PCIe Max Accumulative Outstanding read bytes MaxAccOutRead int `json:"maxAccOutRead,omitempty"` // Specifies the size of a single PCI read request in bytes + // +kubebuilder:validation:Enum=128;256;512;1024;2048;4096 MaxReadRequest int `json:"maxReadRequest,omitempty"` } @@ -48,6 +50,7 @@ type QosSpec struct { // Trust mode for QoS settings, e.g. trust-dscp Trust string `json:"trust"` // Priority-based Flow Control configuration, e.g. "0,0,0,1,0,0,0,0" + // +kubebuilder:validation:Pattern=`^([01],){7}[01]$` PFC string `json:"pfc"` } @@ -79,6 +82,7 @@ type ConfigurationTemplateSpec struct { // Number of VFs to be configured NumVfs int `json:"numVfs"` // LinkType to be configured, Ethernet|Infiniband + // +kubebuilder:validation:Enum=Ethernet;Infiniband LinkType LinkTypeEnum `json:"linkType"` // PCI performance optimization settings PciPerformanceOptimized *PciPerformanceOptimizedSpec `json:"pciPerformanceOptimized,omitempty"` diff --git a/config/crd/bases/configuration.net.nvidia.com_nicconfigurationtemplates.yaml b/config/crd/bases/configuration.net.nvidia.com_nicconfigurationtemplates.yaml index 1de40ee..3802273 100644 --- a/config/crd/bases/configuration.net.nvidia.com_nicconfigurationtemplates.yaml +++ b/config/crd/bases/configuration.net.nvidia.com_nicconfigurationtemplates.yaml @@ -44,7 +44,8 @@ spec: description: NIC selector configuration properties: nicType: - description: Type of the NIC to be selected, e.g. ConnectX5|ConnectX6|ConnectX7 + description: Type of the NIC to be selected, e.g. 101d,1015,a2d6 + etc. type: string pciAddresses: description: Array of PCI addresses to be selected, e.g. "0000:03:00.0" @@ -94,6 +95,9 @@ spec: type: object linkType: description: LinkType to be configured, Ethernet|Infiniband + enum: + - Ethernet + - Infiniband type: string numVfs: description: Number of VFs to be configured @@ -111,6 +115,13 @@ spec: maxReadRequest: description: Specifies the size of a single PCI read request in bytes + enum: + - 128 + - 256 + - 512 + - 1024 + - 2048 + - 4096 type: integer required: - enabled @@ -142,6 +153,7 @@ spec: pfc: description: Priority-based Flow Control configuration, e.g. "0,0,0,1,0,0,0,0" + pattern: ^([01],){7}[01]$ type: string trust: description: Trust mode for QoS settings, e.g. trust-dscp diff --git a/config/crd/bases/configuration.net.nvidia.com_nicdevices.yaml b/config/crd/bases/configuration.net.nvidia.com_nicdevices.yaml index b8c2942..c0e4f2b 100644 --- a/config/crd/bases/configuration.net.nvidia.com_nicdevices.yaml +++ b/config/crd/bases/configuration.net.nvidia.com_nicdevices.yaml @@ -73,6 +73,9 @@ spec: type: object linkType: description: LinkType to be configured, Ethernet|Infiniband + enum: + - Ethernet + - Infiniband type: string numVfs: description: Number of VFs to be configured @@ -91,6 +94,13 @@ spec: maxReadRequest: description: Specifies the size of a single PCI read request in bytes + enum: + - 128 + - 256 + - 512 + - 1024 + - 2048 + - 4096 type: integer required: - enabled @@ -122,6 +132,7 @@ spec: pfc: description: Priority-based Flow Control configuration, e.g. "0,0,0,1,0,0,0,0" + pattern: ^([01],){7}[01]$ type: string trust: description: Trust mode for QoS settings, e.g. trust-dscp From 2e07df58a32ed949068ddc29be5d8a965dd59262 Mon Sep 17 00:00:00 2001 From: amaslennikov Date: Thu, 19 Sep 2024 09:57:42 +0300 Subject: [PATCH 2/2] Align utests with new validation Signed-off-by: amaslennikov --- ...icconfigurationtemplate_controller_test.go | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/internal/controller/nicconfigurationtemplate_controller_test.go b/internal/controller/nicconfigurationtemplate_controller_test.go index 33bf74c..a151ae2 100644 --- a/internal/controller/nicconfigurationtemplate_controller_test.go +++ b/internal/controller/nicconfigurationtemplate_controller_test.go @@ -245,7 +245,10 @@ var _ = Describe("NicConfigurationTemplate Controller", func() { NicType: "ConnectX6", }, ResetToDefault: false, - Template: &v1alpha1.ConfigurationTemplateSpec{}, + Template: &v1alpha1.ConfigurationTemplateSpec{ + NumVfs: 2, + LinkType: consts.Ethernet, + }, }, } Expect(k8sClient.Create(ctx, template)).To(Succeed()) @@ -298,7 +301,7 @@ var _ = Describe("NicConfigurationTemplate Controller", func() { PciPerformanceOptimized: &v1alpha1.PciPerformanceOptimizedSpec{ Enabled: true, MaxAccOutRead: 4, - MaxReadRequest: 4, + MaxReadRequest: 1024, }, }, }, @@ -346,7 +349,10 @@ var _ = Describe("NicConfigurationTemplate Controller", func() { NicSelector: &v1alpha1.NicSelectorSpec{ NicType: "ConnectX6", }, - Template: &v1alpha1.ConfigurationTemplateSpec{NumVfs: 8}, + Template: &v1alpha1.ConfigurationTemplateSpec{ + NumVfs: 8, + LinkType: consts.Ethernet, + }, }, } Expect(k8sClient.Create(ctx, template1)).To(Succeed()) @@ -360,14 +366,18 @@ var _ = Describe("NicConfigurationTemplate Controller", func() { NicSelector: &v1alpha1.NicSelectorSpec{ NicType: "ConnectX6", }, - Template: &v1alpha1.ConfigurationTemplateSpec{NumVfs: 12}, + Template: &v1alpha1.ConfigurationTemplateSpec{ + NumVfs: 12, + LinkType: consts.Ethernet, + }, }, } Expect(k8sClient.Create(ctx, template2)).To(Succeed()) device := &v1alpha1.NicDevice{ ObjectMeta: metav1.ObjectMeta{Name: deviceName, Namespace: namespaceName}, - Spec: v1alpha1.NicDeviceSpec{Configuration: &v1alpha1.NicDeviceConfigurationSpec{Template: &v1alpha1.ConfigurationTemplateSpec{NumVfs: 4}}}, + Spec: v1alpha1.NicDeviceSpec{Configuration: &v1alpha1.NicDeviceConfigurationSpec{ + Template: &v1alpha1.ConfigurationTemplateSpec{NumVfs: 4, LinkType: consts.Ethernet}}}, } Expect(k8sClient.Create(ctx, device)).To(Succeed()) device.Status = v1alpha1.NicDeviceStatus{