Skip to content

Commit

Permalink
Add loadaware plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Monokaix <changxuzheng@huawei.com>
  • Loading branch information
Monokaix committed Dec 17, 2024
1 parent e4f35a4 commit 62d0c5d
Show file tree
Hide file tree
Showing 14 changed files with 1,996 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/descheduler/descheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ import (

"k8s.io/component-base/cli"
"sigs.k8s.io/descheduler/pkg/descheduler"
"sigs.k8s.io/descheduler/pkg/framework/pluginregistry"

"volcano.sh/volcano/cmd/descheduler/app"
"volcano.sh/volcano/pkg/descheduler/framework/plugins/loadaware"
)

func init() {
descheduler.SetupPlugins()
pluginregistry.Register(loadaware.LoadAwareUtilizationPluginName, loadaware.NewLoadAwareUtilization, &loadaware.LoadAwareUtilization{}, &loadaware.LoadAwareUtilizationArgs{}, loadaware.ValidateLoadAwareUtilizationArgs, loadaware.SetDefaults_LoadAwareUtilizationArgs, pluginregistry.PluginRegistry)
}

func main() {
Expand Down
71 changes: 71 additions & 0 deletions pkg/descheduler/framework/plugins/loadaware/deepcopy_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 69 additions & 0 deletions pkg/descheduler/framework/plugins/loadaware/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2024 The Volcano 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 loadaware

import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
)

func SetDefaults_LoadAwareUtilizationArgs(obj runtime.Object) {
args, ok := obj.(*LoadAwareUtilizationArgs)
if !ok {
klog.Errorf("obj with type %T could not parse", obj)
}
if !args.UseDeviationThresholds {
args.UseDeviationThresholds = false
}
if args.Thresholds == nil {
args.Thresholds = nil
}
if args.TargetThresholds == nil {
args.TargetThresholds = nil
}
if args.NumberOfNodes == 0 {
args.NumberOfNodes = 0
}
if args.Duration == "" {
args.Duration = "2m"
}
//defaultEvictor
if args.NodeSelector == "" {
args.NodeSelector = ""
}
if !args.EvictLocalStoragePods {
args.EvictLocalStoragePods = false
}
if !args.EvictSystemCriticalPods {
args.EvictSystemCriticalPods = false
}
if !args.IgnorePvcPods {
args.IgnorePvcPods = false
}
if !args.EvictFailedBarePods {
args.EvictFailedBarePods = false
}
if args.LabelSelector == nil {
args.LabelSelector = nil
}
if args.PriorityThreshold == nil {
args.PriorityThreshold = nil
}
if !args.NodeFit {
args.NodeFit = false
}
}
127 changes: 127 additions & 0 deletions pkg/descheduler/framework/plugins/loadaware/defaults_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
Copyright 2024 The Volcano 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 loadaware

import (
"testing"

"github.com/google/go-cmp/cmp"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"sigs.k8s.io/descheduler/pkg/api"
)

func TestSetDefaults_LowNodeUtilizationArgs(t *testing.T) {
tests := []struct {
name string
in runtime.Object
want runtime.Object
}{
{
name: "LowNodeUtilizationArgs empty",
in: &LoadAwareUtilizationArgs{},
want: &LoadAwareUtilizationArgs{
UseDeviationThresholds: false,
Thresholds: nil,
TargetThresholds: nil,
NumberOfNodes: 0,
},
},
{
name: "LowNodeUtilizationArgs with value",
in: &LoadAwareUtilizationArgs{
UseDeviationThresholds: true,
Thresholds: api.ResourceThresholds{
v1.ResourceCPU: 20,
v1.ResourceMemory: 120,
},
TargetThresholds: api.ResourceThresholds{
v1.ResourceCPU: 80,
v1.ResourceMemory: 80,
},
NumberOfNodes: 10,
},
want: &LoadAwareUtilizationArgs{
UseDeviationThresholds: true,
Thresholds: api.ResourceThresholds{
v1.ResourceCPU: 20,
v1.ResourceMemory: 120,
},
TargetThresholds: api.ResourceThresholds{
v1.ResourceCPU: 80,
v1.ResourceMemory: 80,
},
NumberOfNodes: 10,
},
},
}
for _, tc := range tests {
scheme := runtime.NewScheme()
utilruntime.Must(AddToScheme(scheme))
t.Run(tc.name, func(t *testing.T) {
scheme.Default(tc.in)
if diff := cmp.Diff(tc.in, tc.want); diff != "" {
t.Errorf("Got unexpected defaults (-want, +got):\n%s", diff)
}
})
}
}

func TestSetDefaults_HighNodeUtilizationArgs(t *testing.T) {
tests := []struct {
name string
in runtime.Object
want runtime.Object
}{
{
name: "HighNodeUtilizationArgs empty",
in: &LoadAwareUtilizationArgs{},
want: &LoadAwareUtilizationArgs{
Thresholds: nil,
NumberOfNodes: 0,
},
},
{
name: "HighNodeUtilizationArgs with value",
in: &LoadAwareUtilizationArgs{
Thresholds: api.ResourceThresholds{
v1.ResourceCPU: 20,
v1.ResourceMemory: 120,
},
NumberOfNodes: 10,
},
want: &LoadAwareUtilizationArgs{
Thresholds: api.ResourceThresholds{
v1.ResourceCPU: 20,
v1.ResourceMemory: 120,
},
NumberOfNodes: 10,
},
},
}
for _, tc := range tests {
scheme := runtime.NewScheme()
utilruntime.Must(AddToScheme(scheme))
t.Run(tc.name, func(t *testing.T) {
scheme.Default(tc.in)
if diff := cmp.Diff(tc.in, tc.want); diff != "" {
t.Errorf("Got unexpected defaults (-want, +got):\n%s", diff)
}
})
}
}
Loading

0 comments on commit 62d0c5d

Please sign in to comment.