Skip to content

Commit

Permalink
optimize ovs request in cni (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed May 13, 2022
1 parent 08f2961 commit f8594a2
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 34 deletions.
70 changes: 45 additions & 25 deletions pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,18 @@ func (c *Controller) reconcileRouters(event subnetEvent) error {
}
}
}

if oldSubnet != nil && newSubnet != nil && oldSubnet.Spec.HtbQos != "" && newSubnet.Spec.HtbQos == "" {
if err := c.deleteSubnetQos(newSubnet); err != nil {
klog.Errorf("failed to delete htb qos for subnet %s: %v", newSubnet.Name, err)
return err
}
} else if newSubnet != nil && newSubnet.Spec.HtbQos != "" {
if err := c.setSubnetQosPriority(newSubnet); err != nil {
klog.Errorf("failed to set htb qos priority for subnet %s: %v", newSubnet.Name, err)
return err
}
}
return nil
}

Expand Down Expand Up @@ -919,9 +931,16 @@ func (c *Controller) handlePod(key string) error {
podName = pod.Annotations[fmt.Sprintf(util.VmTemplate, util.OvnProvider)]
}

priority := pod.Annotations[util.PriorityAnnotation]
subnetName := pod.Annotations[util.LogicalSwitchAnnotation]
subnetPriority := c.getSubnetQosPriority(subnetName)
if priority == "" && subnetPriority != "" {
priority = subnetPriority
}

// set default nic bandwidth
ifaceID := ovs.PodNameToPortName(podName, pod.Namespace, util.OvnProvider)
err = ovs.SetInterfaceBandwidth(podName, pod.Namespace, ifaceID, pod.Annotations[util.EgressRateAnnotation], pod.Annotations[util.IngressRateAnnotation], pod.Annotations[util.PriorityAnnotation])
err = ovs.SetInterfaceBandwidth(podName, pod.Namespace, ifaceID, pod.Annotations[util.EgressRateAnnotation], pod.Annotations[util.IngressRateAnnotation], priority)
if err != nil {
return err
}
Expand All @@ -947,7 +966,14 @@ func (c *Controller) handlePod(key string) error {
}
if pod.Annotations[fmt.Sprintf(util.AllocatedAnnotationTemplate, provider)] == "true" {
ifaceID = ovs.PodNameToPortName(podName, pod.Namespace, provider)
err = ovs.SetInterfaceBandwidth(podName, pod.Namespace, ifaceID, pod.Annotations[fmt.Sprintf(util.EgressRateAnnotationTemplate, provider)], pod.Annotations[fmt.Sprintf(util.IngressRateAnnotationTemplate, provider)], pod.Annotations[fmt.Sprintf(util.PriorityAnnotationTemplate, provider)])
priority := pod.Annotations[fmt.Sprintf(util.PriorityAnnotationTemplate, provider)]
subnetName := pod.Annotations[fmt.Sprintf(util.LogicalSwitchAnnotationTemplate, provider)]
subnetPriority := c.getSubnetQosPriority(subnetName)
if priority == "" && subnetPriority != "" {
priority = subnetPriority
}

err = ovs.SetInterfaceBandwidth(podName, pod.Namespace, ifaceID, pod.Annotations[fmt.Sprintf(util.EgressRateAnnotationTemplate, provider)], pod.Annotations[fmt.Sprintf(util.IngressRateAnnotationTemplate, provider)], priority)
if err != nil {
return err
}
Expand Down Expand Up @@ -1034,28 +1060,6 @@ func (c *Controller) markAndCleanInternalPort() error {
return nil
}

func (c *Controller) loopCheckSubnetQosPriority() {
subnets, err := c.subnetsLister.List(labels.Everything())
if err != nil {
klog.Errorf("failed to list subnets %v", err)
return
}

for _, subnet := range subnets {
if subnet.Spec.HtbQos == "" {
if err := c.deleteSubnetQos(subnet); err != nil {
klog.Errorf("failed to delete htb qos for subnet %s: %v", subnet.Name, err)
return
}
} else {
if err := c.setSubnetQosPriority(subnet); err != nil {
klog.Errorf("failed to set htb qos priority for subnet %s: %v", subnet.Name, err)
return
}
}
}
}

func (c *Controller) setSubnetQosPriority(subnet *kubeovnv1.Subnet) error {
htbQos, err := c.htbQosLister.Get(subnet.Spec.HtbQos)
if err != nil {
Expand Down Expand Up @@ -1211,6 +1215,22 @@ func (c *Controller) deleteSubnetQos(subnet *kubeovnv1.Subnet) error {
return nil
}

func (c *Controller) getSubnetQosPriority(subnetName string) string {
var priority string
subnet, err := c.subnetsLister.Get(subnetName)
if err != nil {
klog.Errorf("failed to get subnet %s: %v", subnet, err)
} else if subnet.Spec.HtbQos != "" {
htbQos, err := c.htbQosLister.Get(subnet.Spec.HtbQos)
if err != nil {
klog.Errorf("failed to get htbqos %s: %v", subnet.Spec.HtbQos, err)
} else {
priority = htbQos.Spec.Priority
}
}
return priority
}

// Run starts controller
func (c *Controller) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
Expand Down Expand Up @@ -1245,7 +1265,7 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
klog.Errorf("gc ovs port error: %v", err)
}
}, 5*time.Minute, stopCh)
go wait.Until(c.loopCheckSubnetQosPriority, 5*time.Second, stopCh)

<-stopCh
klog.Info("Shutting down workers")
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/daemon/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ func (c *Controller) setGatewayBandwidth() error {
}
ingress, egress, priority := node.Annotations[util.IngressRateAnnotation], node.Annotations[util.EgressRateAnnotation], node.Annotations[util.PriorityAnnotation]
ifaceId := fmt.Sprintf("node-%s", c.config.NodeName)
if ingress == "" && egress == "" && priority == "" {
if htbQos, _ := ovs.IsHtbQos(ifaceId); !htbQos {
return nil
}
}
return ovs.SetInterfaceBandwidth("", "", ifaceId, egress, ingress, priority)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/daemon/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func (csh cniServerHandler) handleAdd(req *restful.Request, resp *restful.Respon
return
}

subnetPriority := csh.Controller.getSubnetQosPriority(subnet)
if priority == "" && subnetPriority != "" {
priority = subnetPriority
}

//skip ping check gateway for pods during live migration
if pod.Annotations[fmt.Sprintf(util.LiveMigrationAnnotationTemplate, podRequest.Provider)] != "true" {
if !podSubnet.Spec.DisableGatewayCheck {
Expand Down
12 changes: 3 additions & 9 deletions pkg/ovs/ovs-vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,19 +429,13 @@ func ClearHtbQosQueue(podName, podNamespace, iface string) error {
}

func IsHtbQos(iface string) (bool, error) {
qosList, err := ovsFind("qos", "_uuid", fmt.Sprintf(`external-ids:iface-id="%s"`, iface))
qosType, err := ovsFind("qos", "type", fmt.Sprintf(`external-ids:iface-id="%s"`, iface))
if err != nil {
return false, err
}

for _, qos := range qosList {
qosType, err := ovsGet("qos", qos, "type", "")
if err != nil {
return false, err
}
if qosType == util.HtbQos {
return true, nil
}
if len(qosType) != 0 && qosType[0] == util.HtbQos {
return true, nil
}
return false, nil
}
Expand Down

0 comments on commit f8594a2

Please sign in to comment.