Skip to content

Commit

Permalink
Ensure that finalizer is removed
Browse files Browse the repository at this point in the history
Signed-off-by: thepetk <thepetk@gmail.com>
  • Loading branch information
thepetk committed Mar 19, 2024
1 parent 00d6fbe commit 25514f7
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions controllers/component_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,9 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
log.Info(fmt.Sprintf("added the finalizer %v", req.NamespacedName))
}
} else {
if hasApplication.Status.Devfile != "" && (forceGenerateGitopsResource || len(component.Status.Conditions) > 0 && component.Status.Conditions[len(component.Status.Conditions)-1].Status == metav1.ConditionTrue && containsString(component.GetFinalizers(), compFinalizerName)) {
if hasApplication.Status.Devfile != "" && hasApplication.ObjectMeta.DeletionTimestamp.IsZero() && (forceGenerateGitopsResource || len(component.Status.Conditions) > 0 && component.Status.Conditions[len(component.Status.Conditions)-1].Status == metav1.ConditionTrue && containsString(component.GetFinalizers(), compFinalizerName)) {
// only attempt to finalize and update the gitops repo if an Application is present & not under deletion & the previous Component status is good
// A finalizer is present for the Component CR, so make sure we do the necessary cleanup steps
if !hasApplication.ObjectMeta.DeletionTimestamp.IsZero() {
log.Info("application %v is under deletion. Skipping deletion for component %v", hasApplication.Name, component.Name)
return ctrl.Result{}, nil
}

metrics.ComponentDeletionTotalReqs.Inc()
if err := r.Finalize(ctx, &component, &hasApplication, ghClient, gitToken); err != nil {
if errors.IsConflict(err) {
Expand All @@ -217,6 +212,9 @@ func (r *ComponentReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
controllerutil.RemoveFinalizer(&component, compFinalizerName)
if err := r.Update(ctx, &component); err != nil {
return ctrl.Result{}, err
} else if !hasApplication.ObjectMeta.DeletionTimestamp.IsZero() {
log.Info("application %v is under deletion. Skipping deletion for component %v", hasApplication.Name, component.Name)
return ctrl.Result{}, nil
} else {
metrics.ComponentDeletionSucceeded.Inc()
}
Expand Down

0 comments on commit 25514f7

Please sign in to comment.