Skip to content

Commit

Permalink
delete htb qos when releated annotation is deleted (#1788)
Browse files Browse the repository at this point in the history
  • Loading branch information
hongzhen-ma committed Aug 9, 2022
1 parent 85bd5f9 commit 38ee830
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions pkg/ovs/ovs-vsctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ func SetInterfaceBandwidth(podName, podNamespace, iface, ingress, egress, podPri
return err
}

// It's difficult to check if qos and queue should be destroyed here since can not get subnet info here. So leave destroy operation in loop check
if _, err := Exec("remove", "queue", queueId, "other_config", "max-rate"); err != nil {
return fmt.Errorf("failed to remove rate limit for queue in pod %v/%v, %v", podNamespace, podName, err)
}
Expand All @@ -245,6 +244,12 @@ func SetInterfaceBandwidth(podName, podNamespace, iface, ingress, egress, podPri
if err = SetHtbQosPriority(podName, podNamespace, iface, ifName, podPriority, qosIfaceUidMap, queueIfaceUidMap); err != nil {
return err
}

// Delete Qos and Queue record if both bandwidth and priority do not exist
if err = CheckAndUpdateHtbQos(podName, podNamespace, iface, queueIfaceUidMap); err != nil {
klog.Errorf("failed to check htb qos: %v", err)
return err
}
}
return nil
}
Expand Down Expand Up @@ -499,7 +504,6 @@ func SetHtbQosPriority(podName, podNamespace, iface, ifName, priority string, qo
return err
}

// It's difficult to check if qos and queue should be destroyed here since can not get subnet info here. So leave destroy operation in subnet loop check
if _, err := Exec("remove", "queue", queueId, "other_config", "priority"); err != nil {
return fmt.Errorf("failed to remove priority for queue in pod %v/%v, %v", podNamespace, podName, err)
}
Expand Down Expand Up @@ -739,3 +743,42 @@ func ListQosQueueIds() (map[string]string, error) {
}
return result, nil
}

func CheckAndUpdateHtbQos(podName, podNamespace, ifaceID string, queueIfaceUidMap map[string]string) error {
var queueUid string
var ok bool
if queueUid, ok = queueIfaceUidMap[ifaceID]; !ok {
return nil
}

config, err := ovsGet("queue", queueUid, "other_config", "")
if err != nil {
klog.Errorf("failed to get other_config for queueId %s: %v", queueUid, err)
return err
}
// bandwidth or priority exists, can not delete qos
if config != "{}" {
return nil
}

// recall clearQos
if htbQos, _ := IsHtbQos(ifaceID); !htbQos {
return nil
}

if err := ClearPortQosBinding(ifaceID); err != nil {
klog.Errorf("failed to delete qos bingding info: %v", err)
return err
}

if err := ClearPodBandwidth(podName, podNamespace, ifaceID); err != nil {
klog.Errorf("failed to delete htbqos record: %v", err)
return err
}

if err := ClearHtbQosQueue(podName, podNamespace, ifaceID); err != nil {
klog.Errorf("failed to delete htbqos queue: %v", err)
return err
}
return nil
}

0 comments on commit 38ee830

Please sign in to comment.