Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 6a4c032

Browse files
togashidmmadalazar
authored andcommitted
Extend multimetric rules combination
Modifications on CRD to include operators and the new logical operators allOf/anyOf. This would allow multimetrics combinations within a rule in the same strategy.
1 parent ef768b5 commit 6a4c032

File tree

5 files changed

+65
-8
lines changed

5 files changed

+65
-8
lines changed

telemetry-aware-scheduling/deploy/tas-policy-crd.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,18 @@ spec:
3535
properties:
3636
policyName:
3737
type: string
38+
logicalOperator:
39+
type: string
40+
enum: ["allOf", "anyOf"]
3841
rules:
3942
items:
43+
description: Set rules parameters per strategy
4044
properties:
4145
metricname:
4246
type: string
4347
operator:
4448
type: string
49+
enum: ["Equals","LessThan","GreaterThan"]
4550
target:
4651
format: int64
4752
type: integer

telemetry-aware-scheduling/pkg/strategies/deschedule/strategy.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,42 @@ func (d *Strategy) StrategyType() string {
3030
//Returns a map of nodeNames as key with an empty value associated with each.
3131
func (d *Strategy) Violated(cache cache.Reader) map[string]interface{} {
3232
violatingNodes := map[string]interface{}{}
33+
nodeMetricViol := map[string]int{}
34+
3335
for _, rule := range d.Rules {
3436
nodeMetrics, err := cache.ReadMetric(rule.Metricname)
37+
3538
if err != nil {
3639
klog.V(2).InfoS(err.Error(), "component", "controller")
40+
3741
continue
3842
}
43+
3944
for nodeName, nodeMetric := range nodeMetrics {
4045
msg := fmt.Sprint(nodeName+" "+rule.Metricname, " = ", nodeMetric.Value.AsDec())
4146
klog.V(4).InfoS(msg, "component", "controller")
47+
4248
if core.EvaluateRule(nodeMetric.Value, rule) {
43-
msg := fmt.Sprintf(nodeName + " violating " + d.PolicyName + ": " + ruleToString(rule))
44-
klog.V(2).InfoS(msg, "component", "controller")
45-
violatingNodes[nodeName] = nil
49+
klog.V(2).Infof("%v violated in node %v", rule.Metricname, nodeName)
50+
nodeMetricViol[nodeName]++
51+
52+
if d.LogicalOperator == "allOf" {
53+
if nodeMetricViol[nodeName] == len(d.Rules) {
54+
msg := fmt.Sprint(nodeName + " violating all the rules in " + d.StrategyType() + " strategy")
55+
klog.V(2).InfoS(msg, "component", "controller")
56+
57+
violatingNodes[nodeName] = nil
58+
}
59+
} else {
60+
msg := fmt.Sprintf(nodeName + " violating " + d.PolicyName + ": " + ruleToString(rule))
61+
klog.V(2).InfoS(msg, "component", "controller")
62+
63+
violatingNodes[nodeName] = nil
64+
}
4665
}
4766
}
4867
}
68+
4969
return violatingNodes
5070
}
5171

telemetry-aware-scheduling/pkg/strategies/dontschedule/strategy.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,40 @@ const (
2424
//If any single rule is violated the method returns a set of nodes that are currently in violation.
2525
func (d *Strategy) Violated(cache cache.Reader) map[string]interface{} {
2626
violatingNodes := map[string]interface{}{}
27+
nodeMetricViol := map[string]int{}
28+
2729
for _, rule := range d.Rules {
2830
nodeMetrics, err := cache.ReadMetric(rule.Metricname)
2931
if err != nil {
3032
klog.V(2).InfoS(err.Error(), "component", "controller")
33+
3134
continue
3235
}
36+
3337
for nodeName, nodeMetric := range nodeMetrics {
3438
msg := fmt.Sprint(nodeName+" "+rule.Metricname, " = ", nodeMetric.Value.AsDec())
3539
klog.V(2).InfoS(msg, "component", "controller")
40+
3641
if core.EvaluateRule(nodeMetric.Value, rule) {
37-
msg := fmt.Sprint(nodeName + " violating " + d.PolicyName + ": " + ruleToString(rule))
38-
klog.V(2).InfoS(msg, "component", "controller")
39-
violatingNodes[nodeName] = nil
42+
nodeMetricViol[nodeName]++
43+
44+
if d.LogicalOperator == "allOf" {
45+
if nodeMetricViol[nodeName] == len(d.Rules) {
46+
msg := fmt.Sprint(nodeName + " violating all the rules in " + d.StrategyType() + " strategy")
47+
klog.V(2).InfoS(msg, "component", "controller")
48+
49+
violatingNodes[nodeName] = nil
50+
}
51+
} else {
52+
msg := fmt.Sprint(nodeName + " violating " + d.PolicyName + ": " + ruleToString(rule))
53+
klog.V(2).InfoS(msg, "component", "controller")
54+
55+
violatingNodes[nodeName] = nil
56+
}
4057
}
4158
}
4259
}
60+
4361
return violatingNodes
4462
}
4563

@@ -56,6 +74,7 @@ func (d *Strategy) StrategyType() string {
5674
//Equals implementation which checks to see if all rules and the policy name are equal for this strategy and another.
5775
//Used to avoid duplications and to find the correct strategy for deletions in the index.
5876
func (d *Strategy) Equals(other core.Interface) bool {
77+
5978
OtherDontScheduleStrategy, ok := other.(*Strategy)
6079
sameName := other.GetPolicyName() == d.GetPolicyName()
6180
if ok && sameName && len(d.Rules) > 0 && len(d.Rules) == len(OtherDontScheduleStrategy.Rules) {

telemetry-aware-scheduling/pkg/strategies/labeling/strategy.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ func (d *Strategy) Violated(cache cache.Reader) map[string]interface{} {
7878
}
7979
}
8080

81+
if d.LogicalOperator == "allOf" {
82+
for nodeName := range violatingNodes {
83+
if _, ok := violatingNodes[nodeName]; ok {
84+
if res, ok := violatingNodes[nodeName].(*violationResultType); ok {
85+
if len(res.ruleResults) != len(d.Rules) {
86+
delete(violatingNodes, nodeName)
87+
}
88+
}
89+
}
90+
}
91+
}
92+
8193
return violatingNodes
8294
}
8395

telemetry-aware-scheduling/pkg/telemetrypolicy/api/v1alpha1/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ type TASPolicy struct {
2323

2424
// TASPolicyStrategy contains a set of TASPolicyRule which define the strategy.
2525
type TASPolicyStrategy struct {
26-
PolicyName string `json:"policyName"`
27-
Rules []TASPolicyRule `json:"rules"`
26+
PolicyName string `json:"policyName"`
27+
LogicalOperator string `json:"logicalOperator,omitempty"`
28+
Rules []TASPolicyRule `json:"rules"`
2829
}
2930

3031
// TASPolicyRule contains the parameters for the strategy rule.

0 commit comments

Comments
 (0)