@@ -659,7 +659,7 @@ var _ = Describe("Eventhandler", func() {
659659})
660660
661661Describe ("Funcs" , func () {
662- failingFuncs := handler.Funcs {
662+ failingFuncs := handler.TypedFuncs [client. Object , reconcile. Request ] {
663663CreateFunc : func (context.Context , event.CreateEvent , workqueue.TypedRateLimitingInterface [reconcile.Request ]) {
664664defer GinkgoRecover ()
665665Fail ("Did not expect CreateEvent to be called." )
@@ -797,6 +797,27 @@ var _ = Describe("Eventhandler", func() {
797797Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
798798})
799799
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+
800821It ("should not lower the priority of a create request for an object that was created less than one minute in the past" , func () {
801822actualOpts := priorityqueue.AddOpts {}
802823var actualRequests []reconcile.Request
@@ -819,6 +840,28 @@ var _ = Describe("Eventhandler", func() {
819840Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
820841})
821842
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+
822865It ("should lower the priority of an update request with unchanged RV" , func () {
823866actualOpts := priorityqueue.AddOpts {}
824867var actualRequests []reconcile.Request
@@ -843,6 +886,30 @@ var _ = Describe("Eventhandler", func() {
843886Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
844887})
845888
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+
846913It ("should not lower the priority of an update request with changed RV" , func () {
847914actualOpts := priorityqueue.AddOpts {}
848915var actualRequests []reconcile.Request
@@ -868,6 +935,31 @@ var _ = Describe("Eventhandler", func() {
868935Expect (actualRequests ).To (Equal ([]reconcile.Request {{NamespacedName : types.NamespacedName {Name : "my-pod" }}}))
869936})
870937
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+
871963It ("should have no effect on create if the workqueue is not a priorityqueue" , func () {
872964h := handler .WithLowPriorityWhenUnchanged (& handler.EnqueueRequestForObject {})
873965h .Create (ctx , event.CreateEvent {
@@ -881,6 +973,19 @@ var _ = Describe("Eventhandler", func() {
881973Expect (item ).To (Equal (reconcile.Request {NamespacedName : types.NamespacedName {Name : "my-pod" }}))
882974})
883975
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+
884989It ("should have no effect on Update if the workqueue is not a priorityqueue" , func () {
885990h := handler .WithLowPriorityWhenUnchanged (& handler.EnqueueRequestForObject {})
886991h .Update (ctx , event.UpdateEvent {
@@ -896,8 +1001,23 @@ var _ = Describe("Eventhandler", func() {
8961001item , _ := q .Get ()
8971002Expect (item ).To (Equal (reconcile.Request {NamespacedName : types.NamespacedName {Name : "my-pod" }}))
8981003})
899- })
9001004
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+ })
9011021})
9021022
9031023type fakePriorityQueue struct {
0 commit comments