@@ -112,7 +112,7 @@ func startDummyHTTPServer(handle http.HandlerFunc, listenAddr string) (cancelFn
112
112
return func () { _ = srv .Shutdown (context .Background ()) }
113
113
}
114
114
115
- func createNodeDisruption (name string , namespace string , nodeSelectorLabel map [string ]string , ctx context.Context ) {
115
+ func createNodeDisruption (name string , namespace string , nodeSelectorLabel map [string ]string , disruptionType string , ctx context.Context ) {
116
116
overlappingDisruption := & nodedisruptionv1alpha1.NodeDisruption {
117
117
TypeMeta : metav1.TypeMeta {
118
118
APIVersion : "nodedisruption.criteo.com/v1alpha1" ,
@@ -124,6 +124,7 @@ func createNodeDisruption(name string, namespace string, nodeSelectorLabel map[s
124
124
},
125
125
Spec : nodedisruptionv1alpha1.NodeDisruptionSpec {
126
126
NodeSelector : metav1.LabelSelector {MatchLabels : nodeSelectorLabel },
127
+ Type : disruptionType ,
127
128
},
128
129
}
129
130
Expect (k8sClient .Create (ctx , overlappingDisruption .DeepCopy ())).Should (Succeed ())
@@ -644,7 +645,7 @@ var _ = Describe("NodeDisruption controller", func() {
644
645
645
646
BeforeEach (func () {
646
647
By ("configuring a first disruption" )
647
- createNodeDisruption (firstDisruptionName , NDNamespace , nodeLabels1 , ctx )
648
+ createNodeDisruption (firstDisruptionName , NDNamespace , nodeLabels1 , "" , ctx )
648
649
})
649
650
AfterEach (func () {
650
651
clearAllNodeDisruptionResources ()
@@ -664,7 +665,7 @@ var _ = Describe("NodeDisruption controller", func() {
664
665
})
665
666
666
667
By ("creating an overlapping disruption" )
667
- createNodeDisruption (overlappingDisruptionName , NDNamespace , node2Label , ctx )
668
+ createNodeDisruption (overlappingDisruptionName , NDNamespace , node2Label , "" , ctx )
668
669
})
669
670
It ("rejects the NodeDisruption" , func () {
670
671
Eventually (func () nodedisruptionv1alpha1.NodeDisruptionState {
@@ -691,7 +692,7 @@ var _ = Describe("NodeDisruption controller", func() {
691
692
})
692
693
693
694
By ("creating an overlapping disruption" )
694
- createNodeDisruption (overlappingDisruptionName , NDNamespace , node2Label , ctx )
695
+ createNodeDisruption (overlappingDisruptionName , NDNamespace , node2Label , "" , ctx )
695
696
})
696
697
It ("accepts the NodeDisruption" , func () {
697
698
Eventually (func () nodedisruptionv1alpha1.NodeDisruptionState {
@@ -705,5 +706,112 @@ var _ = Describe("NodeDisruption controller", func() {
705
706
})
706
707
})
707
708
})
709
+
710
+ Describe ("Reject typed disruptions feature" , Label ("Node disruption type" ), Ordered , func () {
711
+ var (
712
+ createdDisruption = & nodedisruptionv1alpha1.NodeDisruption {}
713
+ disruptionName = "disruption-test"
714
+ allowedDisruptionTypes = []string {"maintenance" , "decommission" , "tor-maintenance" }
715
+ )
716
+
717
+ AfterEach (func () {
718
+ clearAllNodeDisruptionResources ()
719
+ cancelFn ()
720
+ })
721
+
722
+ Context ("NodeDisruptionTypes is enabled" , func () {
723
+ When ("the created disruption has an allowed type" , func () {
724
+ BeforeEach (func () {
725
+ By ("Configuring a disruption" )
726
+ createNodeDisruption (disruptionName , NDNamespace , nodeLabels1 , "maintenance" , ctx )
727
+
728
+ By ("starting a reconciler with NodeDisruptionTypes enabled" )
729
+ cancelFn = startReconcilerWithConfig (NodeDisruptionReconcilerConfig {
730
+ RejectOverlappingDisruption : false ,
731
+ RetryInterval : time .Second * 1 ,
732
+ NodeDisruptionTypes : allowedDisruptionTypes ,
733
+ })
734
+ })
735
+ It ("grants the NodeDisruption" , func () {
736
+ Eventually (func () nodedisruptionv1alpha1.NodeDisruptionState {
737
+ err := k8sClient .Get (ctx , types.NamespacedName {Name : disruptionName , Namespace : NDNamespace }, createdDisruption )
738
+ if err != nil {
739
+ panic ("should be able to get" )
740
+ }
741
+ return createdDisruption .Status .State
742
+ }, timeout , interval ).Should (Equal (nodedisruptionv1alpha1 .Granted ))
743
+ })
744
+ })
745
+ When ("the created disruption has not an allowed type" , func () {
746
+ BeforeEach (func () {
747
+ By ("Configuring a disruption" )
748
+ createNodeDisruption (disruptionName , NDNamespace , nodeLabels1 , "toto" , ctx )
749
+
750
+ By ("starting a reconciler with NodeDisruptionTypes enabled" )
751
+ cancelFn = startReconcilerWithConfig (NodeDisruptionReconcilerConfig {
752
+ RejectOverlappingDisruption : false ,
753
+ RetryInterval : time .Second * 1 ,
754
+ NodeDisruptionTypes : allowedDisruptionTypes ,
755
+ })
756
+ })
757
+ It ("rejects the NodeDisruption" , func () {
758
+ Eventually (func () nodedisruptionv1alpha1.NodeDisruptionState {
759
+ err := k8sClient .Get (ctx , types.NamespacedName {Name : disruptionName , Namespace : NDNamespace }, createdDisruption )
760
+ if err != nil {
761
+ panic ("should be able to get" )
762
+ }
763
+ return createdDisruption .Status .State
764
+ }, timeout , interval ).Should (Equal (nodedisruptionv1alpha1 .Rejected ))
765
+ })
766
+ })
767
+ })
768
+
769
+ Context ("NodeDisruptionTypes is disabled" , func () {
770
+ When ("the created disruption has a type" , func () {
771
+ BeforeEach (func () {
772
+ By ("Configuring a disruption" )
773
+ createNodeDisruption (disruptionName , NDNamespace , nodeLabels1 , "maintenance" , ctx )
774
+
775
+ By ("starting a reconciler with NodeDisruptionTypes enabled" )
776
+ cancelFn = startReconcilerWithConfig (NodeDisruptionReconcilerConfig {
777
+ RejectOverlappingDisruption : false ,
778
+ RetryInterval : time .Second * 1 ,
779
+ NodeDisruptionTypes : []string {},
780
+ })
781
+ })
782
+ It ("grants the NodeDisruption" , func () {
783
+ Eventually (func () nodedisruptionv1alpha1.NodeDisruptionState {
784
+ err := k8sClient .Get (ctx , types.NamespacedName {Name : disruptionName , Namespace : NDNamespace }, createdDisruption )
785
+ if err != nil {
786
+ panic ("should be able to get" )
787
+ }
788
+ return createdDisruption .Status .State
789
+ }, timeout , interval ).Should (Equal (nodedisruptionv1alpha1 .Granted ))
790
+ })
791
+ })
792
+ When ("the created disruption has not a type" , func () {
793
+ BeforeEach (func () {
794
+ By ("Configuring a disruption" )
795
+ createNodeDisruption (disruptionName , NDNamespace , nodeLabels1 , "" , ctx )
796
+
797
+ By ("starting a reconciler with NodeDisruptionTypes enabled" )
798
+ cancelFn = startReconcilerWithConfig (NodeDisruptionReconcilerConfig {
799
+ RejectOverlappingDisruption : false ,
800
+ RetryInterval : time .Second * 1 ,
801
+ NodeDisruptionTypes : []string {},
802
+ })
803
+ })
804
+ It ("grants the NodeDisruption" , func () {
805
+ Eventually (func () nodedisruptionv1alpha1.NodeDisruptionState {
806
+ err := k8sClient .Get (ctx , types.NamespacedName {Name : disruptionName , Namespace : NDNamespace }, createdDisruption )
807
+ if err != nil {
808
+ panic ("should be able to get" )
809
+ }
810
+ return createdDisruption .Status .State
811
+ }, timeout , interval ).Should (Equal (nodedisruptionv1alpha1 .Granted ))
812
+ })
813
+ })
814
+ })
815
+ })
708
816
})
709
817
})
0 commit comments