Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
kerenlahav committed Dec 22, 2024
1 parent a24b640 commit bd10c03
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
3 changes: 1 addition & 2 deletions controllers/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func (r *SecretReconciler) Reconcile(ctx context.Context, req reconcile.Request)

if utils.IsMarkedForDeletion(secret.ObjectMeta) {
log.Info("secret is marked for deletion, removing finalizer")
controllerutil.RemoveFinalizer(secret, common.FinalizerName)
return ctrl.Result{}, r.Update(ctx, secret)
return ctrl.Result{}, utils.RemoveFinalizer(ctx, r.Client, secret, common.FinalizerName)
}

log.Info("finished reconciling params secret")
Expand Down
19 changes: 4 additions & 15 deletions internal/utils/controller_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,11 @@ type format string
type LogKey struct {
}

func RemoveFinalizer(ctx context.Context, k8sClient client.Client, object common.SAPBTPResource, finalizerName string) error {
func RemoveFinalizer(ctx context.Context, k8sClient client.Client, object client.Object, finalizerName string) error {
log := GetLogger(ctx)
if controllerutil.ContainsFinalizer(object, finalizerName) {
log.Info(fmt.Sprintf("removing finalizer %s", finalizerName))
controllerutil.RemoveFinalizer(object, finalizerName)
if err := k8sClient.Update(ctx, object); err != nil {
if err := k8sClient.Get(ctx, apimachinerytypes.NamespacedName{Name: object.GetName(), Namespace: object.GetNamespace()}, object); err != nil {
return client.IgnoreNotFound(err)
}
controllerutil.RemoveFinalizer(object, finalizerName)
if err := k8sClient.Update(ctx, object); err != nil {
return fmt.Errorf("failed to remove the finalizer '%s'. Error: %v", finalizerName, err)
}
}
log.Info(fmt.Sprintf("removed finalizer %s from %s", finalizerName, object.GetControllerName()))
return nil
if controllerutil.RemoveFinalizer(object, finalizerName) {
log.Info(fmt.Sprintf("removing finalizer %s from resource %s named '%s' in namespace '%s'", finalizerName, object.GetObjectKind(), object.GetName(), object.GetNamespace()))
return k8sClient.Update(ctx, object)
}
return nil
}
Expand Down

0 comments on commit bd10c03

Please sign in to comment.