Skip to content

Commit

Permalink
slo-controller: let node-level network bandwidth takes precedence ove…
Browse files Browse the repository at this point in the history
…r cluster or node strategy

Signed-off-by: sjtufl <jerryfang555@qq.com>
  • Loading branch information
sjtufl committed Apr 7, 2024
1 parent 8838ce9 commit 1170f25
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 6 deletions.
26 changes: 24 additions & 2 deletions pkg/slo-controller/nodeslo/resource_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/klog/v2"

"github.com/koordinator-sh/koordinator/apis/configuration"
"github.com/koordinator-sh/koordinator/apis/extension"
slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
"github.com/koordinator-sh/koordinator/pkg/util"
)
Expand Down Expand Up @@ -79,6 +80,9 @@ func getCPUBurstConfigSpec(node *corev1.Node, cfg *configuration.CPUBurstCfg) (*
}

func getSystemConfigSpec(node *corev1.Node, cfg *configuration.SystemCfg) (*slov1alpha1.SystemStrategy, error) {
var nodeSystemConfig *slov1alpha1.SystemStrategy

// Find strategy that matches current node.
nodeLabels := labels.Set(node.Labels)
for _, nodeStrategy := range cfg.NodeStrategies {
selector, err := metav1.LabelSelectorAsSelector(nodeStrategy.NodeSelector)
Expand All @@ -87,11 +91,29 @@ func getSystemConfigSpec(node *corev1.Node, cfg *configuration.SystemCfg) (*slov
continue
}
if selector.Matches(nodeLabels) {
return nodeStrategy.SystemStrategy.DeepCopy(), nil
nodeSystemConfig = nodeStrategy.SystemStrategy.DeepCopy()
break
}
}

// If there is no matched node strategy, use cluster strategy.
if nodeSystemConfig == nil {
nodeSystemConfig = cfg.ClusterStrategy.DeepCopy()
}
return cfg.ClusterStrategy.DeepCopy(), nil

// Check whether node bandwidth is specified on current node, which takes HIGHER priority
// than ones configured in cluster strategy or node strategy.
// Error is returned if failed to parse node total bandwidth from annotation, which is not
// supposed to happen because we will check the validity of the annotation value in node
// plugins of validating webhook.
if nodeBandwidthQuantity, err := extension.GetNodeTotalBandwidth(node.Annotations); err != nil {
klog.Errorf("failed to get node total bandwidth from annotation, error: %v", err)
return nil, err
} else if nodeBandwidthQuantity != nil {
nodeSystemConfig.TotalNetworkBandwidth = *nodeBandwidthQuantity
}

return nodeSystemConfig, nil
}

func getHostApplicationConfig(node *corev1.Node, cfg *configuration.HostApplicationCfg) ([]slov1alpha1.HostApplicationSpec, error) {
Expand Down
50 changes: 46 additions & 4 deletions pkg/slo-controller/nodeslo/resource_strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/utils/pointer"

"github.com/koordinator-sh/koordinator/apis/configuration"
"github.com/koordinator-sh/koordinator/apis/extension"
ext "github.com/koordinator-sh/koordinator/apis/extension"
slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
"github.com/koordinator-sh/koordinator/pkg/util/sloconfig"
Expand Down Expand Up @@ -812,12 +813,14 @@ func Test_getSystemConfigSpec(t *testing.T) {
defaultConfig := DefaultSLOCfg()
testingSystemConfig := &configuration.SystemCfg{
ClusterStrategy: &slov1alpha1.SystemStrategy{
MinFreeKbytesFactor: pointer.Int64(150),
MinFreeKbytesFactor: pointer.Int64(150),
TotalNetworkBandwidth: resource.MustParse("10G"),
},
}
testingSystemConfig1 := &configuration.SystemCfg{
ClusterStrategy: &slov1alpha1.SystemStrategy{
MinFreeKbytesFactor: pointer.Int64(150),
MinFreeKbytesFactor: pointer.Int64(150),
TotalNetworkBandwidth: resource.MustParse("100M"),
},
NodeStrategies: []configuration.NodeSystemStrategy{
{
Expand All @@ -829,7 +832,8 @@ func Test_getSystemConfigSpec(t *testing.T) {
},
},
SystemStrategy: &slov1alpha1.SystemStrategy{
MinFreeKbytesFactor: pointer.Int64(120),
MinFreeKbytesFactor: pointer.Int64(120),
TotalNetworkBandwidth: resource.MustParse("10M"),
},
},
{
Expand All @@ -841,11 +845,16 @@ func Test_getSystemConfigSpec(t *testing.T) {
},
},
SystemStrategy: &slov1alpha1.SystemStrategy{
MinFreeKbytesFactor: pointer.Int64(130),
MinFreeKbytesFactor: pointer.Int64(130),
TotalNetworkBandwidth: resource.MustParse("1000M"),
},
},
},
}
injectNodeBandwidth := func(systemStrategy *slov1alpha1.SystemStrategy, bandwidth resource.Quantity) *slov1alpha1.SystemStrategy {
systemStrategy.TotalNetworkBandwidth = bandwidth
return systemStrategy
}
type args struct {
node *corev1.Node
cfg *configuration.SystemCfg
Expand Down Expand Up @@ -907,6 +916,39 @@ func Test_getSystemConfigSpec(t *testing.T) {
},
want: testingSystemConfig1.NodeStrategies[0].SystemStrategy,
},
{
name: "use node-wise bandwidth config while use cluster strategy",
args: args{
node: &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Annotations: map[string]string{
extension.AnnotationNodeBandwidth: "99M",
},
},
},
cfg: testingSystemConfig,
},
want: injectNodeBandwidth(testingSystemConfig.ClusterStrategy.DeepCopy(), resource.MustParse("99M")),
},
{
name: "use node-wise bandwidth config while use node strategy",
args: args{
node: &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "test-node",
Labels: map[string]string{
"zzz": "zzz",
},
Annotations: map[string]string{
extension.AnnotationNodeBandwidth: "99M",
},
},
},
cfg: testingSystemConfig1,
},
want: injectNodeBandwidth(testingSystemConfig1.NodeStrategies[1].SystemStrategy.DeepCopy(), resource.MustParse("99M")),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 1170f25

Please sign in to comment.