@@ -63,22 +63,32 @@ var (
6363)
6464
6565// ReplicatedBackups implements sort.Interface for []ReplicatedBackup based on the
66- // CreationTimestamp of the infrastructure backup.
66+ // Status.StartTimestamp of the infrastructure backup.
6767type ReplicatedBackups []ReplicatedBackup
6868
6969func (a ReplicatedBackups ) Len () int { return len (a ) }
7070func (a ReplicatedBackups ) Swap (i , j int ) { a [i ], a [j ] = a [j ], a [i ] }
7171func (a ReplicatedBackups ) Less (i , j int ) bool {
7272 var iTime , jTime time.Time
73- if a [i ].GetInfraBackup () != nil {
74- iTime = a [i ].GetInfraBackup ().GetCreationTimestamp ().Time
75- } else if len (a [i ]) > 0 {
76- iTime = a [i ][0 ].GetCreationTimestamp ().Time
73+ if a [i ].GetInfraBackup () != nil && a [i ].GetInfraBackup ().Status .StartTimestamp != nil {
74+ iTime = a [i ].GetInfraBackup ().Status .StartTimestamp .Time
75+ } else {
76+ for _ , backup := range a [i ] {
77+ if backup .Status .StartTimestamp != nil {
78+ iTime = backup .Status .StartTimestamp .Time
79+ break
80+ }
81+ }
7782 }
78- if a [j ].GetInfraBackup () != nil {
79- jTime = a [j ].GetInfraBackup ().GetCreationTimestamp ().Time
80- } else if len (a [j ]) > 0 {
81- jTime = a [j ][0 ].GetCreationTimestamp ().Time
83+ if a [j ].GetInfraBackup () != nil && a [j ].GetInfraBackup ().Status .StartTimestamp != nil {
84+ jTime = a [j ].GetInfraBackup ().Status .StartTimestamp .Time
85+ } else {
86+ for _ , backup := range a [j ] {
87+ if backup .Status .StartTimestamp != nil {
88+ jTime = backup .Status .StartTimestamp .Time
89+ break
90+ }
91+ }
8292 }
8393 return iTime .Before (jTime )
8494}
@@ -181,18 +191,22 @@ func (b ReplicatedBackup) GetRestore() (*velerov1.Restore, error) {
181191 return nil , fmt .Errorf ("missing restore spec annotation" )
182192}
183193
184- // GetCreationTimestamp returns the creation timestamp of the velero infra backup object or the
185- // first backup in the slice if the infra backup is not found.
186- func ( b ReplicatedBackup ) GetCreationTimestamp () metav1. Time {
187- backup := b . GetInfraBackup ()
188- if backup != nil {
189- return backup . GetCreationTimestamp ()
194+ // GetCompletionTimestamp returns the completion timestamp of the last velero backup to be
195+ // completed or zero if the expected backup count is not met or any of the backups in the slice is
196+ // not completed.
197+ func ( b ReplicatedBackup ) GetCompletionTimestamp () metav1. Time {
198+ if b . GetExpectedBackupCount () != len ( b ) {
199+ return metav1. Time {}
190200 }
191- // if the infra backup is not found, we return the creation timestamp of the first backup
201+ var completionTimestamp metav1. Time
192202 for _ , backup := range b {
193- return backup .GetCreationTimestamp ()
203+ if backup .Status .CompletionTimestamp == nil {
204+ return metav1.Time {}
205+ } else if backup .Status .CompletionTimestamp .Time .After (completionTimestamp .Time ) {
206+ completionTimestamp = * backup .Status .CompletionTimestamp
207+ }
194208 }
195- return metav1. Time {}
209+ return completionTimestamp
196210}
197211
198212// GetAnnotation returns the value of the specified annotation key from the velero infra backup
0 commit comments