@@ -45,15 +45,17 @@ var _ = Describe("recorder", func() {
4545 Expect (err ).NotTo (HaveOccurred ())
4646
4747 By ("Creating the Controller" )
48- deprecatedRecorder := cm .GetEventRecorder ("test-deprecated-recorder" )
48+ deprecatedRecorder := cm .GetEventRecorderFor ("test-deprecated-recorder" )
4949 recorder := cm .GetEventRecorder ("test-recorder" )
50+ annotatedRecorder := cm .GetAnnotatedEventRecorder ("test-annotated-recorder" )
5051 instance , err := controller .New ("foo-controller" , cm , controller.Options {
5152 Reconciler : reconcile .Func (
5253 func (ctx context.Context , request reconcile.Request ) (reconcile.Result , error ) {
5354 dp , err := clientset .AppsV1 ().Deployments (request .Namespace ).Get (ctx , request .Name , metav1.GetOptions {})
5455 Expect (err ).NotTo (HaveOccurred ())
55- deprecatedRecorder .Eventf (dp , nil , corev1 .EventTypeNormal , "deprecated-test-reason" , "deprecatedAction " , "deprecated-test-msg" )
56+ deprecatedRecorder .Eventf (dp , corev1 .EventTypeNormal , "deprecated-test-reason" , "deprecated-test-msg" )
5657 recorder .Eventf (dp , nil , corev1 .EventTypeNormal , "test-reason" , "test-action" , "test-note" )
58+ annotatedRecorder .AnnotatedEventf (dp , nil , map [string ]string {"key" : "value" }, corev1 .EventTypeNormal , "test-annotated-reason" , "test-annotated-action" , "test-annotated-note" )
5759 return reconcile.Result {}, nil
5860 }),
5961 })
@@ -129,6 +131,24 @@ var _ = Describe("recorder", func() {
129131 Expect (evt .Reason ).To (Equal ("test-reason" ))
130132 Expect (evt .Action ).To (Equal ("test-action" ))
131133 Expect (evt .Note ).To (Equal ("test-note" ))
134+
135+ By ("Validate annotated event is published as expected" )
136+ annotatedEvtWatcher , err := clientset .EventsV1 ().Events ("default" ).Watch (ctx ,
137+ metav1.ListOptions {FieldSelector : fields .OneTermEqualSelector ("reason" , "test-annotated-reason" ).String ()})
138+ Expect (err ).NotTo (HaveOccurred ())
139+
140+ resultEvent = <- annotatedEvtWatcher .ResultChan ()
141+
142+ Expect (resultEvent .Type ).To (Equal (watch .Added ))
143+ annotatedEvt , isEvent := resultEvent .Object .(* eventsv1.Event )
144+ Expect (isEvent ).To (BeTrue ())
145+
146+ Expect (annotatedEvt .Regarding ).To (Equal (* dpRef ))
147+ Expect (annotatedEvt .Type ).To (Equal (corev1 .EventTypeNormal ))
148+ Expect (annotatedEvt .Reason ).To (Equal ("test-annotated-reason" ))
149+ Expect (annotatedEvt .Action ).To (Equal ("test-annotated-action" ))
150+ Expect (annotatedEvt .Note ).To (Equal ("test-annotated-note" ))
151+ Expect (annotatedEvt .Annotations ).To (HaveKeyWithValue ("key" , "value" ))
132152 })
133153 })
134154})
0 commit comments