Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix lookup of backup objects in the cluster #1033

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions tembo-operator/src/cloudnativepg/retention/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,32 @@ pub async fn cleanup_old_volume_snapshots(
"Starting cleanup of old volume snapshots for instance: {}", name
);

// List only volume snapshot backups
let lp = ListParams::default().fields(&format!("spec.method={}", BackupMethod::VolumeSnapshot));

// List all backups in the namespace
let backups = backups_api
.list(&lp)
// List all backups and filter in memory
let all_backups = backups_api
.list(&ListParams::default())
.await
.map_err(|e| {
error!("Failed to list backups in namespace {}: {}", namespace, e);
error!(
error = %e,
namespace = %namespace,
"Failed to list backups"
);
Action::requeue(tokio::time::Duration::from_secs(300))
})?
.items;

// Filter to only volume snapshot backups
let volume_snapshot_backups: Vec<_> = all_backups
.into_iter()
.filter(|b| matches!(b.spec.method.as_ref(), Some(BackupMethod::VolumeSnapshot)))
.collect();

debug!(
backup_count = backups.len(),
backup_count = volume_snapshot_backups.len(),
"Found volume snapshot backups to evaluate for instance: {}", name
);

for backup in backups {
for backup in volume_snapshot_backups {
if should_delete_backup(&backup, cutoff_time) {
delete_backup_and_snapshot(&backups_api, &snapshots_api, &backup, namespace).await?;
}
Expand Down
Loading