-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,359 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package extension | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
type NetQosGlobalConfig struct { | ||
HwTxBpsMax uint64 `json:"hw_tx_bps_max"` | ||
HwRxBpsMax uint64 `json:"hw_rx_bps_max"` | ||
L1TxBpsMin uint64 `json:"l1_tx_bps_min"` | ||
L1TxBpsMax uint64 `json:"l1_tx_bps_max"` | ||
L2TxBpsMin uint64 `json:"l2_tx_bps_min"` | ||
L2TxBpsMax uint64 `json:"l2_tx_bps_max"` | ||
L1RxBpsMin uint64 `json:"l1_rx_bps_min"` | ||
L1RxBpsMax uint64 `json:"l1_rx_bps_max"` | ||
L2RxBpsMin uint64 `json:"l2_rx_bps_min"` | ||
L2RxBpsMax uint64 `json:"l2_rx_bps_max"` | ||
} | ||
|
||
type NetQoSClass string | ||
|
||
const ( | ||
NETQoSHigh NetQoSClass = "high_class" | ||
NETQoSMid NetQoSClass = "mid_class" | ||
NETQoSLow NetQoSClass = "low_class" | ||
NETQoSNone NetQoSClass = "" | ||
|
||
NETQOSConfigPathForNode = "/var/run/koordinator/net/node" | ||
NETQOSConfigPathForPod = "/var/run/koordinator/net/pods" | ||
) | ||
|
||
func GetPodNetQoSClassByName(qos string) NetQoSClass { | ||
q := QoSClass(qos) | ||
|
||
switch q { | ||
case QoSSystem: | ||
return NETQoSHigh | ||
case QoSLSE, QoSLSR, QoSLS: | ||
return NETQoSMid | ||
case QoSBE: | ||
return NETQoSLow | ||
} | ||
|
||
return NETQoSNone | ||
} | ||
|
||
func GetPodNetQoSClass(pod *corev1.Pod) NetQoSClass { | ||
if pod == nil || pod.Labels == nil { | ||
return NETQoSNone | ||
} | ||
return GetNetQoSClassByAttrs(pod.Labels, pod.Annotations) | ||
} | ||
|
||
func GetNetQoSClassByAttrs(labels, annotations map[string]string) NetQoSClass { | ||
// annotations are for old format adaption reason | ||
if q, exist := labels[LabelPodQoS]; exist { | ||
return GetPodNetQoSClassByName(q) | ||
} | ||
return NETQoSNone | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tc | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
|
||
"github.com/koordinator-sh/koordinator/apis/extension" | ||
slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1" | ||
) | ||
|
||
func loadConfigFromNodeSlo(nodesloSpec *slov1alpha1.NodeSLOSpec) *extension.NetQosGlobalConfig { | ||
res := extension.NetQosGlobalConfig{} | ||
var total uint64 = 0 | ||
if nodesloSpec != nil && nodesloSpec.SystemStrategy != nil { | ||
total = uint64(nodesloSpec.SystemStrategy.TotalNetworkBandwidth.Value()) | ||
res.HwRxBpsMax = total | ||
res.HwTxBpsMax = total | ||
} | ||
|
||
if nodesloSpec.ResourceQOSStrategy == nil { | ||
return &res | ||
} | ||
|
||
strategy := nodesloSpec.ResourceQOSStrategy | ||
if strategy.LSClass != nil && | ||
strategy.LSClass.NetworkQOS != nil && | ||
*strategy.LSClass.NetworkQOS.Enable { | ||
cur := strategy.LSClass.NetworkQOS | ||
res.L1RxBpsMin = getBandwidthVal(total, cur.IngressRequest) | ||
res.L1RxBpsMax = getBandwidthVal(total, cur.IngressLimit) | ||
res.L1TxBpsMin = getBandwidthVal(total, cur.EgressRequest) | ||
res.L1TxBpsMax = getBandwidthVal(total, cur.EgressLimit) | ||
} | ||
|
||
if strategy.BEClass != nil && | ||
strategy.BEClass.NetworkQOS != nil && | ||
*strategy.BEClass.NetworkQOS.Enable { | ||
cur := strategy.BEClass.NetworkQOS | ||
res.L2RxBpsMin = getBandwidthVal(total, cur.IngressRequest) | ||
res.L2RxBpsMax = getBandwidthVal(total, cur.IngressLimit) | ||
res.L2TxBpsMin = getBandwidthVal(total, cur.EgressRequest) | ||
res.L2TxBpsMax = getBandwidthVal(total, cur.EgressLimit) | ||
} | ||
|
||
return &res | ||
} | ||
|
||
func getBandwidthVal(total uint64, intOrPercent *intstr.IntOrString) uint64 { | ||
if intOrPercent == nil { | ||
return 0 | ||
} | ||
|
||
switch intOrPercent.Type { | ||
case intstr.String: | ||
return getBandwidthByQuantityFormat(intOrPercent.StrVal) | ||
case intstr.Int: | ||
return getBandwidthByPercentageFormat(total, intOrPercent.IntValue()) | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
func getBandwidthByQuantityFormat(quanityStr string) uint64 { | ||
val, err := resource.ParseQuantity(quanityStr) | ||
if err != nil { | ||
return 0 | ||
} | ||
|
||
return uint64(val.Value()) | ||
} | ||
|
||
func getBandwidthByPercentageFormat(total uint64, percentage int) uint64 { | ||
return total * uint64(percentage) / 100 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
/* | ||
Copyright 2022 The Koordinator Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tc | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vishvananda/netlink" | ||
apierror "k8s.io/apimachinery/pkg/util/errors" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func (p *tcPlugin) ipsetExisted() (bool, error) { | ||
var errs []error | ||
for _, cur := range ipsets { | ||
if _, err := netlink.IpsetList(cur); err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
if apierror.NewAggregate(errs) != nil { | ||
return false, apierror.NewAggregate(errs) | ||
} | ||
|
||
return true, nil | ||
} | ||
|
||
func (p *tcPlugin) EnsureIpset() error { | ||
klog.V(5).Infof("start to create ipset.") | ||
var errs []error | ||
for _, cur := range ipsets { | ||
result, err := netlink.IpsetList(cur) | ||
if err == nil && result != nil { | ||
continue | ||
} | ||
|
||
err = netlink.IpsetCreate(cur, "hash:ip", netlink.IpsetCreateOptions{}) | ||
if err != nil { | ||
err = fmt.Errorf("failed to create ipset. err=%v", err) | ||
errs = append(errs, err) | ||
} | ||
} | ||
|
||
return apierror.NewAggregate(errs) | ||
} | ||
|
||
func (p *tcPlugin) DestoryIpset() error { | ||
klog.V(5).Infof("start to delete ipset rules crated by tc plugin.") | ||
var errs []error | ||
for _, cur := range ipsets { | ||
result, err := netlink.IpsetList(cur) | ||
if err == nil && result != nil { | ||
if err := netlink.IpsetDestroy(cur); err != nil { | ||
err = fmt.Errorf("failed to destroy ipset. err=%v", err) | ||
errs = append(errs, err) | ||
} | ||
} | ||
} | ||
|
||
return apierror.NewAggregate(errs) | ||
} |
Oops, something went wrong.