Skip to content

Commit

Permalink
SpiderMultusConfig: Fix error json tag for min/maxTxRateMbps
Browse files Browse the repository at this point in the history
Signed-off-by: Cyclinder Kuo <[email protected]>
Signed-off-by: cyclinder <[email protected]>
  • Loading branch information
cyclinder committed Mar 4, 2025
1 parent 245f6c8 commit 26f9f23
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
12 changes: 6 additions & 6 deletions docs/usage/spider-multus-config-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ spec:
config: '{"cniVersion":"0.3.1","name":"sriov-rdma","plugins":[{"vlan":100,"type":"sriov","ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"}]}'
```

- 配置 Sriov 网络带宽
- 限制 Sriov VF 传输带宽

我们可通过 SpiderMultusConfig 配置 Sriov 的网络带宽:
我们可通过 SpiderMultusConfig 限制 Sriov VF 传输带宽:

```bash
cat <<EOF | kubectl apply -f -
Expand All @@ -405,11 +405,11 @@ spec:
resourceName: spidernet.io/sriov_netdeivce
vlanID: 100
minTxRateMbps: 100
MaxTxRateMbps: 1000
maxTxRateMbps: 1000
EOF
```

> `minTxRateMbps``MaxTxRateMbps` 配置此 CNI 配置文件的网络传输带宽范围为: [100,1000]
> `minTxRateMbps``maxTxRateMbps` 配置此 CNI 配置文件的网络传输带宽范围为: [100,1000]

创建后,查看对应的 Multus NetworkAttachmentDefinition CR:

Expand All @@ -430,7 +430,7 @@ metadata:
name: sriov-bandwidth
uid: b08ce054-1ae8-414a-b37c-7fd6988b1b8e
spec:
config: '{"cniVersion":"0.3.1","name":"sriov-bandwidth","plugins":[{"vlan":100,"type":"sriov","minTxRate": 100, "maxTxRate": 1000,"ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"}]}'
config: '{"cniVersion":"0.3.1","name":"sriov-bandwidth","plugins":[{"vlan":100,"type":"sriov","min_tx_rate": 100, "max_tx_rate": 1000,"ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"}]}'
```

- 配置 Sriov VF 的 MTU 大小
Expand Down Expand Up @@ -475,7 +475,7 @@ metadata:
name: sriov-bandwidth
uid: b08ce054-1ae8-414a-b37c-7fd6988b1b8e
spec:
config: '{"cniVersion":"0.3.1","name":"sriov-bandwidth","plugins":[{"vlan":100,"type":"sriov","minTxRate": 100, "maxTxRate": 1000,"ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"},{"type":"tuning","mtu":8000}]}'
config: '{"cniVersion":"0.3.1","name":"sriov-bandwidth","plugins":[{"vlan":100,"type":"sriov","min_tx_rate": 0, "max_tx_rate": 0,"ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"},{"type":"tuning","mtu":8000}]}'
```

### Ifacer 使用配置
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/spider-multus-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ spec:
EOF
```
> minTxRateMbps and MaxTxRateMbps configure the transmission bandwidth range for pods created with this configuration: [100,1000].
> minTxRateMbps and maxTxRateMbps configure the transmission bandwidth range for pods created with this configuration: [100,1000].
After creation, check the corresponding Multus NetworkAttachmentDefinition CR:
Expand All @@ -432,7 +432,7 @@ metadata:
name: sriov-bandwidth
uid: b08ce054-1ae8-414a-b37c-7fd6988b1b8e
spec:
config: '{"cniVersion":"0.3.1","name":"sriov-bandwidth","plugins":[{"vlan":100,"type":"sriov","minTxRate": 100, "maxTxRate": 1000,"ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"}]}'
config: '{"cniVersion":"0.3.1","name":"sriov-bandwidth","plugins":[{"vlan":100,"type":"sriov","min_tx_rate": 100, "max_tx_rate": 1000,"ipam":{"type":"spiderpool"}},{"type":"rdma"},{"type":"coordinator"}]}'
```
- Configure the mtu size of the Sriov VF
Expand Down
1 change: 1 addition & 0 deletions pkg/constant/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const (
IPoIBCNI = "ipoib"
OvsCNI = "ovs"
CustomCNI = "custom"
TuningCNI = "tuning"
)

const WebhookMutateRoute = "/webhook-health-check"
Expand Down
4 changes: 2 additions & 2 deletions pkg/multuscniconfig/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ type IPvlanNetConf struct {
type SRIOVNetConf struct {
Vlan *int32 `json:"vlan,omitempty"`
// Mbps, 0 = disable rate limiting
MinTxRate *int `json:"minTxRate,omitempty"`
MinTxRate *int `json:"min_tx_rate,omitempty"`
// Mbps, 0 = disable rate limiting
MaxTxRate *int `json:"maxTxRate,omitempty"`
MaxTxRate *int `json:"max_tx_rate,omitempty"`
Type string `json:"type"`
DeviceID string `json:"deviceID,omitempty"`
IPAM *spiderpoolcmd.IPAMConfig `json:"ipam,omitempty"`
Expand Down
26 changes: 24 additions & 2 deletions test/e2e/spidermultus/spidermultus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ var _ = Describe("test spidermultus", Label("SpiderMultusConfig"), func() {
}, common.SpiderSyncMultusTime, common.ForcedWaitingTime).Should(BeTrue())
})

It("test the multusConfig with mtu size for sriov", Label("M00035"), func() {
It("test the multusConfig with for sriov", Label("M00035"), func() {
smcName := "mtu" + common.GenerateString(10, true)
smc := &v2beta1.SpiderMultusConfig{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -1208,6 +1208,8 @@ var _ = Describe("test spidermultus", Label("SpiderMultusConfig"), func() {
MTU: ptr.To(int32(-1)),
ResourceName: ptr.To("spidernet.io/test"),
RdmaIsolation: ptr.To(true),
MinTxRateMbps: ptr.To(int(10)),
MaxTxRateMbps: ptr.To(int(30)),
},
},
}
Expand All @@ -1225,7 +1227,27 @@ var _ = Describe("test spidermultus", Label("SpiderMultusConfig"), func() {
nad, err := frame.GetMultusInstance(smcName, namespace)
if err == nil {
GinkgoWriter.Printf("Multus Nad created: %+v \n", nad.Spec.Config)
return true
config, err := libcni.ConfListFromBytes([]byte(nad.Spec.Config))
Expect(err).NotTo(HaveOccurred())

sriov, tuning := false, false
for _, p := range config.Plugins {
c := make(map[string]interface{})
err = json.Unmarshal(p.Bytes, &c)
Expect(err).NotTo(HaveOccurred())

if c["type"] == constant.SriovCNI {
Expect(c["min_tx_rate"]).To(Equal(float64(10)))
Expect(c["max_tx_rate"]).To(Equal(float64(30)))
sriov = true
}

if c["type"] == constant.TuningCNI {
Expect(c["mtu"]).To(Equal(float64(1400)))
tuning = true
}
}
return sriov && tuning
}

Expect(err.Error()).To(ContainSubstring("not found"))
Expand Down

0 comments on commit 26f9f23

Please sign in to comment.