@@ -35,6 +35,7 @@ import (
3535 coretesting "k8s.io/client-go/testing"
3636 "k8s.io/client-go/tools/events"
3737
38+ "github.com/koordinator-sh/koordinator/apis/extension"
3839 slov1alpha1 "github.com/koordinator-sh/koordinator/apis/slo/v1alpha1"
3940 koordinatorclientset "github.com/koordinator-sh/koordinator/pkg/client/clientset/versioned"
4041 koordfake "github.com/koordinator-sh/koordinator/pkg/client/clientset/versioned/fake"
@@ -1643,6 +1644,9 @@ func TestOverUtilizedEvictionReason(t *testing.T) {
16431644 node : & corev1.Node {
16441645 ObjectMeta : metav1.ObjectMeta {
16451646 Name : "test-node" ,
1647+ Annotations : map [string ]string {
1648+ extension .AnnotationNodeRawAllocatable : `{"cpu":96,"memory":"512Gi"}` ,
1649+ },
16461650 },
16471651 Status : corev1.NodeStatus {
16481652 Allocatable : corev1.ResourceList {
@@ -1666,6 +1670,9 @@ func TestOverUtilizedEvictionReason(t *testing.T) {
16661670 node : & corev1.Node {
16671671 ObjectMeta : metav1.ObjectMeta {
16681672 Name : "test-node" ,
1673+ Annotations : map [string ]string {
1674+ extension .AnnotationNodeRawAllocatable : `{"cpu":96,"memory":"512Gi"}` ,
1675+ },
16691676 },
16701677 Status : corev1.NodeStatus {
16711678 Allocatable : corev1.ResourceList {
@@ -1694,6 +1701,9 @@ func TestOverUtilizedEvictionReason(t *testing.T) {
16941701 node : & corev1.Node {
16951702 ObjectMeta : metav1.ObjectMeta {
16961703 Name : "test-node" ,
1704+ Annotations : map [string ]string {
1705+ extension .AnnotationNodeRawAllocatable : `{"cpu":96,"memory":"512Gi"}` ,
1706+ },
16971707 },
16981708 Status : corev1.NodeStatus {
16991709 Allocatable : corev1.ResourceList {
@@ -1726,6 +1736,9 @@ func TestOverUtilizedEvictionReason(t *testing.T) {
17261736 node : & corev1.Node {
17271737 ObjectMeta : metav1.ObjectMeta {
17281738 Name : "test-node" ,
1739+ Annotations : map [string ]string {
1740+ extension .AnnotationNodeRawAllocatable : `{"cpu":96,"memory":"512Gi"}` ,
1741+ },
17291742 },
17301743 Status : corev1.NodeStatus {
17311744 Allocatable : corev1.ResourceList {
@@ -1998,3 +2011,78 @@ func Test_filterRealAbnormalNodes(t *testing.T) {
19982011 })
19992012 }
20002013}
2014+
2015+ func Test_GetNodeRawAllocatableForDescheduler (t * testing.T ) {
2016+ tests := []struct {
2017+ name string
2018+ node * corev1.Node
2019+ want corev1.ResourceList
2020+ }{
2021+ {
2022+ name : "node has no annotation - use allocatable" ,
2023+ node : & corev1.Node {
2024+ ObjectMeta : metav1.ObjectMeta {
2025+ Name : "test-node" ,
2026+ },
2027+ Status : corev1.NodeStatus {
2028+ Allocatable : corev1.ResourceList {
2029+ corev1 .ResourceCPU : resource .MustParse ("16" ),
2030+ corev1 .ResourceMemory : resource .MustParse ("32Gi" ),
2031+ },
2032+ },
2033+ },
2034+ want : corev1.ResourceList {
2035+ corev1 .ResourceCPU : resource .MustParse ("16" ),
2036+ corev1 .ResourceMemory : resource .MustParse ("32Gi" ),
2037+ },
2038+ },
2039+ {
2040+ name : "node has valid raw allocatable annotation - use raw allocatable" ,
2041+ node : & corev1.Node {
2042+ ObjectMeta : metav1.ObjectMeta {
2043+ Name : "test-node" ,
2044+ Annotations : map [string ]string {
2045+ extension .AnnotationNodeRawAllocatable : `{"cpu":"8","memory":"16Gi"}` ,
2046+ },
2047+ },
2048+ Status : corev1.NodeStatus {
2049+ Allocatable : corev1.ResourceList {
2050+ corev1 .ResourceCPU : resource .MustParse ("32" ),
2051+ corev1 .ResourceMemory : resource .MustParse ("64Gi" ),
2052+ },
2053+ },
2054+ },
2055+ want : corev1.ResourceList {
2056+ corev1 .ResourceCPU : resource .MustParse ("8" ),
2057+ corev1 .ResourceMemory : resource .MustParse ("16Gi" ),
2058+ },
2059+ },
2060+ {
2061+ name : "node has invalid raw allocatable annotation - fallback to allocatable" ,
2062+ node : & corev1.Node {
2063+ ObjectMeta : metav1.ObjectMeta {
2064+ Name : "test-node" ,
2065+ Annotations : map [string ]string {
2066+ extension .AnnotationNodeRawAllocatable : "invalid" ,
2067+ },
2068+ },
2069+ Status : corev1.NodeStatus {
2070+ Allocatable : corev1.ResourceList {
2071+ corev1 .ResourceCPU : resource .MustParse ("16" ),
2072+ corev1 .ResourceMemory : resource .MustParse ("32Gi" ),
2073+ },
2074+ },
2075+ },
2076+ want : corev1.ResourceList {
2077+ corev1 .ResourceCPU : resource .MustParse ("16" ),
2078+ corev1 .ResourceMemory : resource .MustParse ("32Gi" ),
2079+ },
2080+ },
2081+ }
2082+ for _ , tt := range tests {
2083+ t .Run (tt .name , func (t * testing.T ) {
2084+ got := GetNodeRawAllocatableFromNode (tt .node )
2085+ assert .Equal (t , tt .want , got )
2086+ })
2087+ }
2088+ }
0 commit comments