@@ -173,17 +173,42 @@ var _ = Describe("Reconciler", func() {
173173 })
174174
175175 It ("should delete" , func () {
176+ deployment := & appsv1.Deployment {
177+ TypeMeta : metav1.TypeMeta {
178+ APIVersion : "apps/v1" ,
179+ Kind : "Deployment" ,
180+ },
181+ ObjectMeta : metav1.ObjectMeta {
182+ Name : "helper-deployment" ,
183+ Namespace : testcr .Namespace ,
184+ },
185+ }
186+
176187 args := createArgs (version )
188+ invokeCallbacks = func (_ interface {}, state callbacks.ReconcileState , _ client.Object , _ client.Object ) error {
189+ if state == callbacks .ReconcileStateOperatorDelete {
190+ return args .client .Delete (context .TODO (), deployment )
191+ }
192+
193+ return nil
194+ }
195+ err := args .client .Create (context .TODO (), deployment )
196+ Expect (err ).ToNot (HaveOccurred ())
177197 doReconcile (args )
178198
199+ // verify unused exists before upgrade is done
200+ _ , err = getObject (args .client , deployment )
201+ Expect (err ).ToNot (HaveOccurred ())
202+
179203 args .config .DeletionTimestamp = & metav1.Time {Time : time .Now ()}
180- err : = args .client .Update (context .TODO (), args .config )
204+ err = args .client .Update (context .TODO (), args .config )
181205 Expect (err ).ToNot (HaveOccurred ())
182206
183- doReconcile (args )
207+ doReconcileExpectDelete (args )
184208
185- Expect (args .config .Finalizers ).Should (BeEmpty ())
186- Expect (args .config .Status .Phase ).Should (Equal (sdkapi .PhaseDeleted ))
209+ // verify that object no longer exists
210+ _ , err = getObject (args .client , deployment )
211+ Expect (errors .IsNotFound (err )).Should (Equal (true ))
187212 })
188213 })
189214 })
@@ -586,6 +611,7 @@ var _ = Describe("Reconciler", func() {
586611 _ = args .reconciler .CrSetVersion (args .config , prevVersion )
587612 //mark CR for deletion
588613 args .config .SetDeletionTimestamp (& metav1.Time {Time : time .Now ()})
614+ args .config .Finalizers = append (args .config .Finalizers , "keepmearound" )
589615 err := args .client .Update (context .TODO (), args .config )
590616 Expect (err ).ToNot (HaveOccurred ())
591617
@@ -620,6 +646,7 @@ var _ = Describe("Reconciler", func() {
620646
621647 //mark CR for deletion
622648 args .config .SetDeletionTimestamp (& metav1.Time {Time : time .Now ()})
649+ args .config .Finalizers = append (args .config .Finalizers , "keepmearound" )
623650 err = args .client .Update (context .TODO (), args .config )
624651 Expect (err ).ToNot (HaveOccurred ())
625652
@@ -779,6 +806,16 @@ func doReconcileError(args *args) {
779806 Expect (err ).ToNot (HaveOccurred ())
780807}
781808
809+ func doReconcileExpectDelete (args * args ) {
810+ result , err := args .reconciler .Reconcile (reconcileRequest (args .config .Name ), args .version , log )
811+ Expect (err ).ToNot (HaveOccurred ())
812+ Expect (result .Requeue ).To (BeFalse ())
813+
814+ _ , err = getConfig (args .client , args .config )
815+ Expect (err ).To (HaveOccurred ())
816+ Expect (errors .IsNotFound (err )).To (BeTrue ())
817+ }
818+
782819func setDeploymentsReady (args * args ) bool {
783820 crManager := testcr.ConfigCrManager {}
784821 resources , err := crManager .GetAllResources (args .config )
0 commit comments