Skip to content

Commit 38fe985

Browse files
authored
Merge pull request #4221 from k8s-infra-cherrypick-robot/cherry-pick-4211-to-release-1.11
[release-1.11] eliminate short-circuiting in logic to add/remove finalizers
2 parents 80106bb + fbd9ad5 commit 38fe985

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

controllers/azuremanagedcontrolplane_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ func (amcpr *AzureManagedControlPlaneReconciler) reconcileNormal(ctx context.Con
226226
log.Info("Reconciling AzureManagedControlPlane")
227227

228228
// Remove deprecated Cluster finalizer if it exists, if the AzureManagedControlPlane doesn't have our finalizer, add it.
229-
if controllerutil.RemoveFinalizer(scope.ControlPlane, infrav1.ClusterFinalizer) ||
230-
controllerutil.AddFinalizer(scope.ControlPlane, infrav1.ManagedClusterFinalizer) {
229+
needsPatch := controllerutil.RemoveFinalizer(scope.ControlPlane, infrav1.ClusterFinalizer)
230+
needsPatch = controllerutil.AddFinalizer(scope.ControlPlane, infrav1.ManagedClusterFinalizer) || needsPatch
231+
if needsPatch {
231232
// Register the finalizer immediately to avoid orphaning Azure resources on delete
232233
if err := scope.PatchObject(ctx); err != nil {
233234
amcpr.Recorder.Eventf(scope.ControlPlane, corev1.EventTypeWarning, "AzureManagedControlPlane unavailable", "failed to patch resource: %s", err)

controllers/helpers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,9 @@ func EnsureClusterIdentity(ctx context.Context, c client.Client, object conditio
657657
}
658658

659659
// Remove deprecated finalizer if it exists, Register the finalizer immediately to avoid orphaning Azure resources on delete.
660-
if controllerutil.RemoveFinalizer(identity, deprecatedClusterIdentityFinalizer(finalizerPrefix, namespace, name)) ||
661-
controllerutil.AddFinalizer(identity, clusterIdentityFinalizer(finalizerPrefix, namespace, name)) {
660+
needsPatch := controllerutil.RemoveFinalizer(identity, deprecatedClusterIdentityFinalizer(finalizerPrefix, namespace, name))
661+
needsPatch = controllerutil.AddFinalizer(identity, clusterIdentityFinalizer(finalizerPrefix, namespace, name)) || needsPatch
662+
if needsPatch {
662663
// finalizers are added/removed then patch the object
663664
identityHelper, err := patch.NewHelper(identity, c)
664665
if err != nil {

0 commit comments

Comments
 (0)