From c0b1ac1acfa2113a00f2a6f962d48b4791634922 Mon Sep 17 00:00:00 2001 From: Marco Nenciarini Date: Fri, 14 Mar 2025 18:19:40 +0100 Subject: [PATCH] fix: missing backup pruning Signed-off-by: Marco Nenciarini --- internal/cnpgi/instance/retention.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/cnpgi/instance/retention.go b/internal/cnpgi/instance/retention.go index 4f66c98..31b9286 100644 --- a/internal/cnpgi/instance/retention.go +++ b/internal/cnpgi/instance/retention.go @@ -11,12 +11,12 @@ import ( barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command" barmanCredentials "github.com/cloudnative-pg/barman-cloud/pkg/credentials" cnpgv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1" + "github.com/cloudnative-pg/machinery/pkg/log" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/log" barmancloudv1 "github.com/cloudnative-pg/plugin-barman-cloud/api/v1" "github.com/cloudnative-pg/plugin-barman-cloud/internal/cnpgi/common" @@ -209,9 +209,12 @@ func deleteBackupsNotInCatalog( // A can violate 1 and 2 // A + B can still violate 2 // B satisfies 1 and 2 - + // // We chose to go with B + contextLogger := log.FromContext(ctx) + contextLogger.Debug("Checking the catalog to delete backups not present anymore") + backups := cnpgv1.BackupList{} if err := cli.List(ctx, &backups, client.InNamespace(cluster.GetNamespace())); err != nil { return fmt.Errorf("while getting backups: %w", err) @@ -228,6 +231,7 @@ func deleteBackupsNotInCatalog( // here we could add further checks, e.g. if the backup is not found but would still // be in the retention policy we could either not delete it or update it is status if !slices.Contains(backupIDs, backup.Status.BackupID) { + contextLogger.Info("Deleting backup not in the catalog", "backup", backup.Name) if err := cli.Delete(ctx, &backups.Items[id]); err != nil { errors = append(errors, fmt.Errorf( "while deleting backup %s/%s: %w", @@ -248,7 +252,7 @@ func deleteBackupsNotInCatalog( // useSameBackupLocation checks whether the given backup was taken using the same configuration as provided func useSameBackupLocation(backup *cnpgv1.BackupStatus, cluster *cnpgv1.Cluster) bool { - if cluster.Spec.Backup == nil || backup.Method != cnpgv1.BackupMethodPlugin { + if backup.Method != cnpgv1.BackupMethodPlugin { return false }