Skip to content

Commit d746135

Browse files
author
Cecile Robert-Michon
committed
Don't delete AzureIdentities from other Clusters
1 parent d6a8184 commit d746135

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

controllers/azureidentity_controller.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333
apierrors "k8s.io/apimachinery/pkg/api/errors"
3434
"k8s.io/client-go/tools/record"
3535
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha4"
36-
"sigs.k8s.io/cluster-api-provider-azure/util/identity"
3736
"sigs.k8s.io/cluster-api-provider-azure/util/reconciler"
3837
"sigs.k8s.io/cluster-api-provider-azure/util/system"
3938
"sigs.k8s.io/cluster-api-provider-azure/util/tele"
@@ -101,7 +100,7 @@ func (r *AzureIdentityReconciler) SetupWithManager(ctx context.Context, mgr ctrl
101100
func (r *AzureIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
102101
ctx, cancel := context.WithTimeout(ctx, reconciler.DefaultedLoopTimeout(r.ReconcileTimeout))
103102
defer cancel()
104-
log := r.Log.WithValues("namespace", req.Namespace, "azureIdentity", req.Name)
103+
log := r.Log.WithValues("namespace", req.Namespace, "identityOwner", req.Name)
105104

106105
ctx, span := tele.Tracer().Start(ctx, "controllers.AzureIdentityReconciler.Reconcile",
107106
trace.WithAttributes(
@@ -112,7 +111,7 @@ func (r *AzureIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Reques
112111
defer span.End()
113112

114113
// identityOwner is the resource that created the identity. This could be either an AzureCluster or AzureManagedControlPlane (if AKS is enabled).
115-
// check for AzureManagedControlPlane first and if it is not found, check for AzureManagedControlPlane.
114+
// check for AzureCluster first and if it is not found, check for AzureManagedControlPlane.
116115
var identityOwner interface{}
117116

118117
// Fetch the AzureCluster instance
@@ -158,7 +157,6 @@ func (r *AzureIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Reques
158157
clusterNamespace := binding.ObjectMeta.Labels[infrav1.ClusterLabelNamespace]
159158

160159
key := client.ObjectKey{Name: clusterName, Namespace: clusterNamespace}
161-
var expectedIdentityName string
162160

163161
// only delete bindings when the identity owner type is not found.
164162
// we should not delete an identity when azureCluster is not found because it could have been created by AzureManagedControlPlane.
@@ -173,7 +171,6 @@ func (r *AzureIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Reques
173171
return ctrl.Result{}, errors.Wrap(err, "failed to get AzureCluster")
174172
}
175173
}
176-
expectedIdentityName = identity.GetAzureIdentityName(azCluster.Name, azCluster.Namespace, azCluster.Spec.IdentityRef.Name)
177174
case infraexpv1.AzureManagedControlPlane:
178175
azManagedControlPlane := &infraexpv1.AzureManagedControlPlane{}
179176
if err := r.Get(ctx, key, azManagedControlPlane); err != nil {
@@ -184,12 +181,6 @@ func (r *AzureIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Reques
184181
return ctrl.Result{}, errors.Wrap(err, "failed to get AzureManagedControlPlane")
185182
}
186183
}
187-
expectedIdentityName = identity.GetAzureIdentityName(azManagedControlPlane.Name, azManagedControlPlane.Namespace,
188-
azManagedControlPlane.Spec.IdentityRef.Name)
189-
}
190-
191-
if binding.Spec.AzureIdentity != expectedIdentityName {
192-
bindingsToDelete = append(bindingsToDelete, b)
193184
}
194185
}
195186

0 commit comments

Comments
 (0)