Skip to content

Commit

Permalink
traffic rate for multus nic
Browse files Browse the repository at this point in the history
fix error check

check the bandwidth parameters
  • Loading branch information
fanriming committed May 23, 2021
1 parent 1667f14 commit ed49cd4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
24 changes: 23 additions & 1 deletion pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,29 @@ func (c *Controller) handlePod(key string) error {
return err
}

return ovs.SetInterfaceBandwidth(fmt.Sprintf("%s.%s", pod.Name, pod.Namespace), pod.Annotations[util.EgressRateAnnotation], pod.Annotations[util.IngressRateAnnotation])
// set default nic bandwidth
ifaceID := ovs.PodNameToPortName(pod.Name, pod.Namespace, util.OvnProvider)
err = ovs.SetInterfaceBandwidth(pod.Name, pod.Namespace, ifaceID, pod.Annotations[util.EgressRateAnnotation], pod.Annotations[util.IngressRateAnnotation])
if err != nil {
return err
}

// set multis-nic bandwidth
attachNets, err := util.ParsePodNetworkAnnotation(pod.Annotations[util.AttachmentNetworkAnnotation], pod.Namespace)
if err != nil {
return err
}
for _, multiNet := range attachNets {
provider := fmt.Sprintf("%s.%s.ovn", multiNet.Name, multiNet.Namespace)
if pod.Annotations[fmt.Sprintf(util.AllocatedAnnotationTemplate, provider)] == "true" {
ifaceID = ovs.PodNameToPortName(pod.Name, pod.Namespace, provider)
err = ovs.SetInterfaceBandwidth(pod.Name, pod.Namespace, ifaceID, pod.Annotations[fmt.Sprintf(util.IngressRateAnnotationTemplate, provider)], pod.Annotations[fmt.Sprintf(util.EgressRateAnnotationTemplate, provider)])
if err != nil {
return err
}
}
}
return nil
}

// Run starts controller
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func (c *Controller) setGatewayBandwidth() error {
}
ingress, egress := node.Annotations[util.IngressRateAnnotation], node.Annotations[util.EgressRateAnnotation]
ifaceId := fmt.Sprintf("node-%s", c.config.NodeName)
return ovs.SetInterfaceBandwidth(ifaceId, egress, ingress)
return ovs.SetInterfaceBandwidth("", "", ifaceId, egress, ingress)
}

func (c *Controller) setICGateway() 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 @@ -56,7 +56,7 @@ func (csh cniServerHandler) configureNic(podName, podNamespace, provider, netns,
if err = configureHostNic(hostNicName, vlanID); err != nil {
return err
}
if err = ovs.SetInterfaceBandwidth(fmt.Sprintf("%s.%s", podName, podNamespace), ingress, egress); err != nil {
if err = ovs.SetInterfaceBandwidth(podName, podNamespace, ifaceID, ingress, egress); err != nil {
return err
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/ovs/ovs-vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"
"time"

"github.com/kubeovn/kube-ovn/pkg/util"
"k8s.io/klog"
)

Expand Down Expand Up @@ -93,6 +94,12 @@ func ClearPodBandwidth(podName, podNamespace string) error {
if err != nil {
return err
}
qosListByPod, err := ovsFind("qos", "_uuid", fmt.Sprintf(`external-ids:pod="%s/%s"`, podNamespace, podName))
if err != nil {
return err
}
qosList = append(qosList, qosListByPod...)
qosList = util.UniqString(qosList)
for _, qos := range qosList {
if err := ovsDestroy("qos", qos); err != nil {
return err
Expand All @@ -102,7 +109,7 @@ func ClearPodBandwidth(podName, podNamespace string) error {
}

// SetInterfaceBandwidth set ingress/egress qos for given pod
func SetInterfaceBandwidth(iface, ingress, egress string) error {
func SetInterfaceBandwidth(podName, podNamespace, iface, ingress, egress string) error {
ingressMPS, _ := strconv.Atoi(ingress)
ingressKPS := ingressMPS * 1000
interfaceList, err := ovsFind("interface", "name", fmt.Sprintf("external-ids:iface-id=%s", iface))
Expand All @@ -126,7 +133,11 @@ func SetInterfaceBandwidth(iface, ingress, egress string) error {
}
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", iface))
qosCommandValues := []string{"type=linux-htb", fmt.Sprintf("other-config:max-rate=%d", egressBPS), fmt.Sprintf("external-ids:iface-id=%s", iface)}
if podNamespace != "" && podName != "" {
qosCommandValues = append(qosCommandValues, fmt.Sprintf("external-ids:pod=%s/%s", podNamespace, podName))
}
qos, err := ovsCreate("qos", qosCommandValues...)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ const (
VlanIdAnnotationTemplate = "%s.kubernetes.io/vlan_id"
VlanRangeAnnotationTemplate = "%s.kubernetes.io/vlan_range"
NetworkTypeTemplate = "%s.kubernetes.io/network_types"
IngressRateAnnotationTemplate = "%s.ovn.kubernetes.io/ingress_rate"
EgressRateAnnotationTemplate = "%s.ovn.kubernetes.io/egress_rate"
IngressRateAnnotationTemplate = "%s.kubernetes.io/ingress_rate"
EgressRateAnnotationTemplate = "%s.kubernetes.io/egress_rate"

ExcludeIpsAnnotation = "ovn.kubernetes.io/exclude_ips"

Expand Down

0 comments on commit ed49cd4

Please sign in to comment.