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 66643ba commit 4a34c5d
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions pkg/ovs/ovs-vsctl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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 @@ -72,6 +71,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 @@ -202,7 +207,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 @@ -362,3 +366,42 @@ func IsUserspaceDataPath() (is bool, err error) {
}
return len(dp) > 0 && dp[0] == "netdev", 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 4a34c5d

Please sign in to comment.