@@ -29,22 +29,22 @@ import (
29
29
"github.com/stretchr/testify/assert"
30
30
)
31
31
32
- func checkNodesSimilar (t * testing.T , n1 , n2 * apiv1.Node , shouldEqual bool ) {
33
- checkNodesSimilarWithPods (t , n1 , n2 , []* apiv1.Pod {}, []* apiv1.Pod {}, shouldEqual )
32
+ func checkNodesSimilar (t * testing.T , n1 , n2 * apiv1.Node , comparator NodeInfoComparator , shouldEqual bool ) {
33
+ checkNodesSimilarWithPods (t , n1 , n2 , []* apiv1.Pod {}, []* apiv1.Pod {}, comparator , shouldEqual )
34
34
}
35
35
36
- func checkNodesSimilarWithPods (t * testing.T , n1 , n2 * apiv1.Node , pods1 , pods2 []* apiv1.Pod , shouldEqual bool ) {
36
+ func checkNodesSimilarWithPods (t * testing.T , n1 , n2 * apiv1.Node , pods1 , pods2 []* apiv1.Pod , comparator NodeInfoComparator , shouldEqual bool ) {
37
37
ni1 := schedulercache .NewNodeInfo (pods1 ... )
38
38
ni1 .SetNode (n1 )
39
39
ni2 := schedulercache .NewNodeInfo (pods2 ... )
40
40
ni2 .SetNode (n2 )
41
- assert .Equal (t , shouldEqual , IsNodeInfoSimilar (ni1 , ni2 ))
41
+ assert .Equal (t , shouldEqual , comparator (ni1 , ni2 ))
42
42
}
43
43
44
44
func TestIdenticalNodesSimilar (t * testing.T ) {
45
45
n1 := BuildTestNode ("node1" , 1000 , 2000 )
46
46
n2 := BuildTestNode ("node2" , 1000 , 2000 )
47
- checkNodesSimilar (t , n1 , n2 , true )
47
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , true )
48
48
}
49
49
50
50
func TestNodesSimilarVariousRequirements (t * testing.T ) {
@@ -53,23 +53,23 @@ func TestNodesSimilarVariousRequirements(t *testing.T) {
53
53
// Different CPU capacity
54
54
n2 := BuildTestNode ("node2" , 1000 , 2000 )
55
55
n2 .Status .Capacity [apiv1 .ResourceCPU ] = * resource .NewMilliQuantity (1001 , resource .DecimalSI )
56
- checkNodesSimilar (t , n1 , n2 , false )
56
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , false )
57
57
58
58
// Same CPU capacity, but slightly different allocatable
59
59
n3 := BuildTestNode ("node3" , 1000 , 2000 )
60
60
n3 .Status .Allocatable [apiv1 .ResourceCPU ] = * resource .NewMilliQuantity (999 , resource .DecimalSI )
61
- checkNodesSimilar (t , n1 , n3 , true )
61
+ checkNodesSimilar (t , n1 , n3 , IsNodeInfoSimilar , true )
62
62
63
63
// Same CPU capacity, significantly different allocatable
64
64
n4 := BuildTestNode ("node4" , 1000 , 2000 )
65
65
n4 .Status .Allocatable [apiv1 .ResourceCPU ] = * resource .NewMilliQuantity (500 , resource .DecimalSI )
66
- checkNodesSimilar (t , n1 , n4 , false )
66
+ checkNodesSimilar (t , n1 , n4 , IsNodeInfoSimilar , false )
67
67
68
68
// One with GPU, one without
69
69
n5 := BuildTestNode ("node5" , 1000 , 2000 )
70
70
n5 .Status .Capacity [gpu .ResourceNvidiaGPU ] = * resource .NewQuantity (1 , resource .DecimalSI )
71
71
n5 .Status .Allocatable [gpu .ResourceNvidiaGPU ] = n5 .Status .Capacity [gpu .ResourceNvidiaGPU ]
72
- checkNodesSimilar (t , n1 , n5 , false )
72
+ checkNodesSimilar (t , n1 , n5 , IsNodeInfoSimilar , false )
73
73
}
74
74
75
75
func TestNodesSimilarVariousRequirementsAndPods (t * testing.T ) {
@@ -81,20 +81,20 @@ func TestNodesSimilarVariousRequirementsAndPods(t *testing.T) {
81
81
n2 := BuildTestNode ("node2" , 1000 , 2000 )
82
82
n2 .Status .Allocatable [apiv1 .ResourceCPU ] = * resource .NewMilliQuantity (500 , resource .DecimalSI )
83
83
n2 .Status .Allocatable [apiv1 .ResourceMemory ] = * resource .NewQuantity (1000 , resource .DecimalSI )
84
- checkNodesSimilarWithPods (t , n1 , n2 , []* apiv1.Pod {p1 }, []* apiv1.Pod {}, false )
84
+ checkNodesSimilarWithPods (t , n1 , n2 , []* apiv1.Pod {p1 }, []* apiv1.Pod {}, IsNodeInfoSimilar , false )
85
85
86
86
// Same requests of pods
87
87
n3 := BuildTestNode ("node3" , 1000 , 2000 )
88
88
p3 := BuildTestPod ("pod3" , 500 , 1000 )
89
89
p3 .Spec .NodeName = "node3"
90
- checkNodesSimilarWithPods (t , n1 , n3 , []* apiv1.Pod {p1 }, []* apiv1.Pod {p3 }, true )
90
+ checkNodesSimilarWithPods (t , n1 , n3 , []* apiv1.Pod {p1 }, []* apiv1.Pod {p3 }, IsNodeInfoSimilar , true )
91
91
92
92
// Similar allocatable, similar pods
93
93
n4 := BuildTestNode ("node4" , 1000 , 2000 )
94
94
n4 .Status .Allocatable [apiv1 .ResourceCPU ] = * resource .NewMilliQuantity (999 , resource .DecimalSI )
95
95
p4 := BuildTestPod ("pod4" , 501 , 1001 )
96
96
p4 .Spec .NodeName = "node4"
97
- checkNodesSimilarWithPods (t , n1 , n4 , []* apiv1.Pod {p1 }, []* apiv1.Pod {p4 }, true )
97
+ checkNodesSimilarWithPods (t , n1 , n4 , []* apiv1.Pod {p1 }, []* apiv1.Pod {p4 }, IsNodeInfoSimilar , true )
98
98
}
99
99
100
100
func TestNodesSimilarVariousLabels (t * testing.T ) {
@@ -106,27 +106,27 @@ func TestNodesSimilarVariousLabels(t *testing.T) {
106
106
n2 .ObjectMeta .Labels ["test-label" ] = "test-value"
107
107
108
108
// Missing character label
109
- checkNodesSimilar (t , n1 , n2 , false )
109
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , false )
110
110
111
111
n2 .ObjectMeta .Labels ["character" ] = "winnie the pooh"
112
- checkNodesSimilar (t , n1 , n2 , true )
112
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , true )
113
113
114
114
// Different hostname labels shouldn't matter
115
115
n1 .ObjectMeta .Labels [kubeletapis .LabelHostname ] = "node1"
116
116
n2 .ObjectMeta .Labels [kubeletapis .LabelHostname ] = "node2"
117
- checkNodesSimilar (t , n1 , n2 , true )
117
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , true )
118
118
119
119
// Different zone shouldn't matter either
120
120
n1 .ObjectMeta .Labels [kubeletapis .LabelZoneFailureDomain ] = "mars-olympus-mons1-b"
121
121
n2 .ObjectMeta .Labels [kubeletapis .LabelZoneFailureDomain ] = "us-houston1-a"
122
- checkNodesSimilar (t , n1 , n2 , true )
122
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , true )
123
123
124
124
// Different beta.kubernetes.io/fluentd-ds-ready should not matter
125
125
n1 .ObjectMeta .Labels ["beta.kubernetes.io/fluentd-ds-ready" ] = "true"
126
126
n2 .ObjectMeta .Labels ["beta.kubernetes.io/fluentd-ds-ready" ] = "false"
127
- checkNodesSimilar (t , n1 , n2 , true )
127
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , true )
128
128
129
129
n1 .ObjectMeta .Labels ["beta.kubernetes.io/fluentd-ds-ready" ] = "true"
130
130
delete (n2 .ObjectMeta .Labels , "beta.kubernetes.io/fluentd-ds-ready" )
131
- checkNodesSimilar (t , n1 , n2 , true )
131
+ checkNodesSimilar (t , n1 , n2 , IsNodeInfoSimilar , true )
132
132
}
0 commit comments