Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Fix #316 by labeling the cluster uid to each PVC (#322)
Browse files Browse the repository at this point in the history
Label the cassandracluster uid to the PVC and checks the uid before deleting PVC
  • Loading branch information
srteam2020 authored May 7, 2021
1 parent 8851139 commit 2b265f0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/cassandracluster/cassandra_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

var clusterName = "cassandra-demo"
var namespace = "ns"
var clusterUID = "cassandra-demo-uid"

var cc2Dcs = `
apiVersion: "db.orange.com/v1alpha1"
Expand Down Expand Up @@ -95,6 +96,8 @@ func HelperInitCluster(t *testing.T, name string) (*ReconcileCassandraCluster,
var cc api.CassandraCluster
yaml.Unmarshal(common.HelperLoadBytes(t, name), &cc)

cc.ObjectMeta.UID = types.UID(clusterUID) // Set default UID for cc

ccList := api.CassandraClusterList{
TypeMeta: metav1.TypeMeta{
Kind: "CassandraClusterList",
Expand Down Expand Up @@ -220,6 +223,7 @@ func helperCreateCassandraCluster(t *testing.T, cassandraClusterFileName string)
"cassandraclusters.db.orange.com.rack": rack.Name,
"app": "cassandracluster",
"cassandracluster": cc.Name,
"cassandracluster-uid": string(cc.GetUID()),
},
},
Status: v1.PodStatus{
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/cassandracluster/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func TestGenerateCassandraStatefulSet(t *testing.T) {
assert.Equal(map[string]string{
"app": "cassandracluster",
"cassandracluster": "cassandra-demo",
"cassandracluster-uid": clusterUID,
"cassandraclusters.db.orange.com.dc": "dc1",
"cassandraclusters.db.orange.com.rack": "rack1",
"dc-rack": "dc1-rack1",
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/cassandracluster/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ func TestCheckNonAllowedChangesScaleDown(t *testing.T) {
Labels: map[string]string{
"app": "cassandracluster",
"cassandracluster": "cassandra-demo",
"cassandracluster-uid": clusterUID,
"cassandraclusters.db.orange.com.dc": "dc2",
"cassandraclusters.db.orange.com.rack": "rack1",
"cluster": "k8s.pic",
Expand Down
1 change: 1 addition & 0 deletions pkg/k8s/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func LabelsForCassandraDCRack(cc *api.CassandraCluster, dcName string, rackName
m := map[string]string{
"app": "cassandracluster",
"cassandracluster": cc.GetName(),
"cassandracluster-uid": string(cc.GetUID()),
"dc-rack": cc.GetDCRackName(dcName, rackName),
"cassandraclusters.db.orange.com.dc": dcName,
"cassandraclusters.db.orange.com.rack": rackName,
Expand Down

0 comments on commit 2b265f0

Please sign in to comment.