@@ -25,10 +25,12 @@ import (
2525 storagesnapshotv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
2626 corev1 "k8s.io/api/core/v1"
2727 apierrs "k8s.io/apimachinery/pkg/api/errors"
28+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2829 "k8s.io/apimachinery/pkg/runtime"
2930 "k8s.io/client-go/kubernetes"
3031 "k8s.io/client-go/tools/record"
3132 "k8s.io/client-go/util/retry"
33+ "k8s.io/utils/ptr"
3234 ctrl "sigs.k8s.io/controller-runtime"
3335 "sigs.k8s.io/controller-runtime/pkg/builder"
3436 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -322,6 +324,8 @@ func (r *BackupReconciler) startSnapshotBackup(
322324 backup .Status .SetAsStarted (targetPod , apiv1 .BackupMethodVolumeSnapshot )
323325 // given that we use only kubernetes resources we can use the backup name as ID
324326 backup .Status .BackupID = backup .Name
327+ backup .Status .BackupName = backup .Name
328+ backup .Status .StartedAt = ptr .To (metav1 .Now ())
325329 if err := postgres .PatchBackupStatusAndRetry (ctx , r .Client , backup ); err != nil {
326330 return nil , err
327331 }
@@ -375,10 +379,35 @@ func (r *BackupReconciler) startSnapshotBackup(
375379 }
376380
377381 backup .Status .BackupSnapshotStatus .SetSnapshotList (snapshots )
382+ if err := backupStatusFromSnapshots (snapshots , & backup .Status ); err != nil {
383+ contextLogger .Error (err , "while enriching the backup status" )
384+ }
378385
379386 return nil , postgres .PatchBackupStatusAndRetry (ctx , r .Client , backup )
380387}
381388
389+ // backupStatusFromSnapshots adds fields to the backup status based on the snapshots
390+ func backupStatusFromSnapshots (
391+ snapshots volumesnapshot.Slice ,
392+ backupStatus * apiv1.BackupStatus ,
393+ ) error {
394+ _ , lastCreation := snapshots .GetSnapshotsInterval ()
395+ backupStatus .StoppedAt = ptr .To (lastCreation )
396+ controldata , err := snapshots .GetControldata ()
397+ if err != nil {
398+ return err
399+ }
400+ pairs := utils .ParsePgControldataOutput (controldata )
401+
402+ // the begin/end WAL and LSN are the same, since the instance was fenced
403+ // for the snapshot
404+ backupStatus .BeginWal = pairs ["Latest checkpoint's REDO WAL file" ]
405+ backupStatus .EndWal = pairs ["Latest checkpoint's REDO WAL file" ]
406+ backupStatus .BeginLSN = pairs ["Latest checkpoint's REDO location" ]
407+ backupStatus .EndLSN = pairs ["Latest checkpoint's REDO location" ]
408+ return nil
409+ }
410+
382411// isErrorRetryable detects is an error is retryable or not
383412func isErrorRetryable (err error ) bool {
384413 return apierrs .IsServerTimeout (err ) || apierrs .IsConflict (err ) || apierrs .IsInternalError (err )
0 commit comments