Skip to content

Commit

Permalink
Merge pull request #216 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 2, 2023
2 parents 0b3bb05 + 630c9bf commit 08527f0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 85 deletions.
40 changes: 12 additions & 28 deletions controllers/heatapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
)

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

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

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

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

// HeatAPIReconciler reconciles a Heat object
type HeatAPIReconciler struct {
client.Client
Expand Down Expand Up @@ -252,23 +232,27 @@ func (r *HeatAPIReconciler) reconcileDelete(ctx context.Context, instance *heatv
return ctrl.Result{}, err
}
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 KeystoneEndpoint", instance)
}
util.LogForObject(helper, "Removed finalizer from KeystoneEndpoint", instance)
}

keystoneService, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, ksSvc["name"], instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
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)
}
}

Expand Down
40 changes: 12 additions & 28 deletions controllers/heatcfnapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,6 @@ import (
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
)

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

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

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

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

// HeatCfnAPIReconciler reconciles a Heat object
type HeatCfnAPIReconciler struct {
client.Client
Expand Down Expand Up @@ -256,23 +236,27 @@ func (r *HeatCfnAPIReconciler) reconcileDelete(ctx context.Context, instance *he
return ctrl.Result{}, err
}
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 KeystoneEndpoint", instance)
}
util.LogForObject(helper, "Removed finalizer from KeystoneEndpoint", instance)
}

keystoneService, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, ksSvc["name"], instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
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)
}
}

Expand Down
30 changes: 1 addition & 29 deletions controllers/heatengine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
heatv1beta1 "github.com/openstack-k8s-operators/heat-operator/api/v1beta1"
"github.com/openstack-k8s-operators/heat-operator/pkg/heat"
heatengine "github.com/openstack-k8s-operators/heat-operator/pkg/heatengine"
keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
configmap "github.com/openstack-k8s-operators/lib-common/modules/common/configmap"
Expand Down Expand Up @@ -198,35 +197,8 @@ func (r *HeatEngineReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *HeatEngineReconciler) reconcileDelete(ctx context.Context, instance *heatv1beta1.HeatEngine, helper *helper.Helper) (ctrl.Result, error) {
r.Log.Info("Reconciling Engine Delete")

for _, ksSvc := range keystoneServices {
keystoneEndpoint, err := keystonev1.GetKeystoneEndpointWithName(ctx, helper, ksSvc["name"], instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
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
}
util.LogForObject(helper, "Removed finalizer from KeystoneEndpoint", instance)
}

keystoneService, err := keystonev1.GetKeystoneServiceWithName(ctx, helper, ksSvc["name"], instance.Namespace)
if err != nil && !k8s_errors.IsNotFound(err) {
return ctrl.Result{}, err
}
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
}
util.LogForObject(helper, "Removed finalizer from our KeystoneService", instance)
}
}

// Service is deleted so remove the finalizer.
controllerutil.RemoveFinalizer(instance, helper.GetFinalizer())
r.Log.Info("Reconciled API delete successfully")
r.Log.Info("Reconciled Engine delete successfully")

return ctrl.Result{}, nil
}
Expand Down

0 comments on commit 08527f0

Please sign in to comment.