@@ -902,6 +902,10 @@ func createDeleteDataTasks(clusterName string, storageSpec crv1.PgStorageSpec, d
902902 }
903903 log .Debugf ("got %d cluster pods for %s\n " , len (pods .Items ), clusterName )
904904
905+ //a flag for the case when a cluster has performed an autofailover
906+ //we need to go back and remove the original primary's pgdata PVC
907+ originalClusterPrimaryDeleted := false
908+
905909 for _ , pod := range pods .Items {
906910 deploymentName := pod .ObjectMeta .Labels [util .LABEL_PG_CLUSTER ]
907911 if pod .ObjectMeta .Labels [util .LABEL_REPLICA_NAME ] != "" {
@@ -925,6 +929,9 @@ func createDeleteDataTasks(clusterName string, storageSpec crv1.PgStorageSpec, d
925929
926930 if v .VolumeSource .PersistentVolumeClaim != nil {
927931 log .Debugf ("volume [%s] pvc [%s] dataroots [%v]\n " , v .Name , v .VolumeSource .PersistentVolumeClaim .ClaimName , dataRoots )
932+ if clusterName == v .VolumeSource .PersistentVolumeClaim .ClaimName {
933+ originalClusterPrimaryDeleted = true
934+ }
928935 err := apiserver .CreateRMDataTask (storageSpec , clusterName , v .VolumeSource .PersistentVolumeClaim .ClaimName , dataRoots )
929936 if err != nil {
930937 return err
@@ -933,6 +940,16 @@ func createDeleteDataTasks(clusterName string, storageSpec crv1.PgStorageSpec, d
933940 }
934941 }
935942
943+ if originalClusterPrimaryDeleted == false {
944+ log .Debugf ("for autofailover case, removing orignal primary PVC %s" , clusterName )
945+ dataRoots := make ([]string , 0 )
946+ dataRoots = append (dataRoots , clusterName )
947+ err := apiserver .CreateRMDataTask (storageSpec , clusterName , clusterName , dataRoots )
948+ if err != nil {
949+ return err
950+ }
951+ }
952+
936953 if deleteBackups {
937954 log .Debug ("check for backup PVC to delete" )
938955 //get the deployment names for this cluster
0 commit comments