@@ -173,17 +173,42 @@ var _ = Describe("Reconciler", func() {
173
173
})
174
174
175
175
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
+
176
187
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 ())
177
197
doReconcile (args )
178
198
199
+ // verify unused exists before upgrade is done
200
+ _ , err = getObject (args .client , deployment )
201
+ Expect (err ).ToNot (HaveOccurred ())
202
+
179
203
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 )
181
205
Expect (err ).ToNot (HaveOccurred ())
182
206
183
- doReconcile (args )
207
+ doReconcileExpectDelete (args )
184
208
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 ))
187
212
})
188
213
})
189
214
})
@@ -586,6 +611,7 @@ var _ = Describe("Reconciler", func() {
586
611
_ = args .reconciler .CrSetVersion (args .config , prevVersion )
587
612
//mark CR for deletion
588
613
args .config .SetDeletionTimestamp (& metav1.Time {Time : time .Now ()})
614
+ args .config .Finalizers = append (args .config .Finalizers , "keepmearound" )
589
615
err := args .client .Update (context .TODO (), args .config )
590
616
Expect (err ).ToNot (HaveOccurred ())
591
617
@@ -620,6 +646,7 @@ var _ = Describe("Reconciler", func() {
620
646
621
647
//mark CR for deletion
622
648
args .config .SetDeletionTimestamp (& metav1.Time {Time : time .Now ()})
649
+ args .config .Finalizers = append (args .config .Finalizers , "keepmearound" )
623
650
err = args .client .Update (context .TODO (), args .config )
624
651
Expect (err ).ToNot (HaveOccurred ())
625
652
@@ -779,6 +806,16 @@ func doReconcileError(args *args) {
779
806
Expect (err ).ToNot (HaveOccurred ())
780
807
}
781
808
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
+
782
819
func setDeploymentsReady (args * args ) bool {
783
820
crManager := testcr.ConfigCrManager {}
784
821
resources , err := crManager .GetAllResources (args .config )
0 commit comments