mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-19 22:44:21 +00:00
fix(cli): show n/a for expiration on stalled New backups (#10326)
Backups stuck in New state have no Status.Expiration yet. The CLI was estimating expiration from CreationTimestamp + TTL, which made long-queued backups appear already expired. Fixes #3555 Signed-off-by: PranjalManhgaye <manhgayepranjal@gmail.com>
This commit is contained in:
@@ -90,8 +90,12 @@ func printBackup(backup *velerov1api.Backup) []metav1.TableRow {
|
||||
if backup.Status.Expiration != nil {
|
||||
expiration = backup.Status.Expiration.Time
|
||||
}
|
||||
if expiration.IsZero() && backup.Spec.TTL.Duration > 0 {
|
||||
expiration = backup.CreationTimestamp.Add(backup.Spec.TTL.Duration)
|
||||
// Only estimate expiration from TTL after the backup has started. Backups
|
||||
// stalled in New have no Status.Expiration yet; using CreationTimestamp
|
||||
// would incorrectly show them as already expired (issue #3555).
|
||||
if expiration.IsZero() && backup.Spec.TTL.Duration > 0 &&
|
||||
backup.Status.StartTimestamp != nil && !backup.Status.StartTimestamp.Time.IsZero() {
|
||||
expiration = backup.Status.StartTimestamp.Time.Add(backup.Spec.TTL.Duration)
|
||||
}
|
||||
|
||||
status := string(backup.Status.Phase)
|
||||
|
||||
@@ -76,6 +76,26 @@ func TestPrintBackupWithoutStartTimestamp(t *testing.T) {
|
||||
assert.Equal(t, string(velerov1api.BackupPhaseFailedValidation), rows[0].Cells[1])
|
||||
}
|
||||
|
||||
func TestPrintBackupExpiresForStalledNewBackup(t *testing.T) {
|
||||
created := metav1.NewTime(time.Now().Add(-20 * 24 * time.Hour))
|
||||
backup := &velerov1api.Backup{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "clusterstate-20210128123759",
|
||||
CreationTimestamp: created,
|
||||
},
|
||||
Spec: velerov1api.BackupSpec{
|
||||
TTL: metav1.Duration{Duration: 10 * 24 * time.Hour},
|
||||
},
|
||||
Status: velerov1api.BackupStatus{
|
||||
Phase: velerov1api.BackupPhaseNew,
|
||||
},
|
||||
}
|
||||
|
||||
rows := printBackup(backup)
|
||||
require.Len(t, rows, 1)
|
||||
assert.Equal(t, "n/a", rows[0].Cells[5], "stalled New backup should not show expiration in the past")
|
||||
}
|
||||
|
||||
func TestPrintBackupWithStartTimestamp(t *testing.T) {
|
||||
started := metav1.NewTime(time.Date(2026, 8, 8, 21, 6, 28, 0, time.UTC))
|
||||
backup := &velerov1api.Backup{
|
||||
|
||||
Reference in New Issue
Block a user