diff --git a/charts/spiderpool/crds/spiderpool.spidernet.io_spidermultusconfigs.yaml b/charts/spiderpool/crds/spiderpool.spidernet.io_spidermultusconfigs.yaml
index 54925e536..05557938a 100644
--- a/charts/spiderpool/crds/spiderpool.spidernet.io_spidermultusconfigs.yaml
+++ b/charts/spiderpool/crds/spiderpool.spidernet.io_spidermultusconfigs.yaml
@@ -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.
@@ -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.
@@ -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
diff --git a/docs/reference/crd-spidermultusconfig.md b/docs/reference/crd-spidermultusconfig.md
index 1ca44d5a5..32dc86fce 100644
--- a/docs/reference/crd-spidermultusconfig.md
+++ b/docs/reference/crd-spidermultusconfig.md
@@ -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
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
@@ -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
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
@@ -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 |
diff --git a/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/spidermultus_types.go b/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/spidermultus_types.go
index 18db4af1a..78c6a9af6 100644
--- a/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/spidermultus_types.go
+++ b/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/spidermultus_types.go
@@ -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
@@ -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
@@ -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"`
diff --git a/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/zz_generated.deepcopy.go b/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/zz_generated.deepcopy.go
index 0aa0d7a93..ad1ecd170 100644
--- a/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/zz_generated.deepcopy.go
+++ b/pkg/k8s/apis/spiderpool.spidernet.io/v2beta1/zz_generated.deepcopy.go
@@ -741,6 +741,11 @@ func (in *SpiderIPvlanCniConfig) DeepCopyInto(out *SpiderIPvlanCniConfig) {
*out = make([]string, len(*in))
copy(*out, *in)
}
+ if in.MTU != nil {
+ in, out := &in.MTU, &out.MTU
+ *out = new(int32)
+ **out = **in
+ }
if in.VlanID != nil {
in, out := &in.VlanID, &out.VlanID
*out = new(int32)
@@ -801,6 +806,11 @@ func (in *SpiderMacvlanCniConfig) DeepCopyInto(out *SpiderMacvlanCniConfig) {
*out = make([]string, len(*in))
copy(*out, *in)
}
+ if in.MTU != nil {
+ in, out := &in.MTU, &out.MTU
+ *out = new(int32)
+ **out = **in
+ }
if in.VlanID != nil {
in, out := &in.VlanID, &out.VlanID
*out = new(int32)
@@ -998,6 +1008,11 @@ func (in *SpiderSRIOVCniConfig) DeepCopyInto(out *SpiderSRIOVCniConfig) {
*out = new(int32)
**out = **in
}
+ if in.MTU != nil {
+ in, out := &in.MTU, &out.MTU
+ *out = new(int32)
+ **out = **in
+ }
if in.MinTxRateMbps != nil {
in, out := &in.MinTxRateMbps, &out.MinTxRateMbps
*out = new(int)
diff --git a/pkg/multuscniconfig/multusconfig_informer.go b/pkg/multuscniconfig/multusconfig_informer.go
index 93c35fb60..c156c04b5 100644
--- a/pkg/multuscniconfig/multusconfig_informer.go
+++ b/pkg/multuscniconfig/multusconfig_informer.go
@@ -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)
@@ -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,
@@ -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,
diff --git a/pkg/multuscniconfig/multusconfig_mutate.go b/pkg/multuscniconfig/multusconfig_mutate.go
index de131bc7f..704803940 100644
--- a/pkg/multuscniconfig/multusconfig_mutate.go
+++ b/pkg/multuscniconfig/multusconfig_mutate.go
@@ -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("")
}
@@ -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)
}
@@ -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)
}
diff --git a/pkg/multuscniconfig/multusconfig_validate.go b/pkg/multuscniconfig/multusconfig_validate.go
index c6d8a7e08..1114a7fd5 100644
--- a/pkg/multuscniconfig/multusconfig_validate.go
+++ b/pkg/multuscniconfig/multusconfig_validate.go
@@ -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())
}
@@ -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())
}
@@ -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")
diff --git a/pkg/multuscniconfig/utils.go b/pkg/multuscniconfig/utils.go
index 36319a0fd..5decf0216 100644
--- a/pkg/multuscniconfig/utils.go
+++ b/pkg/multuscniconfig/utils.go
@@ -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"`
}
@@ -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"`
diff --git a/test/doc/spidermultus.md b/test/doc/spidermultus.md
index b8f249d38..6966d38c4 100644
--- a/test/doc/spidermultus.md
+++ b/test/doc/spidermultus.md
@@ -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 | |
diff --git a/test/e2e/spidermultus/spidermultus_test.go b/test/e2e/spidermultus/spidermultus_test.go
index 3a47d56e8..e0e09dd62 100644
--- a/test/e2e/spidermultus/spidermultus_test.go
+++ b/test/e2e/spidermultus/spidermultus_test.go
@@ -1090,4 +1090,132 @@ var _ = Describe("test spidermultus", Label("SpiderMultusConfig"), func() {
err = frame.CreateSpiderMultusInstance(invalid)
Expect(err).To(HaveOccurred(), "create invalid spiderMultusConfig should fail: %v", err)
})
+
+ It("test the multusConfig with mtu size for macvlan", Label("M00033"), func() {
+ smcName := "mtu" + common.GenerateString(10, true)
+ smc := &v2beta1.SpiderMultusConfig{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: smcName,
+ Namespace: namespace,
+ },
+ Spec: v2beta1.MultusCNIConfigSpec{
+ CniType: ptr.To(constant.MacvlanCNI),
+ MacvlanConfig: &v2beta1.SpiderMacvlanCniConfig{
+ Master: []string{"eth0"},
+ MTU: ptr.To(int32(-1)),
+ SpiderpoolConfigPools: &v2beta1.SpiderpoolPools{},
+ },
+ },
+ }
+
+ ginkgo.By("create a spiderMultusConfig with invalid mtu size")
+ err := frame.CreateSpiderMultusInstance(smc)
+ Expect(err).To(HaveOccurred(), "create invalid spiderMultusConfig should fail: %v", err)
+
+ smc.Spec.MacvlanConfig.MTU = ptr.To(int32(1400))
+ if frame.Info.IpV4Enabled {
+ smc.Spec.MacvlanConfig.SpiderpoolConfigPools.IPv4IPPool = []string{"default-v4-ippool"}
+ }
+ if frame.Info.IpV6Enabled {
+ smc.Spec.MacvlanConfig.SpiderpoolConfigPools.IPv6IPPool = []string{"default-v6-ippool"}
+ }
+
+ ginkgo.By("create a spiderMultusConfig with mtu size")
+ err = frame.CreateSpiderMultusInstance(smc)
+ Expect(err).NotTo(HaveOccurred())
+
+ depName := "macvlan-mtu"
+ var annotations = make(map[string]string)
+ annotations[common.MultusDefaultNetwork] = fmt.Sprintf("%s/%s", namespace, smcName)
+ deployObject := common.GenerateExampleDeploymentYaml(depName, namespace, int32(1))
+ deployObject.Spec.Template.Annotations = annotations
+ Expect(frame.CreateDeployment(deployObject)).NotTo(HaveOccurred())
+
+ ctx, cancel := context.WithTimeout(context.Background(), common.PodStartTimeout)
+ defer cancel()
+
+ depObject, err := frame.WaitDeploymentReady(depName, namespace, ctx)
+ Expect(err).NotTo(HaveOccurred(), "waiting for deploy ready failed: %v ", err)
+ podList, err := frame.GetPodListByLabel(depObject.Spec.Template.Labels)
+ Expect(err).NotTo(HaveOccurred(), "failed to get podList: %v ", err)
+
+ commandString := "ip link show eth0 | grep mtu | awk '{print $5}'"
+ ctx, cancel = context.WithTimeout(context.Background(), common.ExecCommandTimeout)
+ defer cancel()
+
+ res, err := frame.ExecCommandInPod(podList.Items[0].Name, podList.Items[0].Namespace, commandString, ctx)
+ Expect(err).NotTo(HaveOccurred(), "failed to execute command, err: %v ", err)
+ Expect(string(res)).To(ContainSubstring("1400"))
+ })
+
+ // failed to create ipvlan: device or resource busy
+ //
+ It("test the multusConfig with mtu size for ipvlan", Label("M00034"), func() {
+ smcName := "mtu" + common.GenerateString(10, true)
+ smc := &v2beta1.SpiderMultusConfig{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: smcName,
+ Namespace: namespace,
+ },
+ Spec: v2beta1.MultusCNIConfigSpec{
+ CniType: ptr.To(string(constant.IPVlanCNI)),
+ IPVlanConfig: &v2beta1.SpiderIPvlanCniConfig{
+ Master: []string{common.NIC4},
+ MTU: ptr.To(int32(-1)),
+ SpiderpoolConfigPools: &v2beta1.SpiderpoolPools{},
+ },
+ },
+ }
+
+ ginkgo.By("create a spiderMultusConfig with invalid mtu size")
+ err := frame.CreateSpiderMultusInstance(smc)
+ Expect(err).To(HaveOccurred(), "create invalid spiderMultusConfig should fail: %v", err)
+
+ smc.Spec.IPVlanConfig.MTU = ptr.To(int32(1400))
+ if frame.Info.IpV4Enabled {
+ smc.Spec.IPVlanConfig.SpiderpoolConfigPools.IPv4IPPool = []string{"default-v4-ippool"}
+ }
+ if frame.Info.IpV6Enabled {
+ smc.Spec.IPVlanConfig.SpiderpoolConfigPools.IPv6IPPool = []string{"default-v6-ippool"}
+ }
+
+ ginkgo.By("create a spiderMultusConfig with mtu size")
+ err = frame.CreateSpiderMultusInstance(smc)
+ Expect(err).NotTo(HaveOccurred())
+
+ nad, err := frame.GetMultusInstance(smcName, namespace)
+ Expect(err).NotTo(HaveOccurred())
+ GinkgoWriter.Printf("Multus Nad created: %+v \n", nad.Spec.Config)
+ })
+
+ It("test the multusConfig with mtu size for sriov", Label("M00035"), func() {
+ smcName := "mtu" + common.GenerateString(10, true)
+ smc := &v2beta1.SpiderMultusConfig{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: smcName,
+ Namespace: namespace,
+ },
+ Spec: v2beta1.MultusCNIConfigSpec{
+ CniType: ptr.To(string(constant.SriovCNI)),
+ SriovConfig: &v2beta1.SpiderSRIOVCniConfig{
+ MTU: ptr.To(int32(-1)),
+ ResourceName: ptr.To("spidernet.io/test"),
+ RdmaIsolation: ptr.To(true),
+ },
+ },
+ }
+
+ ginkgo.By("create a spiderMultusConfig with invalid mtu size")
+ err := frame.CreateSpiderMultusInstance(smc)
+ Expect(err).To(HaveOccurred(), "create invalid spiderMultusConfig should fail: %v", err)
+
+ smc.Spec.SriovConfig.MTU = ptr.To(int32(1400))
+ ginkgo.By("create a spiderMultusConfig with mtu size")
+ err = frame.CreateSpiderMultusInstance(smc)
+ Expect(err).NotTo(HaveOccurred())
+
+ nad, err := frame.GetMultusInstance(smcName, namespace)
+ Expect(err).NotTo(HaveOccurred())
+ GinkgoWriter.Printf("Multus Nad created: %+v \n", nad.Spec.Config)
+ })
})