@@ -126,12 +126,15 @@ var _ = Describe("Limitador controller", func() {
126
126
BeforeEach (func () {
127
127
limitadorObj = newLimitador ()
128
128
limitadorObj .Spec = limitadorv1alpha1.LimitadorSpec {}
129
- err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
130
- Expect (err == nil || errors .IsNotFound (err ))
131
129
132
130
Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
133
131
})
134
132
133
+ AfterEach (func () {
134
+ err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
135
+ Expect (err == nil || errors .IsNotFound (err ))
136
+ })
137
+
135
138
It ("Should create a Limitador service with default ports" , func () {
136
139
createdLimitadorService := v1.Service {}
137
140
Eventually (func () bool {
@@ -157,10 +160,12 @@ var _ = Describe("Limitador controller", func() {
157
160
158
161
BeforeEach (func () {
159
162
limitadorObj = newLimitador ()
163
+ Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
164
+ })
165
+
166
+ AfterEach (func () {
160
167
err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
161
168
Expect (err == nil || errors .IsNotFound (err ))
162
-
163
- Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
164
169
})
165
170
166
171
It ("Should create a new deployment with the right settings" , func () {
@@ -292,30 +297,18 @@ var _ = Describe("Limitador controller", func() {
292
297
293
298
BeforeEach (func () {
294
299
limitadorObj = newLimitador ()
300
+ Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
301
+ })
302
+
303
+ AfterEach (func () {
295
304
err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
296
305
Expect (err == nil || errors .IsNotFound (err ))
297
-
298
- Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
299
306
})
300
307
301
308
It ("Should modify the limitador deployment" , func () {
302
309
updatedLimitador := limitadorv1alpha1.Limitador {}
303
- Eventually (func () bool {
304
- err := k8sClient .Get (
305
- context .TODO (),
306
- types.NamespacedName {
307
- Namespace : LimitadorNamespace ,
308
- Name : limitadorObj .Name ,
309
- },
310
- & updatedLimitador )
311
-
312
- return err == nil
313
- }, timeout , interval ).Should (BeTrue ())
314
-
315
310
replicas = LimitadorReplicas + 1
316
- updatedLimitador .Spec .Replicas = & replicas
317
311
version = "latest"
318
- updatedLimitador .Spec .Version = & version
319
312
resourceRequirements := & v1.ResourceRequirements {
320
313
Requests : v1.ResourceList {
321
314
v1 .ResourceCPU : resource .MustParse ("200m" ),
@@ -326,11 +319,30 @@ var _ = Describe("Limitador controller", func() {
326
319
v1 .ResourceMemory : resource .MustParse ("60Mi" ),
327
320
},
328
321
}
329
- updatedLimitador .Spec .ResourceRequirements = resourceRequirements
330
- affinity .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].Weight = 99
331
- updatedLimitador .Spec .Affinity = affinity
332
322
333
- Expect (k8sClient .Update (context .TODO (), & updatedLimitador )).Should (Succeed ())
323
+ // Sometimes there can be a conflict due to stale resource if controller is still reconciling resource
324
+ // from create event
325
+ Eventually (func () bool {
326
+ err := k8sClient .Get (
327
+ context .TODO (),
328
+ types.NamespacedName {
329
+ Namespace : LimitadorNamespace ,
330
+ Name : limitadorObj .Name ,
331
+ },
332
+ & updatedLimitador )
333
+ if err != nil {
334
+ return false
335
+ }
336
+
337
+ updatedLimitador .Spec .Replicas = & replicas
338
+ updatedLimitador .Spec .Version = & version
339
+ updatedLimitador .Spec .ResourceRequirements = resourceRequirements
340
+ affinity .PodAntiAffinity .PreferredDuringSchedulingIgnoredDuringExecution [0 ].Weight = 99
341
+ updatedLimitador .Spec .Affinity = affinity
342
+
343
+ return k8sClient .Update (context .TODO (), & updatedLimitador ) == nil
344
+ }, timeout , interval ).Should (BeTrue ())
345
+
334
346
updatedLimitadorDeployment := appsv1.Deployment {}
335
347
Eventually (func () bool {
336
348
err := k8sClient .Get (
@@ -365,12 +377,15 @@ var _ = Describe("Limitador controller", func() {
365
377
},
366
378
& updatedLimitador )
367
379
368
- return err == nil
369
- }, timeout , interval ).Should (BeTrue ())
380
+ if err != nil {
381
+ return false
382
+ }
383
+ updatedLimitador .Spec .Affinity = nil
370
384
371
- updatedLimitador .Spec .Affinity = nil
385
+ return k8sClient .Update (context .TODO (), & updatedLimitador ) == nil
386
+
387
+ }, timeout , interval ).Should (BeTrue ())
372
388
373
- Expect (k8sClient .Update (context .TODO (), & updatedLimitador )).Should (Succeed ())
374
389
updatedLimitadorDeployment := appsv1.Deployment {}
375
390
Eventually (func () bool {
376
391
err := k8sClient .Get (
@@ -406,6 +421,15 @@ var _ = Describe("Limitador controller", func() {
406
421
}, timeout , interval ).Should (BeTrue ())
407
422
408
423
updatedLimitador := limitadorv1alpha1.Limitador {}
424
+ newLimits := []limitadorv1alpha1.RateLimit {
425
+ {
426
+ Conditions : []string {"req.method == GET" },
427
+ MaxValue : 100 ,
428
+ Namespace : "test-namespace" ,
429
+ Seconds : 60 ,
430
+ Variables : []string {"user_id" },
431
+ },
432
+ }
409
433
Eventually (func () bool {
410
434
err := k8sClient .Get (
411
435
context .TODO (),
@@ -415,20 +439,14 @@ var _ = Describe("Limitador controller", func() {
415
439
},
416
440
& updatedLimitador )
417
441
418
- return err == nil
419
- }, timeout , interval ).Should (BeTrue ())
442
+ updatedLimitador .Spec .Limits = newLimits
420
443
421
- newLimits := []limitadorv1alpha1.RateLimit {
422
- {
423
- Conditions : []string {"req.method == GET" },
424
- MaxValue : 100 ,
425
- Namespace : "test-namespace" ,
426
- Seconds : 60 ,
427
- Variables : []string {"user_id" },
428
- },
429
- }
430
- updatedLimitador .Spec .Limits = newLimits
431
- Expect (k8sClient .Update (context .TODO (), & updatedLimitador )).Should (Succeed ())
444
+ if err != nil {
445
+ return false
446
+ }
447
+
448
+ return k8sClient .Update (context .TODO (), & updatedLimitador ) == nil
449
+ }, timeout , interval ).Should (BeTrue ())
432
450
433
451
updatedLimitadorConfigMap := v1.ConfigMap {}
434
452
Eventually (func () bool {
@@ -465,6 +483,7 @@ var _ = Describe("Limitador controller", func() {
465
483
}, timeout , interval ).Should (BeTrue ())
466
484
467
485
updatedLimitador := limitadorv1alpha1.Limitador {}
486
+
468
487
Eventually (func () bool {
469
488
err := k8sClient .Get (
470
489
context .TODO (),
@@ -474,11 +493,13 @@ var _ = Describe("Limitador controller", func() {
474
493
},
475
494
& updatedLimitador )
476
495
477
- return err == nil
478
- }, timeout , interval ).Should (BeTrue ())
496
+ if err != nil {
497
+ return false
498
+ }
499
+ updatedLimitador .Spec .PodDisruptionBudget .MaxUnavailable = updatedMaxUnavailable
479
500
480
- updatedLimitador . Spec . PodDisruptionBudget . MaxUnavailable = updatedMaxUnavailable
481
- Expect ( k8sClient . Update ( context . TODO (), & updatedLimitador )) .Should (Succeed ())
501
+ return k8sClient . Update ( context . TODO (), & updatedLimitador ) == nil
502
+ }, timeout , interval ) .Should (BeTrue ())
482
503
483
504
updatedPdb := policyv1.PodDisruptionBudget {}
484
505
Eventually (func () bool {
@@ -503,12 +524,15 @@ var _ = Describe("Limitador controller", func() {
503
524
BeforeEach (func () {
504
525
limitadorObj = newLimitador ()
505
526
limitadorObj .Spec .RateLimitHeaders = & []limitadorv1alpha1.RateLimitHeadersType {"DRAFT_VERSION_03" }[0 ]
506
- err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
507
- Expect (err == nil || errors .IsNotFound (err ))
508
527
509
528
Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
510
529
})
511
530
531
+ AfterEach (func () {
532
+ err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
533
+ Expect (err == nil || errors .IsNotFound (err ))
534
+ })
535
+
512
536
It ("Should create a new deployment with rate limit headers command line arg" , func () {
513
537
createdLimitadorDeployment := appsv1.Deployment {}
514
538
Eventually (func () bool {
@@ -544,12 +568,15 @@ var _ = Describe("Limitador controller", func() {
544
568
545
569
BeforeEach (func () {
546
570
limitadorObj = newLimitador ()
547
- err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
548
- Expect (err == nil || errors .IsNotFound (err ))
549
571
550
572
Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
551
573
})
552
574
575
+ AfterEach (func () {
576
+ err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
577
+ Expect (err == nil || errors .IsNotFound (err ))
578
+ })
579
+
553
580
It ("Should modify the limitador deployment command line args" , func () {
554
581
updatedLimitador := limitadorv1alpha1.Limitador {}
555
582
Eventually (func () bool {
@@ -561,13 +588,17 @@ var _ = Describe("Limitador controller", func() {
561
588
},
562
589
& updatedLimitador )
563
590
564
- return err == nil
565
- }, timeout , interval ).Should (BeTrue ())
591
+ if err != nil {
592
+ return false
593
+ }
566
594
567
- Expect (updatedLimitador .Spec .RateLimitHeaders ).Should (BeNil ())
568
- updatedLimitador .Spec .RateLimitHeaders = & []limitadorv1alpha1.RateLimitHeadersType {"DRAFT_VERSION_03" }[0 ]
595
+ if updatedLimitador .Spec .RateLimitHeaders != nil {
596
+ return false
597
+ }
598
+ updatedLimitador .Spec .RateLimitHeaders = & []limitadorv1alpha1.RateLimitHeadersType {"DRAFT_VERSION_03" }[0 ]
599
+ return k8sClient .Update (context .TODO (), & updatedLimitador ) == nil
600
+ }, timeout , interval ).Should (BeTrue ())
569
601
570
- Expect (k8sClient .Update (context .TODO (), & updatedLimitador )).Should (Succeed ())
571
602
Eventually (func () bool {
572
603
updatedLimitadorDeployment := appsv1.Deployment {}
573
604
err := k8sClient .Get (
@@ -599,10 +630,12 @@ var _ = Describe("Limitador controller", func() {
599
630
600
631
BeforeEach (func () {
601
632
limitadorObj = newLimitador ()
633
+ Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
634
+ })
635
+
636
+ AfterEach (func () {
602
637
err := k8sClient .Delete (context .TODO (), limitadorObj , deletePropagationPolicy )
603
638
Expect (err == nil || errors .IsNotFound (err ))
604
-
605
- Expect (k8sClient .Create (context .TODO (), limitadorObj )).Should (Succeed ())
606
639
})
607
640
608
641
It ("User tries adding side-cars to deployment CR" , func () {
0 commit comments