Skip to content

Commit 57f24a7

Browse files
committed
OCPBUGS-88036: Set cluster ownership tag on AzureCluster
Set the kubernetes.io_cluster.<infraID>=owned tag on the AzureCluster object via AdditionalTags so that CAPI-created Azure resources are visible to the installer's destroy logic. Azure tag keys do not permit slashes, so underscores and a dot are used instead. Also propagate user-defined resource tags from Infrastructure.Status.PlatformStatus.Azure.ResourceTags to match MAPI behaviour. Without this tag, openshift-install destroy cluster cannot identify CAPI-created resources and they are leaked. Signed-off-by: Matthias Wessendorf <mwessend@redhat.com>
1 parent 05c113e commit 57f24a7

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

pkg/controllers/infracluster/azure.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ func (r *InfraClusterController) ensureAzureInfraCluster(ctx context.Context, ta
242242

243243
// createNewAzureCluster creates a new Azure Infra Cluster.
244244
func (r *InfraClusterController) newAzureCluster(providerSpec *mapiv1beta1.AzureMachineProviderSpec, apiURL *url.URL, port int32, location string) *azurev1.AzureCluster {
245+
tags := azurev1.Tags{}
246+
247+
if r.Infra.Status.PlatformStatus.Azure != nil {
248+
for _, t := range r.Infra.Status.PlatformStatus.Azure.ResourceTags {
249+
tags[t.Key] = t.Value
250+
}
251+
}
252+
253+
tags[fmt.Sprintf("kubernetes.io_cluster.%s", r.Infra.Status.InfrastructureName)] = "owned"
254+
245255
return &azurev1.AzureCluster{
246256
ObjectMeta: metav1.ObjectMeta{
247257
Name: r.Infra.Status.InfrastructureName,
@@ -257,6 +267,7 @@ func (r *InfraClusterController) newAzureCluster(providerSpec *mapiv1beta1.Azure
257267
AzureClusterClassSpec: azurev1.AzureClusterClassSpec{
258268
Location: location,
259269
AzureEnvironment: "AzurePublicCloud",
270+
AdditionalTags: tags,
260271
IdentityRef: &corev1.ObjectReference{
261272
Name: r.Infra.Status.InfrastructureName,
262273
Namespace: r.CAPINamespace,

0 commit comments

Comments
 (0)