@@ -659,7 +659,7 @@ var _ = Describe("Eventhandler", func() {
659
659
})
660
660
661
661
Describe ("Funcs" , func () {
662
- failingFuncs := handler.Funcs {
662
+ failingFuncs := handler.TypedFuncs [client. Object , reconcile. Request ] {
663
663
CreateFunc : func (context.Context , event.CreateEvent , workqueue.TypedRateLimitingInterface [reconcile.Request ]) {
664
664
defer GinkgoRecover ()
665
665
Fail ("Did not expect CreateEvent to be called." )
@@ -797,6 +797,27 @@ var _ = Describe("Eventhandler", func() {
797
797
Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
798
798
})
799
799
800
+ It ("should lower the priority of a create request for an object that was created more than one minute in the past without the WithLowPriorityWrapper" , func () {
801
+ actualOpts := priorityqueue.AddOpts {}
802
+ var actualRequests []reconcile.Request
803
+ wq := & fakePriorityQueue {
804
+ addWithOpts : func (o priorityqueue.AddOpts , items ... reconcile.Request ) {
805
+ actualOpts = o
806
+ actualRequests = items
807
+ },
808
+ }
809
+
810
+ h := & handler.EnqueueRequestForObject {}
811
+ h .Create (ctx , event.CreateEvent {
812
+ Object : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
813
+ Name : "my-pod" ,
814
+ }},
815
+ }, wq )
816
+
817
+ Expect (actualOpts ).To (Equal (priorityqueue.AddOpts {Priority : handler .LowPriority }))
818
+ Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
819
+ })
820
+
800
821
It ("should not lower the priority of a create request for an object that was created less than one minute in the past" , func () {
801
822
actualOpts := priorityqueue.AddOpts {}
802
823
var actualRequests []reconcile.Request
@@ -819,6 +840,28 @@ var _ = Describe("Eventhandler", func() {
819
840
Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
820
841
})
821
842
843
+ It ("should not lower the priority of a create request for an object that was created less than one minute in the past without the WithLowPriority wrapperr" , func () {
844
+ actualOpts := priorityqueue.AddOpts {}
845
+ var actualRequests []reconcile.Request
846
+ wq := & fakePriorityQueue {
847
+ addWithOpts : func (o priorityqueue.AddOpts , items ... reconcile.Request ) {
848
+ actualOpts = o
849
+ actualRequests = items
850
+ },
851
+ }
852
+
853
+ h := & handler.EnqueueRequestForObject {}
854
+ h .Create (ctx , event.CreateEvent {
855
+ Object : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
856
+ Name : "my-pod" ,
857
+ CreationTimestamp : metav1 .Now (),
858
+ }},
859
+ }, wq )
860
+
861
+ Expect (actualOpts ).To (Equal (priorityqueue.AddOpts {}))
862
+ Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
863
+ })
864
+
822
865
It ("should lower the priority of an update request with unchanged RV" , func () {
823
866
actualOpts := priorityqueue.AddOpts {}
824
867
var actualRequests []reconcile.Request
@@ -843,6 +886,30 @@ var _ = Describe("Eventhandler", func() {
843
886
Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
844
887
})
845
888
889
+ It ("should lower the priority of an update request with unchanged RV without the WithLowPriority wrapper" , func () {
890
+ actualOpts := priorityqueue.AddOpts {}
891
+ var actualRequests []reconcile.Request
892
+ wq := & fakePriorityQueue {
893
+ addWithOpts : func (o priorityqueue.AddOpts , items ... reconcile.Request ) {
894
+ actualOpts = o
895
+ actualRequests = items
896
+ },
897
+ }
898
+
899
+ h := & handler.EnqueueRequestForObject {}
900
+ h .Update (ctx , event.UpdateEvent {
901
+ ObjectOld : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
902
+ Name : "my-pod" ,
903
+ }},
904
+ ObjectNew : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
905
+ Name : "my-pod" ,
906
+ }},
907
+ }, wq )
908
+
909
+ Expect (actualOpts ).To (Equal (priorityqueue.AddOpts {Priority : handler .LowPriority }))
910
+ Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
911
+ })
912
+
846
913
It ("should not lower the priority of an update request with changed RV" , func () {
847
914
actualOpts := priorityqueue.AddOpts {}
848
915
var actualRequests []reconcile.Request
@@ -868,6 +935,31 @@ var _ = Describe("Eventhandler", func() {
868
935
Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
869
936
})
870
937
938
+ It ("should not lower the priority of an update request with changed RV without the WithLowPriority wrapper" , func () {
939
+ actualOpts := priorityqueue.AddOpts {}
940
+ var actualRequests []reconcile.Request
941
+ wq := & fakePriorityQueue {
942
+ addWithOpts : func (o priorityqueue.AddOpts , items ... reconcile.Request ) {
943
+ actualOpts = o
944
+ actualRequests = items
945
+ },
946
+ }
947
+
948
+ h := & handler.EnqueueRequestForObject {}
949
+ h .Update (ctx , event.UpdateEvent {
950
+ ObjectOld : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
951
+ Name : "my-pod" ,
952
+ }},
953
+ ObjectNew : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
954
+ Name : "my-pod" ,
955
+ ResourceVersion : "1" ,
956
+ }},
957
+ }, wq )
958
+
959
+ Expect (actualOpts ).To (Equal (priorityqueue.AddOpts {}))
960
+ Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
961
+ })
962
+
871
963
It ("should have no effect on create if the workqueue is not a priorityqueue" , func () {
872
964
h := handler .WithLowPriorityWhenUnchanged (& handler.EnqueueRequestForObject {})
873
965
h .Create (ctx , event.CreateEvent {
@@ -881,6 +973,19 @@ var _ = Describe("Eventhandler", func() {
881
973
Expect (item ).To (Equal (reconcile.Request {NamespacedName : types.NamespacedName {Name : "my-pod" }}))
882
974
})
883
975
976
+ It ("should have no effect on create if the workqueue is not a priorityqueue without the WithLowPriority wrapper" , func () {
977
+ h := & handler.EnqueueRequestForObject {}
978
+ h .Create (ctx , event.CreateEvent {
979
+ Object : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
980
+ Name : "my-pod" ,
981
+ }},
982
+ }, q )
983
+
984
+ Expect (q .Len ()).To (Equal (1 ))
985
+ item , _ := q .Get ()
986
+ Expect (item ).To (Equal (reconcile.Request {NamespacedName : types.NamespacedName {Name : "my-pod" }}))
987
+ })
988
+
884
989
It ("should have no effect on Update if the workqueue is not a priorityqueue" , func () {
885
990
h := handler .WithLowPriorityWhenUnchanged (& handler.EnqueueRequestForObject {})
886
991
h .Update (ctx , event.UpdateEvent {
@@ -896,8 +1001,23 @@ var _ = Describe("Eventhandler", func() {
896
1001
item , _ := q .Get ()
897
1002
Expect (item ).To (Equal (reconcile.Request {NamespacedName : types.NamespacedName {Name : "my-pod" }}))
898
1003
})
899
- })
900
1004
1005
+ It ("should have no effect on Update if the workqueue is not a priorityqueue without the WithLowPriority wrapper" , func () {
1006
+ h := & handler.EnqueueRequestForObject {}
1007
+ h .Update (ctx , event.UpdateEvent {
1008
+ ObjectOld : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1009
+ Name : "my-pod" ,
1010
+ }},
1011
+ ObjectNew : & corev1.Pod {ObjectMeta : metav1.ObjectMeta {
1012
+ Name : "my-pod" ,
1013
+ }},
1014
+ }, q )
1015
+
1016
+ Expect (q .Len ()).To (Equal (1 ))
1017
+ item , _ := q .Get ()
1018
+ Expect (item ).To (Equal (reconcile.Request {NamespacedName : types.NamespacedName {Name : "my-pod" }}))
1019
+ })
1020
+ })
901
1021
})
902
1022
903
1023
type fakePriorityQueue struct {
0 commit comments