Skip to content

Commit ceb0255

Browse files
author
Per Goncalves da Silva
committed
Remove condition setting on finalizer removal
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 8de1c8e commit ceb0255

File tree

1 file changed

+55
-61
lines changed

1 file changed

+55
-61
lines changed

internal/operator-controller/controllers/clusterextensionrevision_controller.go

Lines changed: 55 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -118,67 +118,8 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
118118

119119
revision, opts, previous := toBoxcutterRevision(rev)
120120

121-
// nolint:nestif
122-
if !rev.DeletionTimestamp.IsZero() ||
123-
rev.Spec.LifecycleState == ocv1.ClusterExtensionRevisionLifecycleStateArchived {
124-
//
125-
// Teardown
126-
//
127-
tres, err := c.RevisionEngine.Teardown(ctx, *revision)
128-
if err != nil {
129-
meta.SetStatusCondition(&rev.Status.Conditions, metav1.Condition{
130-
Type: ocv1.ClusterExtensionRevisionTypeAvailable,
131-
Status: metav1.ConditionFalse,
132-
Reason: ocv1.ClusterExtensionRevisionReasonReconcileFailure,
133-
Message: err.Error(),
134-
ObservedGeneration: rev.Generation,
135-
})
136-
return ctrl.Result{}, fmt.Errorf("revision teardown: %v", err)
137-
}
138-
139-
l.Info("teardown report", "report", tres.String())
140-
if !tres.IsComplete() {
141-
// TODO: If it is not complete, it seems like it would be good to update
142-
// the status in some way to tell the user that the teardown is still
143-
// in progress.
144-
return ctrl.Result{}, nil
145-
}
146-
147-
if err := c.TrackingCache.Free(ctx, rev); err != nil {
148-
meta.SetStatusCondition(&rev.Status.Conditions, metav1.Condition{
149-
Type: ocv1.ClusterExtensionRevisionTypeAvailable,
150-
Status: metav1.ConditionFalse,
151-
Reason: ocv1.ClusterExtensionRevisionReasonReconcileFailure,
152-
Message: err.Error(),
153-
ObservedGeneration: rev.Generation,
154-
})
155-
return ctrl.Result{}, fmt.Errorf("error stopping informers: %v", err)
156-
}
157-
158-
// Ensure Available condition is set to Unknown before removing the finalizer when archiving
159-
if rev.Spec.LifecycleState == ocv1.ClusterExtensionRevisionLifecycleStateArchived &&
160-
!meta.IsStatusConditionPresentAndEqual(rev.Status.Conditions, ocv1.ClusterExtensionRevisionTypeAvailable, metav1.ConditionUnknown) {
161-
meta.SetStatusCondition(&rev.Status.Conditions, metav1.Condition{
162-
Type: ocv1.ClusterExtensionRevisionTypeAvailable,
163-
Status: metav1.ConditionUnknown,
164-
Reason: ocv1.ClusterExtensionRevisionReasonArchived,
165-
Message: "revision is archived",
166-
ObservedGeneration: rev.Generation,
167-
})
168-
return ctrl.Result{}, nil
169-
}
170-
171-
if err := c.removeFinalizer(ctx, rev, clusterExtensionRevisionTeardownFinalizer); err != nil {
172-
meta.SetStatusCondition(&rev.Status.Conditions, metav1.Condition{
173-
Type: ocv1.ClusterExtensionRevisionTypeAvailable,
174-
Status: metav1.ConditionFalse,
175-
Reason: ocv1.ClusterExtensionRevisionReasonReconcileFailure,
176-
Message: err.Error(),
177-
ObservedGeneration: rev.Generation,
178-
})
179-
return ctrl.Result{}, fmt.Errorf("error removing teardown finalizer: %v", err)
180-
}
181-
return ctrl.Result{}, nil
121+
if !rev.DeletionTimestamp.IsZero() || rev.Spec.LifecycleState == ocv1.ClusterExtensionRevisionLifecycleStateArchived {
122+
return c.teardown(ctx, rev, revision)
182123
}
183124

184125
//
@@ -354,6 +295,59 @@ func (c *ClusterExtensionRevisionReconciler) reconcile(ctx context.Context, rev
354295
return ctrl.Result{}, nil
355296
}
356297

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+
357351
type Sourcerer interface {
358352
Source(handler handler.EventHandler, predicates ...predicate.Predicate) source.Source
359353
}

0 commit comments

Comments
 (0)