@@ -79,8 +79,10 @@ var _ = Describe("Function Controller", func() {
7979
8080 type reconcileTestCase struct {
8181 spec functionsdevv1alpha1.FunctionSpec
82+ annotations map [string ]string
8283 configureMocks func (* funccli.MockManager , * git.MockManager )
8384 statusChecks func (* functionsdevv1alpha1.FunctionStatus )
85+ functionChecks func (* functionsdevv1alpha1.Function )
8486 operatorConfig map [string ]string
8587 }
8688
@@ -90,6 +92,16 @@ var _ = Describe("Function Controller", func() {
9092 err := createFunctionResource (resourceName , resourceNamespace , tc .spec )
9193 Expect (err ).NotTo (HaveOccurred ())
9294
95+ if tc .annotations != nil {
96+ By ("Adding annotations to the Function" )
97+ f := & functionsdevv1alpha1.Function {}
98+ err = k8sClient .Get (ctx , typeNamespacedName , f )
99+ Expect (err ).NotTo (HaveOccurred ())
100+ f .SetAnnotations (tc .annotations )
101+ err = k8sClient .Update (ctx , f )
102+ Expect (err ).NotTo (HaveOccurred ())
103+ }
104+
93105 By ("Setting up mocks" )
94106 funcCliManagerMock := funccli .NewMockManager (GinkgoT ())
95107 gitManagerMock := git .NewMockManager (GinkgoT ())
@@ -127,6 +139,14 @@ var _ = Describe("Function Controller", func() {
127139
128140 tc .statusChecks (& f .Status )
129141 }
142+
143+ if tc .functionChecks != nil {
144+ f := & functionsdevv1alpha1.Function {}
145+ err := k8sClient .Get (ctx , typeNamespacedName , f )
146+ Expect (err ).NotTo (HaveOccurred ())
147+
148+ tc .functionChecks (f )
149+ }
130150 },
131151 Entry ("should deploy when middleware update required" , reconcileTestCase {
132152 spec : defaultSpec ,
@@ -397,6 +417,52 @@ var _ = Describe("Function Controller", func() {
397417 Expect (messages ).ToNot (ContainElement (ContainSubstring ("Middleware updated" )))
398418 },
399419 }),
420+ Entry ("should remove func annotations after successful reconcile" , reconcileTestCase {
421+ spec : defaultSpec ,
422+ annotations : map [string ]string {
423+ "functions.knative.dev/rebuild" : "true" ,
424+ "other-annotation" : "keep-me" ,
425+ },
426+ configureMocks : func (funcMock * funccli.MockManager , gitMock * git.MockManager ) {
427+ funcMock .EXPECT ().Describe (mock .Anything , functionName , resourceNamespace ).Return (functions.Instance {
428+ Middleware : functions.Middleware {
429+ Version : "v1.0.0" ,
430+ },
431+ }, nil )
432+ funcMock .EXPECT ().GetLatestMiddlewareVersion (mock .Anything , mock .Anything , mock .Anything ).Return ("v1.0.0" , nil )
433+ funcMock .EXPECT ().GetMiddlewareVersion (mock .Anything , functionName , resourceNamespace ).Return ("v1.0.0" , nil )
434+
435+ gitMock .EXPECT ().CloneRepository (mock .Anything , "https://github.com/foo/bar" , "" , "my-branch" , mock .Anything ).Return (createTmpGitRepo (functions.Function {Name : "func-go" }), nil )
436+ },
437+ functionChecks : func (f * functionsdevv1alpha1.Function ) {
438+ annotations := f .GetAnnotations ()
439+ Expect (annotations ).NotTo (HaveKey ("functions.knative.dev/rebuild" ))
440+ Expect (annotations ).To (HaveKeyWithValue ("other-annotation" , "keep-me" ))
441+ },
442+ }),
443+ Entry ("should remove multiple func annotations after successful reconcile" , reconcileTestCase {
444+ spec : defaultSpec ,
445+ annotations : map [string ]string {
446+ "functions.knative.dev/rebuild" : "true" ,
447+ "functions.knative.dev/reason" : "config-change" ,
448+ },
449+ configureMocks : func (funcMock * funccli.MockManager , gitMock * git.MockManager ) {
450+ funcMock .EXPECT ().Describe (mock .Anything , functionName , resourceNamespace ).Return (functions.Instance {
451+ Middleware : functions.Middleware {
452+ Version : "v1.0.0" ,
453+ },
454+ }, nil )
455+ funcMock .EXPECT ().GetLatestMiddlewareVersion (mock .Anything , mock .Anything , mock .Anything ).Return ("v1.0.0" , nil )
456+ funcMock .EXPECT ().GetMiddlewareVersion (mock .Anything , functionName , resourceNamespace ).Return ("v1.0.0" , nil )
457+
458+ gitMock .EXPECT ().CloneRepository (mock .Anything , "https://github.com/foo/bar" , "" , "my-branch" , mock .Anything ).Return (createTmpGitRepo (functions.Function {Name : "func-go" }), nil )
459+ },
460+ functionChecks : func (f * functionsdevv1alpha1.Function ) {
461+ annotations := f .GetAnnotations ()
462+ Expect (annotations ).NotTo (HaveKey ("functions.knative.dev/rebuild" ))
463+ Expect (annotations ).NotTo (HaveKey ("functions.knative.dev/reason" ))
464+ },
465+ }),
400466 Entry ("should set ServiceReady condition to false with unknown reason when ready status is empty" , reconcileTestCase {
401467 spec : defaultSpec ,
402468 configureMocks : func (funcMock * funccli.MockManager , gitMock * git.MockManager ) {
0 commit comments