@@ -553,24 +553,23 @@ var _ = Describe("ValidateDelete", func() {
553
553
})
554
554
})
555
555
556
- var _ = Describe ("validateModuleTolerarations " , func () {
556
+ var _ = Describe ("validateTolerations " , func () {
557
557
It ("should fail when Module has an invalid toleration effect" , func () {
558
- mod := validModule
559
- mod .Spec .Tolerations = []v1.Toleration {
558
+ tolerations := []v1.Toleration {
560
559
{
561
560
Key : "Test-Key1" , Operator : v1 .TolerationOpEqual , Value : "Test-Value1" , Effect : v1 .TaintEffectPreferNoSchedule ,
562
561
},
563
562
{
564
- Key : "Test-Key2" , Operator : v1 .TolerationOpExists , Value : "Test-Value2" , Effect : "Invalid-Effect" ,
563
+ Key : "Test-Key2" , Operator : v1 .TolerationOpExists , Effect : "Invalid-Effect" ,
565
564
},
566
565
}
567
566
568
- err := validateModuleTolerations ( & mod )
567
+ err := validateTolerations ( tolerations )
569
568
Expect (err ).To (HaveOccurred ())
570
569
})
570
+
571
571
It ("should fail when Module has an invalid toleration operator" , func () {
572
- mod := validModule
573
- mod .Spec .Tolerations = []v1.Toleration {
572
+ tolerations := []v1.Toleration {
574
573
{
575
574
Key : "Test-Key1" , Operator : v1 .TolerationOpEqual , Value : "Test-Value1" , Effect : v1 .TaintEffectPreferNoSchedule ,
576
575
},
@@ -579,14 +578,28 @@ var _ = Describe("validateModuleTolerarations", func() {
579
578
},
580
579
}
581
580
582
- err := validateModuleTolerations ( & mod )
581
+ err := validateTolerations ( tolerations )
583
582
Expect (err ).To (HaveOccurred ())
584
583
})
585
- It ("should work when all tolerations have valid effects " , func () {
586
- mod := validModule
587
- mod .Spec .Tolerations = []v1.Toleration {
584
+
585
+ It ("should fail when toleration has non empty value and Exists operator" , func () {
586
+ tolerations := []v1.Toleration {
587
+ {
588
+ Key : "Test-Key1" , Operator : v1 .TolerationOpEqual , Value : "Test-Value1" , Effect : v1 .TaintEffectPreferNoSchedule ,
589
+ },
590
+ {
591
+ Key : "Test-Key2" , Operator : v1 .TolerationOpExists , Value : "Test-Value2" , Effect : v1 .TaintEffectNoExecute ,
592
+ },
593
+ }
594
+
595
+ err := validateTolerations (tolerations )
596
+ Expect (err ).To (HaveOccurred ())
597
+ })
598
+
599
+ It ("should work when all tolerations have valid effects" , func () {
600
+ tolerations := []v1.Toleration {
588
601
{
589
- Key : "Test-Key1" , Operator : v1 .TolerationOpExists , Value : "Test-Value" , Effect : v1 .TaintEffectPreferNoSchedule ,
602
+ Key : "Test-Key1" , Operator : v1 .TolerationOpExists , Effect : v1 .TaintEffectPreferNoSchedule ,
590
603
},
591
604
{
592
605
Key : "Test-Key2" , Operator : v1 .TolerationOpEqual , Value : "Test-Value" , Effect : v1 .TaintEffectNoSchedule ,
@@ -596,8 +609,82 @@ var _ = Describe("validateModuleTolerarations", func() {
596
609
},
597
610
}
598
611
599
- err := validateModuleTolerations (& mod )
600
- Expect (err ).ToNot (HaveOccurred ())
612
+ err := validateTolerations (tolerations )
613
+ Expect (err ).To (Not (HaveOccurred ()))
614
+ })
615
+
616
+ It ("should fail when toleration has an invalid key format" , func () {
617
+ tolerations := []v1.Toleration {
618
+ {
619
+ Key : "Invalid Key!" , Operator : v1 .TolerationOpEqual , Value : "Test-Value" ,
620
+ },
621
+ }
622
+
623
+ err := validateTolerations (tolerations )
624
+ Expect (err ).To (HaveOccurred ())
625
+ })
626
+
627
+ It ("should fail when toleration has empty key with an invalid operator" , func () {
628
+ tolerations := []v1.Toleration {
629
+ {
630
+ Key : "" , Operator : v1 .TolerationOpEqual , Value : "Test-Value" ,
631
+ },
632
+ }
633
+
634
+ err := validateTolerations (tolerations )
635
+ Expect (err ).To (HaveOccurred ())
601
636
})
602
637
638
+ It ("should fail when TolerationSeconds is set but Effect is not NoExecute" , func () {
639
+ tolSecs := int64 (30 )
640
+ tolerations := []v1.Toleration {
641
+ {
642
+ Key : "Test-Key" , Operator : v1 .TolerationOpEqual , Value : "Test-Value" , Effect : v1 .TaintEffectNoSchedule , TolerationSeconds : & tolSecs ,
643
+ },
644
+ }
645
+
646
+ err := validateTolerations (tolerations )
647
+ Expect (err ).To (HaveOccurred ())
648
+ })
649
+
650
+ It ("should pass when TolerationSeconds is set with NoExecute effect" , func () {
651
+ tolSecs := int64 (60 )
652
+ tolerations := []v1.Toleration {
653
+ {
654
+ Key : "Test-Key" , Operator : v1 .TolerationOpEqual , Value : "Test-Value" , Effect : v1 .TaintEffectNoExecute , TolerationSeconds : & tolSecs ,
655
+ },
656
+ }
657
+
658
+ err := validateTolerations (tolerations )
659
+ Expect (err ).To (Not (HaveOccurred ()))
660
+ })
661
+
662
+ It ("should fail when an invalid effect is provided" , func () {
663
+ tolerations := []v1.Toleration {
664
+ {
665
+ Key : "Test-Key" , Operator : v1 .TolerationOpExists , Effect : "Invalid-Effect" ,
666
+ },
667
+ }
668
+
669
+ err := validateTolerations (tolerations )
670
+ Expect (err ).To (HaveOccurred ())
671
+ })
672
+
673
+ It ("should fail when operator is not Equal or Exists" , func () {
674
+ tolerations := []v1.Toleration {
675
+ {
676
+ Key : "Test-Key" , Operator : "InvalidOperator" , Value : "Test-Value" ,
677
+ },
678
+ }
679
+
680
+ err := validateTolerations (tolerations )
681
+ Expect (err ).To (HaveOccurred ())
682
+ })
683
+
684
+ It ("should pass with an empty toleration list" , func () {
685
+ var tolerations []v1.Toleration
686
+
687
+ err := validateTolerations (tolerations )
688
+ Expect (err ).To (Not (HaveOccurred ()))
689
+ })
603
690
})
0 commit comments