Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip redundant update when removing a finalizer #284

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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