@@ -2743,7 +2743,7 @@ func (r *Reconciler) reconcileRepos(ctx context.Context,
27432743
27442744	errors  :=  []error {}
27452745	errMsg  :=  "reconciling repository volume" 
2746- 	repoVols  :=  [ ]* corev1.PersistentVolumeClaim {} 
2746+ 	repoVols  :=  make ( map [ string ]* corev1.PersistentVolumeClaim ) 
27472747	var  replicaCreateRepo  v1beta1.PGBackRestRepo 
27482748
27492749	if  feature .Enabled (ctx , feature .AutoGrowVolumes ) &&  pgbackrest .RepoHostVolumeDefined (postgresCluster ) {
@@ -2770,16 +2770,15 @@ func (r *Reconciler) reconcileRepos(ctx context.Context,
27702770		// value to change later. 
27712771		spec .Resources .Limits  =  nil 
27722772
2773- 		repo , err  :=  r .applyRepoVolumeIntent (ctx , postgresCluster , spec ,
2773+ 		repoPVC , err  :=  r .applyRepoVolumeIntent (ctx , postgresCluster , spec ,
27742774			repo .Name , repoResources )
27752775		if  err  !=  nil  {
27762776			log .Error (err , errMsg )
27772777			errors  =  append (errors , err )
2778- 			continue 
2779- 		}
2780- 		if  repo  !=  nil  {
2781- 			repoVols  =  append (repoVols , repo )
27822778		}
2779+ 		// Store the repo volume after apply. If nil, that indicates a problem 
2780+ 		// and the existing status should be preserved. 
2781+ 		repoVols [repo .Name ] =  repoPVC 
27832782	}
27842783
27852784	postgresCluster .Status .PGBackRest .Repos  = 
@@ -2977,19 +2976,26 @@ func getRepoHostStatus(repoHost *appsv1.StatefulSet) *v1beta1.RepoHostStatus {
29772976// existing/current status for any repos in the cluster, the repository volumes 
29782977// (i.e. PVCs) reconciled  for the cluster, and the hashes calculated for the configuration for any 
29792978// external repositories defined for the cluster. 
2980- func  getRepoVolumeStatus (repoStatus  []v1beta1.RepoStatus , repoVolumes  [ ]* corev1.PersistentVolumeClaim ,
2979+ func  getRepoVolumeStatus (repoStatus  []v1beta1.RepoStatus , repoVolumes  map [ string ]* corev1.PersistentVolumeClaim ,
29812980	configHashes  map [string ]string , replicaCreateRepoName  string ) []v1beta1.RepoStatus  {
29822981
29832982	// the new repository status that will be generated and returned 
29842983	updatedRepoStatus  :=  []v1beta1.RepoStatus {}
29852984
29862985	// Update the repo status based on the repo volumes (PVCs) that were reconciled.  This includes 
29872986	// updating the status for any existing repository volumes, and adding status for any new 
2988- 	// repository volumes. 
2989- 	for  _ , rv  :=  range  repoVolumes  {
2987+ 	// repository volumes. If there was a problem with the volume when an apply was attempted, 
2988+ 	// the existing status is preserved. 
2989+ 	for  repoName , rv  :=  range  repoVolumes  {
29902990		newRepoVolStatus  :=  true 
2991- 		repoName  :=  rv .Labels [naming .LabelPGBackRestRepo ]
29922991		for  _ , rs  :=  range  repoStatus  {
2992+ 			// Preserve the previous status if it exists and the apply failed. 
2993+ 			if  rs .Name  ==  repoName  &&  rv  ==  nil  {
2994+ 				updatedRepoStatus  =  append (updatedRepoStatus , rs )
2995+ 				newRepoVolStatus  =  false 
2996+ 				break 
2997+ 			}
2998+ 
29932999			// treat as new status if contains properties of a cloud (s3, gcr or azure) repo 
29943000			if  rs .Name  ==  repoName  &&  rs .RepoOptionsHash  ==  ""  {
29953001				newRepoVolStatus  =  false 
0 commit comments