Skip to content

Commit

Permalink
Merge pull request #14 from almaslennikov/validation-nic-template
Browse files Browse the repository at this point in the history
Additional validation for NicConfigurationTemplate, fix for NicDevice
  • Loading branch information
almaslennikov authored Sep 19, 2024
2 parents 7102558 + 2e07df5 commit e1a4b36
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
6 changes: 5 additions & 1 deletion api/v1alpha1/nicconfigurationtemplate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}

Expand All @@ -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"`
}

Expand Down Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions config/crd/bases/configuration.net.nvidia.com_nicdevices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions internal/controller/nicconfigurationtemplate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -298,7 +301,7 @@ var _ = Describe("NicConfigurationTemplate Controller", func() {
PciPerformanceOptimized: &v1alpha1.PciPerformanceOptimizedSpec{
Enabled: true,
MaxAccOutRead: 4,
MaxReadRequest: 4,
MaxReadRequest: 1024,
},
},
},
Expand Down Expand Up @@ -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())
Expand All @@ -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{
Expand Down

0 comments on commit e1a4b36

Please sign in to comment.