@@ -118,52 +118,8 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
118118
119119 revision , opts , previous := toBoxcutterRevision (rev )
120120
121- if ! rev .DeletionTimestamp .IsZero () ||
122- rev .Spec .LifecycleState == ocv1 .ClusterExtensionRevisionLifecycleStateArchived {
123- //
124- // Teardown
125- //
126- tres , err := c .RevisionEngine .Teardown (ctx , * revision )
127- if err != nil {
128- meta .SetStatusCondition (& rev .Status .Conditions , metav1.Condition {
129- Type : ocv1 .ClusterExtensionRevisionTypeAvailable ,
130- Status : metav1 .ConditionFalse ,
131- Reason : ocv1 .ClusterExtensionRevisionReasonReconcileFailure ,
132- Message : err .Error (),
133- ObservedGeneration : rev .Generation ,
134- })
135- return ctrl.Result {}, fmt .Errorf ("revision teardown: %v" , err )
136- }
137-
138- l .Info ("teardown report" , "report" , tres .String ())
139- if ! tres .IsComplete () {
140- // TODO: If it is not complete, it seems like it would be good to update
141- // the status in some way to tell the user that the teardown is still
142- // in progress.
143- return ctrl.Result {}, nil
144- }
145-
146- if err := c .TrackingCache .Free (ctx , rev ); err != nil {
147- meta .SetStatusCondition (& rev .Status .Conditions , metav1.Condition {
148- Type : ocv1 .ClusterExtensionRevisionTypeAvailable ,
149- Status : metav1 .ConditionFalse ,
150- Reason : ocv1 .ClusterExtensionRevisionReasonReconcileFailure ,
151- Message : err .Error (),
152- ObservedGeneration : rev .Generation ,
153- })
154- return ctrl.Result {}, fmt .Errorf ("error stopping informers: %v" , err )
155- }
156- if err := c .removeFinalizer (ctx , rev , clusterExtensionRevisionTeardownFinalizer ); err != nil {
157- meta .SetStatusCondition (& rev .Status .Conditions , metav1.Condition {
158- Type : "Available" ,
159- Status : metav1 .ConditionFalse ,
160- Reason : "ReconcileFailure" ,
161- Message : err .Error (),
162- ObservedGeneration : rev .Generation ,
163- })
164- return ctrl.Result {}, fmt .Errorf ("error removing teardown finalizer: %v" , err )
165- }
166- return ctrl.Result {}, nil
121+ if ! rev .DeletionTimestamp .IsZero () || rev .Spec .LifecycleState == ocv1 .ClusterExtensionRevisionLifecycleStateArchived {
122+ return c .teardown (ctx , rev , revision )
167123 }
168124
169125 //
@@ -339,6 +295,59 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
339295 return ctrl.Result {}, nil
340296}
341297
298+ func (c * ClusterExtensionRevisionReconciler ) teardown (ctx context.Context , rev * ocv1.ClusterExtensionRevision , revision * boxcutter.Revision ) (ctrl.Result , error ) {
299+ l := log .FromContext (ctx )
300+
301+ tres , err := c .RevisionEngine .Teardown (ctx , * revision )
302+ if err != nil {
303+ meta .SetStatusCondition (& rev .Status .Conditions , metav1.Condition {
304+ Type : ocv1 .ClusterExtensionRevisionTypeAvailable ,
305+ Status : metav1 .ConditionFalse ,
306+ Reason : ocv1 .ClusterExtensionRevisionReasonReconcileFailure ,
307+ Message : err .Error (),
308+ ObservedGeneration : rev .Generation ,
309+ })
310+ return ctrl.Result {}, fmt .Errorf ("revision teardown: %v" , err )
311+ }
312+
313+ l .Info ("teardown report" , "report" , tres .String ())
314+ if ! tres .IsComplete () {
315+ // TODO: If it is not complete, it seems like it would be good to update
316+ // the status in some way to tell the user that the teardown is still
317+ // in progress.
318+ return ctrl.Result {}, nil
319+ }
320+
321+ if err := c .TrackingCache .Free (ctx , rev ); err != nil {
322+ meta .SetStatusCondition (& rev .Status .Conditions , metav1.Condition {
323+ Type : ocv1 .ClusterExtensionRevisionTypeAvailable ,
324+ Status : metav1 .ConditionFalse ,
325+ Reason : ocv1 .ClusterExtensionRevisionReasonReconcileFailure ,
326+ Message : err .Error (),
327+ ObservedGeneration : rev .Generation ,
328+ })
329+ return ctrl.Result {}, fmt .Errorf ("error stopping informers: %v" , err )
330+ }
331+
332+ // Ensure Available condition is set to Unknown before removing the finalizer when archiving
333+ if rev .Spec .LifecycleState == ocv1 .ClusterExtensionRevisionLifecycleStateArchived &&
334+ ! meta .IsStatusConditionPresentAndEqual (rev .Status .Conditions , ocv1 .ClusterExtensionRevisionTypeAvailable , metav1 .ConditionUnknown ) {
335+ meta .SetStatusCondition (& rev .Status .Conditions , metav1.Condition {
336+ Type : ocv1 .ClusterExtensionRevisionTypeAvailable ,
337+ Status : metav1 .ConditionUnknown ,
338+ Reason : ocv1 .ClusterExtensionRevisionReasonArchived ,
339+ Message : "revision is archived" ,
340+ ObservedGeneration : rev .Generation ,
341+ })
342+ return ctrl.Result {}, nil
343+ }
344+
345+ if err := c .removeFinalizer (ctx , rev , clusterExtensionRevisionTeardownFinalizer ); err != nil {
346+ return ctrl.Result {}, fmt .Errorf ("error removing teardown finalizer: %v" , err )
347+ }
348+ return ctrl.Result {}, nil
349+ }
350+
342351type Sourcerer interface {
343352 Source (handler handler.EventHandler , predicates ... predicate.Predicate ) source.Source
344353}
0 commit comments