Skip to content

Commit

Permalink
fix: when delete DSCI CR get current instance and remove finalizer on…
Browse files Browse the repository at this point in the history
… it (#1142)

- after remove servicemesh and update condition, instance has been
updated
- use retryonconflict to make sure it is removed when something else
might also update DSCI at the same time

Signed-off-by: Wen Zhou <[email protected]>
  • Loading branch information
zdtsw authored Jul 26, 2024
1 parent a08c94a commit fb6a37f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/retry"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -113,11 +114,23 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
if err := r.removeServiceMesh(ctx, instance); err != nil {
return reconcile.Result{}, err
}
if controllerutil.ContainsFinalizer(instance, finalizerName) {
controllerutil.RemoveFinalizer(instance, finalizerName)
if err := r.Update(ctx, instance); err != nil {
return ctrl.Result{}, err

err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
newInstance := &dsciv1.DSCInitialization{}
if err := r.Client.Get(ctx, client.ObjectKeyFromObject(instance), newInstance); err != nil {
return err
}
if controllerutil.ContainsFinalizer(newInstance, finalizerName) {
controllerutil.RemoveFinalizer(newInstance, finalizerName)
if err := r.Update(ctx, newInstance); err != nil {
return err
}
}
return nil
})
if err != nil {
r.Log.Error(err, "Failed to remove finalizer when deleting DSCInitialization instance")
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
Expand Down

0 comments on commit fb6a37f

Please sign in to comment.