Commit 54acd0c3 authored by Mengxin Liu's avatar Mengxin Liu Committed by oilbeater
Browse files

feat: support gw qos

parent 24e6435e
Showing with 24 additions and 7 deletions
+24 -7
......@@ -342,7 +342,7 @@ func (c *Controller) handlePod(key string) error {
return err
}
return ovs.SetPodBandwidth(pod.Name, pod.Namespace, pod.Annotations[util.EgressRateAnnotation], pod.Annotations[util.IngressRateAnnotation])
return ovs.SetInterfaceBandwidth(fmt.Sprintf("%s.%s", pod.Name, pod.Namespace), pod.Annotations[util.EgressRateAnnotation], pod.Annotations[util.IngressRateAnnotation])
}
// Run starts controller
......
......@@ -3,8 +3,10 @@ package daemon
import (
"fmt"
kubeovnv1 "github.com/alauda/kube-ovn/pkg/apis/kubeovn/v1"
"github.com/alauda/kube-ovn/pkg/ovs"
"github.com/alauda/kube-ovn/pkg/util"
"github.com/projectcalico/felix/ipsets"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/klog"
"net"
......@@ -131,6 +133,21 @@ func (c *Controller) runGateway() {
}
}
}
if err := c.setGatewayBandwidth(); err != nil {
klog.Errorf("failed to set gw bandwidth, %v", err)
}
}
func (c *Controller) setGatewayBandwidth() error {
node, err := c.config.KubeClient.CoreV1().Nodes().Get(c.config.NodeName, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get node, %v", err)
return err
}
ingress, egress := node.Annotations[util.IngressRateAnnotation], node.Annotations[util.EgressRateAnnotation]
ifaceId := fmt.Sprintf("node-%s", c.config.NodeName)
return ovs.SetInterfaceBandwidth(ifaceId, ingress, egress)
}
func (c *Controller) getLocalPodIPsNeedNAT(protocol string) ([]string, error) {
......
......@@ -53,7 +53,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, netns, container
if err = configureHostNic(hostNicName, vlanID, macAddr); err != nil {
return err
}
if err = ovs.SetPodBandwidth(podName, podNamespace, ingress, egress); err != nil {
if err = ovs.SetInterfaceBandwidth(fmt.Sprintf("%s.%s", podName, podNamespace), ingress, egress); err != nil {
return err
}
......
......@@ -91,11 +91,11 @@ func ClearPodBandwidth(podName, podNamespace string) error {
return nil
}
// SetPodBandwidth set ingress/egress qos for given pod
func SetPodBandwidth(podName, podNamespace, ingress, egress string) error {
// SetInterfaceBandwidth set ingress/egress qos for given pod
func SetInterfaceBandwidth(iface, ingress, egress string) error {
ingressMPS, _ := strconv.Atoi(ingress)
ingressKPS := ingressMPS * 1000
interfaceList, err := ovsFind("interface", "name", fmt.Sprintf("external-ids:iface-id=%s.%s", podName, podNamespace))
interfaceList, err := ovsFind("interface", "name", fmt.Sprintf("external-ids:iface-id=%s", iface))
if err != nil {
return err
}
......@@ -110,13 +110,13 @@ func SetPodBandwidth(podName, podNamespace, ingress, egress string) error {
egressMPS, _ := strconv.Atoi(egress)
egressBPS := egressMPS * 1000 * 1000
qosList, err := ovsFind("qos", "_uuid", fmt.Sprintf("external-ids:iface-id=%s.%s", podName, podNamespace))
qosList, err := ovsFind("qos", "_uuid", fmt.Sprintf("external-ids:iface-id=%s", iface))
if err != nil {
return err
}
if egressBPS > 0 {
if len(qosList) == 0 {
qos, err := ovsCreate("qos", "type=linux-htb", fmt.Sprintf("other-config:max-rate=%d", egressBPS), fmt.Sprintf("external-ids:iface-id=%s.%s", podName, podNamespace))
qos, err := ovsCreate("qos", "type=linux-htb", fmt.Sprintf("other-config:max-rate=%d", egressBPS), fmt.Sprintf("external-ids:iface-id=%s", iface))
if err != nil {
return err
}
......
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