@@ -19,6 +19,7 @@ package clusterapi
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "reflect"
22
23
"testing"
23
24
"time"
24
25
@@ -222,6 +223,65 @@ func TestReplicas(t *testing.T) {
222
223
})
223
224
}
224
225
226
+ func TestTaints (t * testing.T ) {
227
+ initialReplicas := 1
228
+
229
+ expectedTaints := []v1.Taint {
230
+ {Key : "test" , Effect : v1 .TaintEffectNoSchedule , Value : "test" },
231
+ {Key : "test-no-value" , Effect : v1 .TaintEffectNoSchedule },
232
+ }
233
+ expectedTaintsWithAnnotations := []v1.Taint {
234
+ {Key : "test" , Effect : v1 .TaintEffectNoSchedule , Value : "test" },
235
+ {Key : "test-no-value" , Effect : v1 .TaintEffectNoSchedule },
236
+ {Key : "key1" , Effect : v1 .TaintEffectNoSchedule , Value : "value1" },
237
+ {Key : "key2" , Effect : v1 .TaintEffectNoExecute , Value : "value2" },
238
+ }
239
+ taintAnnotation := "key1=value1:NoSchedule,key2=value2:NoExecute"
240
+
241
+ test := func (t * testing.T , testConfig * testConfig ) {
242
+ controller , stop := mustCreateTestController (t , testConfig )
243
+ defer stop ()
244
+
245
+ testResource := testConfig .machineSet
246
+ if testConfig .machineDeployment != nil {
247
+ testResource = testConfig .machineDeployment
248
+ }
249
+
250
+ sr , err := newUnstructuredScalableResource (controller , testResource )
251
+ if err != nil {
252
+ t .Fatal (err )
253
+ }
254
+
255
+ taints := sr .Taints ()
256
+
257
+ if ! reflect .DeepEqual (taints , expectedTaints ) {
258
+ t .Errorf ("expected %v, got: %v" , expectedTaints , taints )
259
+ }
260
+
261
+ srAnnotations := sr .unstructured .GetAnnotations ()
262
+ if srAnnotations == nil {
263
+ srAnnotations = make (map [string ]string )
264
+ }
265
+
266
+ srAnnotations [taintsKey ] = taintAnnotation
267
+ sr .unstructured .SetAnnotations (srAnnotations )
268
+
269
+ taints = sr .Taints ()
270
+
271
+ if ! reflect .DeepEqual (taints , expectedTaintsWithAnnotations ) {
272
+ t .Errorf ("expected %v, got: %v" , expectedTaintsWithAnnotations , taints )
273
+ }
274
+ }
275
+
276
+ t .Run ("MachineSet" , func (t * testing.T ) {
277
+ test (t , createMachineSetTestConfig (RandomString (6 ), RandomString (6 ), RandomString (6 ), initialReplicas , nil , nil ))
278
+ })
279
+
280
+ t .Run ("MachineDeployment" , func (t * testing.T ) {
281
+ test (t , createMachineDeploymentTestConfig (RandomString (6 ), RandomString (6 ), RandomString (6 ), initialReplicas , nil , nil ))
282
+ })
283
+ }
284
+
225
285
func TestSetSizeAndReplicas (t * testing.T ) {
226
286
initialReplicas := 1
227
287
updatedReplicas := 5
@@ -297,7 +357,15 @@ func TestAnnotations(t *testing.T) {
297
357
memQuantity := resource .MustParse ("1024" )
298
358
gpuQuantity := resource .MustParse ("1" )
299
359
maxPodsQuantity := resource .MustParse ("42" )
300
- expectedTaints := []v1.Taint {{Key : "key1" , Effect : v1 .TaintEffectNoSchedule , Value : "value1" }, {Key : "key2" , Effect : v1 .TaintEffectNoExecute , Value : "value2" }}
360
+
361
+ // Note, the first two taints comes from the spec of the machine template, the rest from the annotations.
362
+ expectedTaints := []v1.Taint {
363
+ {Key : "test" , Effect : v1 .TaintEffectNoSchedule , Value : "test" },
364
+ {Key : "test-no-value" , Effect : v1 .TaintEffectNoSchedule },
365
+ {Key : "key1" , Effect : v1 .TaintEffectNoSchedule , Value : "value1" },
366
+ {Key : "key2" , Effect : v1 .TaintEffectNoExecute , Value : "value2" },
367
+ }
368
+
301
369
annotations := map [string ]string {
302
370
cpuKey : cpuQuantity .String (),
303
371
memoryKey : memQuantity .String (),
0 commit comments