Skip to content

Commit

Permalink
fix finalizer removal ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
Berk Dehrioglu committed Nov 7, 2023
1 parent 07fc982 commit 3044e55
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions controllers/awsmachinetemplate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,34 @@ func (r *AWSMachineTemplateReconciler) reconcileDelete(ctx context.Context, iamS
}
}
}

cm := &corev1.ConfigMap{}
err = r.Get(
ctx,
types.NamespacedName{
Namespace: namespace,
Name: fmt.Sprintf("%s-%s", clusterName, "cluster-values"),
},
cm)
if err != nil {
logger.Error(err, "Failed to get the cluster-values configmap for cluster")
return ctrl.Result{}, errors.WithStack(err)
}

if controllerutil.ContainsFinalizer(cm, key.FinalizerName(iam.ControlPlaneRole)) {
patchHelper, err := patch.NewHelper(cm, r.Client)
if err != nil {
return ctrl.Result{}, errors.WithStack(err)
}
controllerutil.RemoveFinalizer(cm, key.FinalizerName(iam.ControlPlaneRole))
err = patchHelper.Patch(ctx, cm)
if err != nil {
logger.Error(err, "failed to remove finalizer from configmap")
return ctrl.Result{}, errors.WithStack(err)
}
logger.Info("successfully removed finalizer from configmap", "finalizer_name", iam.ControlPlaneRole)
}

// remove finalizer from AWSCluster
{
awsCluster, err := key.GetAWSClusterByName(ctx, r.Client, clusterName, awsMachineTemplate.GetNamespace())
Expand Down Expand Up @@ -198,33 +226,6 @@ func (r *AWSMachineTemplateReconciler) reconcileDelete(ctx context.Context, iamS
logger.Info("successfully removed finalizer from AWSMachineTemplate", "finalizer_name", iam.ControlPlaneRole)
}

cm := &corev1.ConfigMap{}
err = r.Get(
ctx,
types.NamespacedName{
Namespace: namespace,
Name: fmt.Sprintf("%s-%s", clusterName, "cluster-values"),
},
cm)
if err != nil {
logger.Error(err, "Failed to get the cluster-values configmap for cluster")
return ctrl.Result{}, errors.WithStack(err)
}

if controllerutil.ContainsFinalizer(cm, key.FinalizerName(iam.ControlPlaneRole)) {
patchHelper, err := patch.NewHelper(cm, r.Client)
if err != nil {
return ctrl.Result{}, errors.WithStack(err)
}
controllerutil.RemoveFinalizer(cm, key.FinalizerName(iam.ControlPlaneRole))
err = patchHelper.Patch(ctx, cm)
if err != nil {
logger.Error(err, "failed to remove finalizer from configmap")
return ctrl.Result{}, errors.WithStack(err)
}
logger.Info("successfully removed finalizer from configmap", "finalizer_name", iam.ControlPlaneRole)
}

return ctrl.Result{}, nil
}

Expand Down

0 comments on commit 3044e55

Please sign in to comment.