-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lucming <2876757716@qq.com>
- Loading branch information
Showing
17 changed files
with
1,406 additions
and
12 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | ||
} |
Oops, something went wrong.