Skip to content

Commit

Permalink
Skip redundant update when removing a finalizer
Browse files Browse the repository at this point in the history
We don't have to update a CR when the CR does not contain the finalizer
being removed. This also removes some unused/redundant function from
the Reconciler struct.
  • Loading branch information
kajinamit authored and openshift-merge-robot committed Aug 1, 2023
1 parent 18d0310 commit 5311ef2
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions controllers/placementapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,6 @@ import (
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
)

// GetClient -
func (r *PlacementAPIReconciler) GetClient() client.Client {
return r.Client
}

// GetKClient -
func (r *PlacementAPIReconciler) GetKClient() kubernetes.Interface {
return r.Kclient
}

// GetLogger -
func (r *PlacementAPIReconciler) GetLogger() logr.Logger {
return r.Log
}

// GetScheme -
func (r *PlacementAPIReconciler) GetScheme() *runtime.Scheme {
return r.Scheme
}

// PlacementAPIReconciler reconciles a PlacementAPI object
type PlacementAPIReconciler struct {
client.Client
Expand Down Expand Up @@ -251,11 +231,13 @@ func (r *PlacementAPIReconciler) reconcileDelete(ctx context.Context, instance *
}

if err == nil {
controllerutil.RemoveFinalizer(keystoneEndpoint, helper.GetFinalizer())
if err = helper.GetClient().Update(ctx, keystoneEndpoint); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
if controllerutil.RemoveFinalizer(keystoneEndpoint, helper.GetFinalizer()) {
err = r.Update(ctx, keystoneEndpoint)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
util.LogForObject(helper, "Removed finalizer from our KeystoneEndpoint", instance)
}
util.LogForObject(helper, "Removed finalizer from our KeystoneEndpoint", instance)
}

// Remove the finalizer from our KeystoneService CR
Expand All @@ -265,11 +247,13 @@ func (r *PlacementAPIReconciler) reconcileDelete(ctx context.Context, instance *
}

if err == nil {
controllerutil.RemoveFinalizer(keystoneService, helper.GetFinalizer())
if err = helper.GetClient().Update(ctx, keystoneService); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
if controllerutil.RemoveFinalizer(keystoneService, helper.GetFinalizer()) {
err = r.Update(ctx, keystoneService)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
util.LogForObject(helper, "Removed finalizer from our KeystoneService", instance)
}
util.LogForObject(helper, "Removed finalizer from our KeystoneService", instance)
}

// We did all the cleanup on the objects we created so we can remove the
Expand Down

0 comments on commit 5311ef2

Please sign in to comment.