@@ -23,6 +23,7 @@ import (
23
23
corev1 "k8s.io/api/core/v1"
24
24
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
25
"k8s.io/client-go/tools/record"
26
+ "k8s.io/utils/ptr"
26
27
"sigs.k8s.io/controller-runtime/pkg/client"
27
28
"sigs.k8s.io/controller-runtime/pkg/client/fake"
28
29
@@ -44,6 +45,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
44
45
Spec : corev1.NodeSpec {
45
46
ProviderID : "aws://us-east-1/id-node-1" ,
46
47
},
48
+ Status : corev1.NodeStatus {
49
+ Conditions : []corev1.NodeCondition {
50
+ {
51
+ Type : corev1 .NodeReady ,
52
+ Status : corev1 .ConditionTrue ,
53
+ },
54
+ },
55
+ },
47
56
},
48
57
& corev1.Node {
49
58
ObjectMeta : metav1.ObjectMeta {
@@ -52,6 +61,22 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
52
61
Spec : corev1.NodeSpec {
53
62
ProviderID : "aws://us-west-2/id-node-2" ,
54
63
},
64
+ Status : corev1.NodeStatus {
65
+ Conditions : []corev1.NodeCondition {
66
+ {
67
+ Type : corev1 .NodeReady ,
68
+ Status : corev1 .ConditionTrue ,
69
+ },
70
+ },
71
+ },
72
+ },
73
+ & corev1.Node {
74
+ ObjectMeta : metav1.ObjectMeta {
75
+ Name : "node-3" ,
76
+ },
77
+ Spec : corev1.NodeSpec {
78
+ ProviderID : "aws://us-west-2/id-node-3" ,
79
+ },
55
80
},
56
81
& corev1.Node {
57
82
ObjectMeta : metav1.ObjectMeta {
@@ -60,6 +85,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
60
85
Spec : corev1.NodeSpec {
61
86
ProviderID : "gce://us-central1/gce-id-node-2" ,
62
87
},
88
+ Status : corev1.NodeStatus {
89
+ Conditions : []corev1.NodeCondition {
90
+ {
91
+ Type : corev1 .NodeReady ,
92
+ Status : corev1 .ConditionTrue ,
93
+ },
94
+ },
95
+ },
63
96
},
64
97
& corev1.Node {
65
98
ObjectMeta : metav1.ObjectMeta {
@@ -68,6 +101,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
68
101
Spec : corev1.NodeSpec {
69
102
ProviderID : "azure://westus2/id-node-4" ,
70
103
},
104
+ Status : corev1.NodeStatus {
105
+ Conditions : []corev1.NodeCondition {
106
+ {
107
+ Type : corev1 .NodeReady ,
108
+ Status : corev1 .ConditionTrue ,
109
+ },
110
+ },
111
+ },
71
112
},
72
113
& corev1.Node {
73
114
ObjectMeta : metav1.ObjectMeta {
@@ -76,6 +117,14 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
76
117
Spec : corev1.NodeSpec {
77
118
ProviderID : "azure://westus2/id-nodepool1/0" ,
78
119
},
120
+ Status : corev1.NodeStatus {
121
+ Conditions : []corev1.NodeCondition {
122
+ {
123
+ Type : corev1 .NodeReady ,
124
+ Status : corev1 .ConditionTrue ,
125
+ },
126
+ },
127
+ },
79
128
},
80
129
& corev1.Node {
81
130
ObjectMeta : metav1.ObjectMeta {
@@ -84,16 +133,25 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
84
133
Spec : corev1.NodeSpec {
85
134
ProviderID : "azure://westus2/id-nodepool2/0" ,
86
135
},
136
+ Status : corev1.NodeStatus {
137
+ Conditions : []corev1.NodeCondition {
138
+ {
139
+ Type : corev1 .NodeReady ,
140
+ Status : corev1 .ConditionTrue ,
141
+ },
142
+ },
143
+ },
87
144
},
88
145
}
89
146
90
147
client := fake .NewClientBuilder ().WithObjects (nodeList ... ).Build ()
91
148
92
149
testCases := []struct {
93
- name string
94
- providerIDList []string
95
- expected * getNodeReferencesResult
96
- err error
150
+ name string
151
+ providerIDList []string
152
+ expected * getNodeReferencesResult
153
+ err error
154
+ minReadySeconds int32
97
155
}{
98
156
{
99
157
name : "valid provider id, valid aws node" ,
@@ -102,6 +160,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
102
160
references : []corev1.ObjectReference {
103
161
{Name : "node-1" },
104
162
},
163
+ available : 1 ,
164
+ ready : 1 ,
105
165
},
106
166
},
107
167
{
@@ -111,6 +171,19 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
111
171
references : []corev1.ObjectReference {
112
172
{Name : "node-2" },
113
173
},
174
+ available : 1 ,
175
+ ready : 1 ,
176
+ },
177
+ },
178
+ {
179
+ name : "valid provider id, valid aws node, nodeReady condition set to false" ,
180
+ providerIDList : []string {"aws://us-west-2/id-node-3" },
181
+ expected : & getNodeReferencesResult {
182
+ references : []corev1.ObjectReference {
183
+ {Name : "node-3" },
184
+ },
185
+ available : 0 ,
186
+ ready : 0 ,
114
187
},
115
188
},
116
189
{
@@ -120,6 +193,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
120
193
references : []corev1.ObjectReference {
121
194
{Name : "gce-node-2" },
122
195
},
196
+ available : 1 ,
197
+ ready : 1 ,
123
198
},
124
199
},
125
200
{
@@ -129,6 +204,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
129
204
references : []corev1.ObjectReference {
130
205
{Name : "azure-node-4" },
131
206
},
207
+ available : 1 ,
208
+ ready : 1 ,
132
209
},
133
210
},
134
211
{
@@ -139,6 +216,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
139
216
{Name : "node-1" },
140
217
{Name : "azure-node-4" },
141
218
},
219
+ available : 2 ,
220
+ ready : 2 ,
142
221
},
143
222
},
144
223
{
@@ -163,6 +242,8 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
163
242
references : []corev1.ObjectReference {
164
243
{Name : "azure-nodepool1-0" },
165
244
},
245
+ available : 1 ,
246
+ ready : 1 ,
166
247
},
167
248
},
168
249
{
@@ -173,15 +254,37 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
173
254
{Name : "azure-nodepool1-0" },
174
255
{Name : "azure-nodepool2-0" },
175
256
},
257
+ available : 2 ,
258
+ ready : 2 ,
176
259
},
177
260
},
261
+ {
262
+ name : "valid provider id, valid aws node, with minReadySeconds" ,
263
+ providerIDList : []string {"aws://us-east-1/id-node-1" },
264
+ expected : & getNodeReferencesResult {
265
+ references : []corev1.ObjectReference {{Name : "node-1" }},
266
+ available : 0 ,
267
+ ready : 1 ,
268
+ },
269
+ minReadySeconds : 20 ,
270
+ },
271
+ {
272
+ name : "valid provider id, valid aws node, with minReadySeconds equals 0" ,
273
+ providerIDList : []string {"aws://us-east-1/id-node-1" },
274
+ expected : & getNodeReferencesResult {
275
+ references : []corev1.ObjectReference {{Name : "node-1" }},
276
+ available : 1 ,
277
+ ready : 1 ,
278
+ },
279
+ minReadySeconds : 0 ,
280
+ },
178
281
}
179
282
180
283
for _ , test := range testCases {
181
284
t .Run (test .name , func (t * testing.T ) {
182
285
g := NewWithT (t )
183
286
184
- result , err := r .getNodeReferences (ctx , client , test .providerIDList )
287
+ result , err := r .getNodeReferences (ctx , client , test .providerIDList , ptr . To ( test . minReadySeconds ) )
185
288
if test .err == nil {
186
289
g .Expect (err ).ToNot (HaveOccurred ())
187
290
} else {
@@ -195,6 +298,9 @@ func TestMachinePoolGetNodeReference(t *testing.T) {
195
298
196
299
g .Expect (result .references ).To (HaveLen (len (test .expected .references )), "Expected NodeRef count to be %v, got %v" , len (result .references ), len (test .expected .references ))
197
300
301
+ g .Expect (result .available ).To (Equal (test .expected .available ), "Expected available node count to be %v, got %v" , test .expected .available , result .available )
302
+ g .Expect (result .ready ).To (Equal (test .expected .ready ), "Expected ready node count to be %v, got %v" , test .expected .ready , result .ready )
303
+
198
304
for n := range test .expected .references {
199
305
g .Expect (result .references [n ].Name ).To (Equal (test .expected .references [n ].Name ), "Expected NodeRef's name to be %v, got %v" , result .references [n ].Name , test .expected .references [n ].Name )
200
306
g .Expect (result .references [n ].Namespace ).To (Equal (test .expected .references [n ].Namespace ), "Expected NodeRef's namespace to be %v, got %v" , result .references [n ].Namespace , test .expected .references [n ].Namespace )
0 commit comments