-
Notifications
You must be signed in to change notification settings - Fork 994
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: Monokaix <changxuzheng@huawei.com>
- Loading branch information
Showing
14 changed files
with
1,996 additions
and
0 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
71 changes: 71 additions & 0 deletions
71
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.
Oops, something went wrong.
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,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
127
pkg/descheduler/framework/plugins/loadaware/defaults_test.go
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,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) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.