Skip to content

Commit

Permalink
Add mtu support for macvlan and ipvlan
Browse files Browse the repository at this point in the history
Signed-off-by: Cyclinder Kuo <[email protected]>
  • Loading branch information
cyclinder committed Feb 25, 2025
1 parent edb0960 commit 1174b54
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ spec:
items:
type: string
type: array
mtu:
default: 0
description: explicitly set MTU to the specified value. Defaults('0'
or no value provided) to the value chosen by the kernel.
format: int32
minimum: 0
type: integer
rdmaResourceName:
description: The RDMA resource name of the nic. the RDMA resource
is often reported to kubelet by the k8s-rdma-shared-dev-plugin.
Expand Down Expand Up @@ -304,6 +311,13 @@ spec:
items:
type: string
type: array
mtu:
default: 0
description: explicitly set MTU to the specified value. Defaults('0'
or no value provided) to the value chosen by the kernel.
format: int32
minimum: 0
type: integer
rdmaResourceName:
description: The RDMA resource name of the nic. the RDMA resource
is often reported to kubelet by the k8s-rdma-shared-dev-plugin.
Expand Down Expand Up @@ -386,6 +400,14 @@ spec:
minTxRateMbps:
minimum: 0
type: integer
mtu:
default: 0
description: explicitly set MTU to the specified value via tuning
plugin. Defaults('0' or no value provided) to the value chosen
by the kernel.
format: int32
minimum: 0
type: integer
rdmaIsolation:
default: false
description: rdmaIsolation enable RDMA CNI plugin is intended
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/crd-spidermultusconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ This is the SpiderReservedIP spec for users to configure.
| master | the Interfaces on your master, you could specify a single one Interface<br/> or multiple Interfaces to generate one bond Interface | list of strings | required | |
| vlanID | vlan ID | int | optional | [0,4094] |
| bond | expected bond Interface configurations | [BondConfig](./crd-spidermultusconfig.md#bondconfig) | optional | |
| mtu | mtu of the Interface | int | optional | the max mtu can't be over than the max mtu of the Interface |
| ippools | the default IPPools in your CNI configurations | [SpiderpoolPools](./crd-spidermultusconfig.md#spiderpoolpools) | optional | |

#### SpiderIPvlanCniConfig
Expand All @@ -80,6 +81,7 @@ This is the SpiderReservedIP spec for users to configure.
| master | the Interfaces on your master, you could specify a single one Interface<br/> or multiple Interfaces to generate one bond Interface | list of strings | required | |
| vlanID | vlan ID | int | optional | [0,4094] |
| bond | expected bond Interface configurations | [BondConfig](./crd-spidermultusconfig.md#bondconfig) | optional | |
| mtu | mtu of the Interface | int | optional | the max mtu can't be over than the max mtu of the Interface |
| ippools | the default IPPools in your CNI configurations | [SpiderpoolPools](./crd-spidermultusconfig.md#spiderpoolpools) | optional | |

#### SpiderSRIOVCniConfig
Expand All @@ -88,6 +90,7 @@ This is the SpiderReservedIP spec for users to configure.
|---------------|-------------------------------------------------------------------------------------------|----------------------------------------------------------------|------------|
| resourceName | this property will create an annotation for Multus net-attach-def to cooperate with SRIOV | string | required |
| vlanID | vlan ID | int | optional |
| mtu | mtu of the vf Interface, the max mtu can't be over than the PF Interface | int | optional |
| minTxRateMbps | change the allowed minimum transmit bandwidth, in Mbps, for the VF. Setting this to 0 disables rate limiting. The min_tx_rate value should be <= max_tx_rate. Support of this feature depends on NICs and drivers | int | optional |
| maxTxRateMbps | change the allowed maximum transmit bandwidth, in Mbps, for the VF. Setting this to 0 disables rate limiting | int | optional |
| rdmaIsolation | enable RDMA CNI plugin is intended to be run as a chained CNI plugin. it ensures isolation of RDMA traffic from other workloads in the system by moving the associated RDMA interfaces of the provided network interface to the container'snetwork namespace path | bool | optional |
Expand Down
18 changes: 18 additions & 0 deletions pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/spidermultus_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ type SpiderMacvlanCniConfig struct {
// by the ifacer plugin.
Master []string `json:"master"`

// +kubebuilder:default=0
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// explicitly set MTU to the specified value. Defaults('0' or no value provided) to the value chosen by the kernel.
MTU *int32 `json:"mtu,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4094
Expand Down Expand Up @@ -107,6 +113,12 @@ type SpiderIPvlanCniConfig struct {
// by the ifacer plugin.
Master []string `json:"master"`

// +kubebuilder:default=0
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// explicitly set MTU to the specified value. Defaults('0' or no value provided) to the value chosen by the kernel.
MTU *int32 `json:"mtu,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=4094
Expand Down Expand Up @@ -139,6 +151,12 @@ type SpiderSRIOVCniConfig struct {
// The VLAN ID for the CNI configuration, optional and must be within the specified range: [0.4096).
VlanID *int32 `json:"vlanID,omitempty"`

// +kubebuilder:default=0
// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
// explicitly set MTU to the specified value via tuning plugin. Defaults('0' or no value provided) to the value chosen by the kernel.
MTU *int32 `json:"mtu,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:validation:Minimum=0
MinTxRateMbps *int `json:"minTxRateMbps,omitempty"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pkg/multuscniconfig/multusconfig_informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,15 @@ func generateNetAttachDef(netAttachName string, multusConf *spiderpoolv2beta1.Sp
// head insertion
plugins = append([]interface{}{sriovCNIConf}, plugins...)

if multusConfSpec.SriovConfig.MTU != nil && *multusConfSpec.SriovConfig.MTU > 0 {
tuningConf := tuningConf{
Type: "tuning",
Mtu: *multusConfSpec.SriovConfig.MTU,
}
// head insertion
plugins = append(plugins, []interface{}{tuningConf})
}

confStr, err = marshalCniConfig2String(netAttachName, cniVersion, plugins)
if err != nil {
return nil, fmt.Errorf("failed to marshal sriov cniConfig to String: %w", err)
Expand Down Expand Up @@ -518,6 +527,10 @@ func generateMacvlanCNIConf(disableIPAM bool, multusConfSpec spiderpoolv2beta1.M
Mode: "bridge",
}

if multusConfSpec.MacvlanConfig.MTU != nil {
netConf.MTU = multusConfSpec.MacvlanConfig.MTU
}

if !disableIPAM {
netConf.IPAM = &spiderpoolcmd.IPAMConfig{
Type: constant.Spiderpool,
Expand Down Expand Up @@ -553,6 +566,10 @@ func generateIPvlanCNIConf(disableIPAM bool, multusConfSpec spiderpoolv2beta1.Mu
Master: masterName,
}

if multusConfSpec.IPVlanConfig.MTU != nil {
netConf.MTU = multusConfSpec.IPVlanConfig.MTU
}

if !disableIPAM {
netConf.IPAM = &spiderpoolcmd.IPAMConfig{
Type: constant.Spiderpool,
Expand Down
12 changes: 12 additions & 0 deletions pkg/multuscniconfig/multusconfig_mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func setMacvlanDefaultConfig(macvlanConfig *spiderpoolv2beta1.SpiderMacvlanCniCo
macvlanConfig.Bond = setBondDefaultConfig(macvlanConfig.Bond)
}

if macvlanConfig.MTU == nil {
macvlanConfig.MTU = ptr.To(int32(0))
}

if macvlanConfig.RdmaResourceName == nil {
macvlanConfig.RdmaResourceName = ptr.To("")
}
Expand Down Expand Up @@ -111,6 +115,10 @@ func setIPVlanDefaultConfig(ipvlanConfig *spiderpoolv2beta1.SpiderIPvlanCniConfi
ipvlanConfig.RdmaResourceName = ptr.To("")
}

if ipvlanConfig.MTU == nil {
ipvlanConfig.MTU = ptr.To(int32(0))
}

if ipvlanConfig.Bond != nil {
ipvlanConfig.Bond = setBondDefaultConfig(ipvlanConfig.Bond)
}
Expand All @@ -132,6 +140,10 @@ func setSriovDefaultConfig(sriovConfig *spiderpoolv2beta1.SpiderSRIOVCniConfig)
sriovConfig.VlanID = ptr.To(int32(0))
}

if sriovConfig.MTU == nil {
sriovConfig.MTU = ptr.To(int32(0))
}

if sriovConfig.MinTxRateMbps == nil {
sriovConfig.MinTxRateMbps = ptr.To(0)
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/multuscniconfig/multusconfig_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if multusConfig.Spec.MacvlanConfig.MTU != nil && *multusConfig.Spec.MacvlanConfig.MTU < 0 {
return field.Invalid(macvlanConfigField, *multusConfig.Spec.MacvlanConfig.MTU, "MTU must be greater than or equal to 0")
}

if err := validateVlanCNIConfig(multusConfig.Spec.MacvlanConfig.Master, multusConfig.Spec.MacvlanConfig.Bond); err != nil {
return field.Invalid(macvlanConfigField, *multusConfig.Spec.MacvlanConfig, err.Error())
}
Expand Down Expand Up @@ -133,6 +137,10 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if multusConfig.Spec.IPVlanConfig.MTU != nil && *multusConfig.Spec.IPVlanConfig.MTU < 0 {
return field.Invalid(ipvlanConfigField, *multusConfig.Spec.IPVlanConfig.MTU, "MTU must be greater than or equal to 0")
}

if err := validateVlanCNIConfig(multusConfig.Spec.IPVlanConfig.Master, multusConfig.Spec.IPVlanConfig.Bond); err != nil {
return field.Invalid(ipvlanConfigField, *multusConfig.Spec.IPVlanConfig, err.Error())
}
Expand Down Expand Up @@ -164,6 +172,10 @@ func validateCNIConfig(multusConfig *spiderpoolv2beta1.SpiderMultusConfig) *fiel
}
}

if multusConfig.Spec.SriovConfig.MTU != nil && *multusConfig.Spec.SriovConfig.MTU < 0 {
return field.Invalid(macvlanConfigField, *multusConfig.Spec.MacvlanConfig.MTU, "MTU must be greater than or equal to 0")
}

if multusConfig.Spec.SriovConfig.MinTxRateMbps != nil && multusConfig.Spec.SriovConfig.MaxTxRateMbps != nil {
if *multusConfig.Spec.SriovConfig.MinTxRateMbps > *multusConfig.Spec.SriovConfig.MaxTxRateMbps {
return field.Invalid(sriovConfigField, *multusConfig.Spec.SriovConfig.MinTxRateMbps, "minTxRateMbps must be less than maxTxRateMbps")
Expand Down
7 changes: 7 additions & 0 deletions pkg/multuscniconfig/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ type MacvlanNetConf struct {
Type string `json:"type"`
Master string `json:"master"`
Mode string `json:"mode"`
MTU *int32 `json:"mtu,omitempty"`
IPAM *spiderpoolcmd.IPAMConfig `json:"ipam,omitempty"`
}

type IPvlanNetConf struct {
Type string `json:"type"`
Master string `json:"master"`
MTU *int32 `json:"mtu,omitempty"`
IPAM *spiderpoolcmd.IPAMConfig `json:"ipam,omitempty"`
}

Expand Down Expand Up @@ -93,6 +95,11 @@ type IfacerNetConf struct {
Bond *v2beta1.BondConfig `json:"bond,omitempty"`
}

type tuningConf struct {
Type string `json:"type"`
Mtu int32 `json:"mtu,omitempty"`
}

type CoordinatorConfig struct {
TxQueueLen *int `json:"txQueueLen,omitempty"`
IPConflict *bool `json:"detectIPConflict,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions test/doc/spidermultus.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
| M00030 | return an err if cniType is not in [macvlan,ipvlan,sriov,ib-sriov,ipoib] when spidermutlus with annotation: cni.spidernet.io/rdma-resource-inject | p3 | | done | |
| M00031 | resoucename and ippools config must be both set when spidermutlus with annotation: cni.spidernet.io/network-resource-inject | p3 | | done | |
| M00032 | return an err if resoucename is set without ippools config when spidermutlus with annotation: cni.spidernet.io/network-resource-inject | p3 | | done | |
| M00033 | test the multusConfig with mtu size for macvlan | p3 | | done | |
| M00034 | test the multusConfig with mtu size for ipvlan | p3 | | done | |
| M00035 | test the multusConfig with mtu size for sriov | p3 | | done | |
Loading

0 comments on commit 1174b54

Please sign in to comment.