Commit 68ee5eb9 authored by 马洪贞's avatar 马洪贞
Browse files

delete and recreate netem qos when update process

parent e13c4ef1
No related merge requests found
Showing with 74 additions and 37 deletions
+74 -37
...@@ -109,17 +109,6 @@ func ovsGet(table, record, column, key string) (string, error) { ...@@ -109,17 +109,6 @@ func ovsGet(table, record, column, key string) (string, error) {
return Exec(args...) return Exec(args...)
} }
func ovsRemove(table, record, column, key string) error {
args := []string{"remove"}
if key == "" {
args = append(args, table, record, column)
} else {
args = append(args, table, record, column, key)
}
_, err := Exec(args...)
return err
}
// Bridges returns bridges created by Kube-OVN // Bridges returns bridges created by Kube-OVN
func Bridges() ([]string, error) { func Bridges() ([]string, error) {
return ovsFind("bridge", "name", fmt.Sprintf("external-ids:vendor=%s", util.CniTypeName)) return ovsFind("bridge", "name", fmt.Sprintf("external-ids:vendor=%s", util.CniTypeName))
......
...@@ -3,6 +3,7 @@ package ovs ...@@ -3,6 +3,7 @@ package ovs
import ( import (
"fmt" "fmt"
"strconv" "strconv"
"strings"
"k8s.io/klog/v2" "k8s.io/klog/v2"
...@@ -315,42 +316,43 @@ func SetNetemQos(podName, podNamespace, iface, latency, limit, loss string) erro ...@@ -315,42 +316,43 @@ func SetNetemQos(podName, podNamespace, iface, latency, limit, loss string) erro
return nil return nil
} }
if err := ovsSet("qos", qos, qosCommandValues...); err != nil { latencyVal, lossVal, limitVal, err := getNetemQosConfig(qos)
if err != nil {
klog.Errorf("failed to get other_config for qos %s: %v", qos, err)
return err return err
} }
if latencyMs == 0 { if latencyVal == strconv.Itoa(latencyUs) && limitVal == limit && lossVal == loss {
if err := ovsRemove("qos", qos, "other_config", "latency"); err != nil { klog.Infof("no value changed for netem qos, ignore")
return err continue
}
} }
if limitPkts == 0 {
if err := ovsRemove("qos", qos, "other_config", "limit"); err != nil { if err = deleteNetemQosById(qos, iface, podName, podNamespace); err != nil {
return err klog.Errorf("failed to delete netem qos: %v", err)
} return err
}
qosCommandValues = append(qosCommandValues, "type=linux-netem", fmt.Sprintf(`external-ids:iface-id="%s"`, iface))
if podNamespace != "" && podName != "" {
qosCommandValues = append(qosCommandValues, fmt.Sprintf("external-ids:pod=%s/%s", podNamespace, podName))
} }
if lossPercent == 0 {
if err := ovsRemove("qos", qos, "other_config", "loss"); err != nil { qos, err := ovsCreate("qos", qosCommandValues...)
return err if err != nil {
} klog.Errorf("failed to create netem qos: %v", err)
return err
}
err = ovsSet("port", ifName, fmt.Sprintf("qos=%s", qos))
if err != nil {
klog.Errorf("failed to set netem qos to port: %v", err)
return err
} }
} }
} }
} else { } else {
for _, qos := range qosList { for _, qos := range qosList {
qosType, _ := ovsGet("qos", qos, "type", "") if err := deleteNetemQosById(qos, iface, podName, podNamespace); err != nil {
if qosType != util.NetemQos { klog.Errorf("failed to delete netem qos: %v", err)
continue
}
if err = ClearPortQosBinding(iface); err != nil {
klog.Errorf("failed to delete qos bingding info for interface %s: %v", iface, err)
return err
}
// reuse this function to delete qos record
if err = ClearPodBandwidth(podName, podNamespace, iface); err != nil {
klog.Errorf("failed to delete netemqos record for pod %s/%s: %v", podNamespace, podName, err)
return err return err
} }
} }
...@@ -359,6 +361,52 @@ func SetNetemQos(podName, podNamespace, iface, latency, limit, loss string) erro ...@@ -359,6 +361,52 @@ func SetNetemQos(podName, podNamespace, iface, latency, limit, loss string) erro
return nil return nil
} }
func getNetemQosConfig(qosId string) (string, string, string, error) {
var latency, loss, limit string
config, err := ovsGet("qos", qosId, "other_config", "")
if err != nil {
klog.Errorf("failed to get other_config for qos %s: %v", qosId, err)
return latency, loss, limit, err
}
if len(config) == 0 {
return latency, loss, limit, nil
}
values := strings.Split(strings.Trim(config, "{}"), ",")
for _, value := range values {
records := strings.Split(value, "=")
switch strings.TrimSpace(records[0]) {
case "latency":
latency = strings.TrimSpace(records[1])
case "loss":
loss = strings.TrimSpace(records[1])
case "limit":
limit = strings.TrimSpace(records[1])
}
}
return latency, loss, limit, nil
}
func deleteNetemQosById(qosId, iface, podName, podNamespace string) error {
qosType, _ := ovsGet("qos", qosId, "type", "")
if qosType != util.NetemQos {
return nil
}
if err := ClearPortQosBinding(iface); err != nil {
klog.Errorf("failed to delete qos bingding info for interface %s: %v", iface, err)
return err
}
// reuse this function to delete qos record
if err := ClearPodBandwidth(podName, podNamespace, iface); err != nil {
klog.Errorf("failed to delete netemqos record for pod %s/%s: %v", podNamespace, podName, err)
return err
}
return nil
}
func IsUserspaceDataPath() (is bool, err error) { func IsUserspaceDataPath() (is bool, err error) {
dp, err := ovsFind("bridge", "datapath_type", "name=br-int") dp, err := ovsFind("bridge", "datapath_type", "name=br-int")
if err != nil { if err != nil {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment