From 99f59696880cb3ca86b94d1d0825da5ada8b9098 Mon Sep 17 00:00:00 2001 From: srteam2020 Date: Sat, 12 Jun 2021 11:17:00 -0500 Subject: [PATCH] Fix-118: Check UID before deleting PVC --- .../pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go | 6 +++++- operator/pkg/reconciliation/reconcile_datacenter.go | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go index 460243890..e2dab8b6c 100644 --- a/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/operator/pkg/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -22,6 +22,9 @@ const ( // DatacenterLabel is the operator's label for the datacenter name DatacenterLabel = "cassandra.datastax.com/datacenter" + // DatacenterUID is the operator's label for datacenter UID + DatacenterUID = "cassandra.datastax.com/datacenterUID" + // SeedNodeLabel is the operator's label for the seed node state SeedNodeLabel = "cassandra.datastax.com/seed-node" @@ -102,7 +105,7 @@ type CassandraDatacenterSpec struct { // }, // "jmv-options": { // "max_heap_size": 1024M - // } + // } // } // // ConfigSecret is mutually exclusive with Config. ConfigSecret takes precedence and @@ -514,6 +517,7 @@ func (dc *CassandraDatacenter) SetCondition(condition DatacenterCondition) { func (dc *CassandraDatacenter) GetDatacenterLabels() map[string]string { labels := dc.GetClusterLabels() labels[DatacenterLabel] = dc.Name + labels[DatacenterUID] = string(dc.UID) return labels } diff --git a/operator/pkg/reconciliation/reconcile_datacenter.go b/operator/pkg/reconciliation/reconcile_datacenter.go index 5e5b82e07..badfec3f3 100644 --- a/operator/pkg/reconciliation/reconcile_datacenter.go +++ b/operator/pkg/reconciliation/reconcile_datacenter.go @@ -98,6 +98,7 @@ func (rc *ReconciliationContext) listPVCs() (*corev1.PersistentVolumeClaimList, selector := map[string]string{ api.DatacenterLabel: rc.Datacenter.Name, + api.DatacenterUID: string(rc.Datacenter.UID), } listOptions := &client.ListOptions{