@@ -11,12 +11,12 @@ import (
1111 barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command"
1212 barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials"
1313 cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
14+ "github.com/cloudnative-pg/machinery/pkg/log"
1415 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516 "k8s.io/apimachinery/pkg/types"
1617 "k8s.io/client-go/tools/record"
1718 "k8s.io/utils/ptr"
1819 "sigs.k8s.io/controller-runtime/pkg/client"
19- "sigs.k8s.io/controller-runtime/pkg/log"
2020
2121 barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1"
2222 "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common"
@@ -209,9 +209,12 @@ func deleteBackupsNotInCatalog(
209209 // A can violate 1 and 2
210210 // A + B can still violate 2
211211 // B satisfies 1 and 2
212-
212+ //
213213 // We chose to go with B
214214
215+ contextLogger := log .FromContext (ctx )
216+ contextLogger .Debug ("Checking the catalog to delete backups not present anymore" )
217+
215218 backups := cnpgv1.BackupList {}
216219 if err := cli .List (ctx , & backups , client .InNamespace (cluster .GetNamespace ())); err != nil {
217220 return fmt .Errorf ("while getting backups: %w" , err )
@@ -228,6 +231,7 @@ func deleteBackupsNotInCatalog(
228231 // here we could add further checks, e.g. if the backup is not found but would still
229232 // be in the retention policy we could either not delete it or update it is status
230233 if ! slices .Contains (backupIDs , backup .Status .BackupID ) {
234+ contextLogger .Info ("Deleting backup not in the catalog" , "backup" , backup .Name )
231235 if err := cli .Delete (ctx , & backups .Items [id ]); err != nil {
232236 errors = append (errors , fmt .Errorf (
233237 "while deleting backup %s/%s: %w" ,
@@ -248,7 +252,7 @@ func deleteBackupsNotInCatalog(
248252
249253// useSameBackupLocation checks whether the given backup was taken using the same configuration as provided
250254func useSameBackupLocation (backup * cnpgv1.BackupStatus , cluster * cnpgv1.Cluster ) bool {
251- if cluster . Spec . Backup == nil || backup .Method != cnpgv1 .BackupMethodPlugin {
255+ if backup .Method != cnpgv1 .BackupMethodPlugin {
252256 return false
253257 }
254258
0 commit comments