Skip to content

Commit

Permalink
Merge pull request #284 from kajinamit/remove-finalizer-update
Browse files Browse the repository at this point in the history
Skip redundant update when removing a finalizer
  • Loading branch information
openshift-merge-robot authored Aug 16, 2023
2 parents 9679b71 + b016cfa commit 836fb65
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
27 changes: 13 additions & 14 deletions controllers/glance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,32 +221,31 @@ func (r *GlanceReconciler) reconcileDelete(ctx context.Context, instance *glance
}

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)
}

// Remove finalizers from any existing child GlanceAPIs
for _, apiType := range []string{glancev1.APIInternal, glancev1.APIExternal} {
glanceAPI := &glancev1.GlanceAPI{}
err = helper.GetClient().Get(ctx, types.NamespacedName{Name: fmt.Sprintf("%s-%s", instance.Name, apiType), Namespace: instance.Namespace}, glanceAPI)
err = r.Get(ctx, types.NamespacedName{Name: fmt.Sprintf("%s-%s", instance.Name, apiType), Namespace: instance.Namespace}, glanceAPI)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}

if err == nil {
controllerutil.RemoveFinalizer(glanceAPI, helper.GetFinalizer())
if err = helper.GetClient().Update(ctx, glanceAPI); err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
if controllerutil.RemoveFinalizer(glanceAPI, helper.GetFinalizer()) {
err = r.Update(ctx, glanceAPI)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
util.LogForObject(helper, fmt.Sprintf("Removed finalizer from GlanceAPI %s", glanceAPI.Name), glanceAPI)
}
util.LogForObject(helper, fmt.Sprintf("Removed finalizer from GlanceAPI %s", glanceAPI.Name), glanceAPI)

// if err = helper.GetClient().Delete(ctx, glanceAPI); err != nil && !k8s_errors.IsNotFound(err) {
// return ctrl.Result{}, err
// }
// util.LogForObject(helper, fmt.Sprintf("Deleted GlanceAPI %s", glanceAPI.Name), glanceAPI)
}
}

Expand Down
10 changes: 6 additions & 4 deletions controllers/glanceapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,13 @@ func (r *GlanceAPIReconciler) reconcileDelete(ctx context.Context, instance *gla
}

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)
}

// Endpoints are deleted so remove the finalizer.
Expand Down

0 comments on commit 836fb65

Please sign in to comment.