Skip to content

Commit

Permalink
feat: support gw qos
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Jul 2, 2020
1 parent 24e6435 commit 54acd0c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/ovs/ovs-vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 54acd0c

Please sign in to comment.