Skip to content

Commit 0de7612

Browse files
committed
OCPBUGS-88037: Set cluster ownership label on GCPCluster
Set the kubernetes-io-cluster-<infraID>=owned label on the GCPCluster object via AdditionalLabels so that CAPI-created GCP resources are visible to the installer's destroy logic. GCP label keys only permit lowercase letters, hyphens, and underscores. Also propagate user-defined resource labels from Infrastructure.Status.PlatformStatus.GCP.ResourceLabels and resource manager tags from GCP.ResourceTags to match MAPI behaviour. Without this label, 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 0de7612

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

  • pkg/controllers/infracluster

pkg/controllers/infracluster/gcp.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ func (r *InfraClusterController) ensureGCPCluster(ctx context.Context, log logr.
7373
return nil, fmt.Errorf("error obtaining GCP Provider Spec: %w", err)
7474
}
7575

76+
labels := gcpv1.Labels{}
77+
78+
if r.Infra.Status.PlatformStatus.GCP != nil {
79+
for _, l := range r.Infra.Status.PlatformStatus.GCP.ResourceLabels {
80+
labels[l.Key] = l.Value
81+
}
82+
}
83+
84+
labels[fmt.Sprintf("kubernetes-io-cluster-%s", r.Infra.Status.InfrastructureName)] = "owned"
85+
86+
var resourceManagerTags gcpv1.ResourceManagerTags
87+
88+
if r.Infra.Status.PlatformStatus.GCP != nil {
89+
for _, t := range r.Infra.Status.PlatformStatus.GCP.ResourceTags {
90+
resourceManagerTags = append(resourceManagerTags, gcpv1.ResourceManagerTag{
91+
ParentID: t.ParentID,
92+
Key: t.Key,
93+
Value: t.Value,
94+
})
95+
}
96+
}
97+
7698
target = &gcpv1.GCPCluster{
7799
ObjectMeta: metav1.ObjectMeta{
78100
Name: r.Infra.Status.InfrastructureName,
@@ -87,8 +109,10 @@ func (r *InfraClusterController) ensureGCPCluster(ctx context.Context, log logr.
87109
Network: gcpv1.NetworkSpec{
88110
Name: &providerSpec.NetworkInterfaces[0].Network,
89111
},
90-
Region: r.Infra.Status.PlatformStatus.GCP.Region,
91-
Project: gcpProjectID,
112+
Region: r.Infra.Status.PlatformStatus.GCP.Region,
113+
Project: gcpProjectID,
114+
AdditionalLabels: labels,
115+
ResourceManagerTags: resourceManagerTags,
92116
ControlPlaneEndpoint: clusterv1beta1.APIEndpoint{
93117
Host: apiURL.Hostname(),
94118
Port: int32(port),

0 commit comments

Comments
 (0)