Skip to content

Commit e2ddec3

Browse files
committed
WIP: initial commit
1 parent 406e069 commit e2ddec3

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,7 @@ func (r *Reconciler) reconcileRepos(ctx context.Context,
27562756

27572757
errors := []error{}
27582758
errMsg := "reconciling repository volume"
2759-
repoVols := []*corev1.PersistentVolumeClaim{}
2759+
repoVols := make(map[string]*corev1.PersistentVolumeClaim)
27602760
var replicaCreateRepo v1beta1.PGBackRestRepo
27612761

27622762
if feature.Enabled(ctx, feature.AutoGrowVolumes) && pgbackrest.RepoHostVolumeDefined(postgresCluster) {
@@ -2783,16 +2783,15 @@ func (r *Reconciler) reconcileRepos(ctx context.Context,
27832783
// value to change later.
27842784
spec.Resources.Limits = nil
27852785

2786-
repo, err := r.applyRepoVolumeIntent(ctx, postgresCluster, spec,
2786+
repoPVC, err := r.applyRepoVolumeIntent(ctx, postgresCluster, spec,
27872787
repo.Name, repoResources)
27882788
if err != nil {
27892789
log.Error(err, errMsg)
27902790
errors = append(errors, err)
2791-
continue
2792-
}
2793-
if repo != nil {
2794-
repoVols = append(repoVols, repo)
27952791
}
2792+
// Store the repo volume after apply. If nil, that indicates a problem
2793+
// and the existing status should be preserved.
2794+
repoVols[repo.Name] = repoPVC
27962795
}
27972796

27982797
postgresCluster.Status.PGBackRest.Repos =
@@ -2990,19 +2989,26 @@ func getRepoHostStatus(repoHost *appsv1.StatefulSet) *v1beta1.RepoHostStatus {
29902989
// existing/current status for any repos in the cluster, the repository volumes
29912990
// (i.e. PVCs) reconciled for the cluster, and the hashes calculated for the configuration for any
29922991
// external repositories defined for the cluster.
2993-
func getRepoVolumeStatus(repoStatus []v1beta1.RepoStatus, repoVolumes []*corev1.PersistentVolumeClaim,
2992+
func getRepoVolumeStatus(repoStatus []v1beta1.RepoStatus, repoVolumes map[string]*corev1.PersistentVolumeClaim,
29942993
configHashes map[string]string, replicaCreateRepoName string) []v1beta1.RepoStatus {
29952994

29962995
// the new repository status that will be generated and returned
29972996
updatedRepoStatus := []v1beta1.RepoStatus{}
29982997

29992998
// Update the repo status based on the repo volumes (PVCs) that were reconciled. This includes
30002999
// updating the status for any existing repository volumes, and adding status for any new
3001-
// repository volumes.
3002-
for _, rv := range repoVolumes {
3000+
// repository volumes. If there was a problem with the volume when an apply was attempted,
3001+
// the existing status is preserved.
3002+
for repoName, rv := range repoVolumes {
30033003
newRepoVolStatus := true
3004-
repoName := rv.Labels[naming.LabelPGBackRestRepo]
30053004
for _, rs := range repoStatus {
3005+
// Preserve the previous status if it exists and the apply failed.
3006+
if rs.Name == repoName && rv == nil {
3007+
updatedRepoStatus = append(updatedRepoStatus, rs)
3008+
newRepoVolStatus = false
3009+
continue
3010+
}
3011+
30063012
// treat as new status if contains properties of a cloud (s3, gcr or azure) repo
30073013
if rs.Name == repoName && rs.RepoOptionsHash == "" {
30083014
newRepoVolStatus = false

0 commit comments

Comments
 (0)