Skip to content

Commit

Permalink
Merge pull request #267 from gibizer/remove-double-update
Browse files Browse the repository at this point in the history
Remove the double update when finalizer added
  • Loading branch information
openshift-merge-bot[bot] authored Apr 15, 2024
2 parents 52c4fc7 + 50173e6 commit ae3a608
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
17 changes: 5 additions & 12 deletions controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ func (r *OVNDBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
}()

// If we're not deleting this and the service object doesn't have our finalizer, add it.
if instance.DeletionTimestamp.IsZero() && controllerutil.AddFinalizer(instance, helper.GetFinalizer()) {
return ctrl.Result{}, nil
}

// Handle service delete
if !instance.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, instance, helper)
Expand Down Expand Up @@ -283,9 +288,6 @@ func (r *OVNDBClusterReconciler) reconcileDelete(ctx context.Context, instance *
// Service is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
Log.Info("Reconciled Service delete successfully")
if err := r.Update(ctx, instance); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
}
Expand Down Expand Up @@ -319,15 +321,6 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *

Log.Info("Reconciling Service")

if !controllerutil.ContainsFinalizer(instance, helper.GetFinalizer()) {
// If the service object doesn't have our finalizer, add it.
controllerutil.AddFinalizer(instance, helper.GetFinalizer())
// Register the finalizer immediately to avoid orphaning resources on delete
err := r.Update(ctx, instance)

return ctrl.Result{}, err
}

// Service account, role, binding
rbacRules := []rbacv1.PolicyRule{
{
Expand Down
9 changes: 5 additions & 4 deletions controllers/ovnnorthd_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func (r *OVNNorthdReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
}()

// If we're not deleting this and the service object doesn't have our finalizer, add it.
if instance.DeletionTimestamp.IsZero() && controllerutil.AddFinalizer(instance, helper.GetFinalizer()) {
return ctrl.Result{}, nil
}

// Handle service delete
if !instance.DeletionTimestamp.IsZero() {
return r.reconcileDelete(ctx, instance, helper)
Expand Down Expand Up @@ -265,10 +270,6 @@ func (r *OVNNorthdReconciler) reconcileDelete(ctx context.Context, instance *ovn
// Service is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
Log.Info("Reconciled Service delete successfully")
if err := r.Update(ctx, instance); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}

return ctrl.Result{}, nil
}

Expand Down

0 comments on commit ae3a608

Please sign in to comment.