Skip to content

Commit

Permalink
set .status.createdAt according to timestamp of the snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
  • Loading branch information
ushitora-anqou committed Aug 30, 2024
1 parent 26ba97c commit 3dc47d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/controller/mantlebackup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,12 @@ func (r *MantleBackupReconciler) Reconcile(ctx context.Context, req ctrl.Request
}
backup.Status.SnapID = snapshot.Id

backup.Status.CreatedAt = metav1.NewTime(time.Now())
createdAt, err := time.Parse("Mon Jan 02 15:04:05 2006", snapshot.Timestamp)
if err != nil {
return ctrl.Result{}, err
}
backup.Status.CreatedAt = metav1.NewTime(createdAt)

err = r.updateStatus(ctx, &backup, metav1.Condition{Type: mantlev1.BackupConditionReadyToUse, Status: metav1.ConditionTrue, Reason: mantlev1.BackupReasonNone})
if err != nil {
return ctrl.Result{}, err
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/mantlebackup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var _ = Describe("MantleBackup controller", func() {

executeCommand = func(command []string, _ io.Reader) ([]byte, error) {
if command[0] == "rbd" && command[1] == "snap" && command[2] == "ls" {
return []byte(fmt.Sprintf("[{\"id\":1000,\"name\":\"backup\"}]")), nil
return []byte(fmt.Sprintf("[{\"id\":1000,\"name\":\"backup\"," +
"\"timestamp\":\"Thu Aug 29 07:49:13 2024\"}]")), nil
}
return nil, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/mantlerestore_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (test *mantleRestoreControllerUnitTest) setupEnv() {
By("prepare MantleBackup reconciler")
executeCommand = func(command []string, _ io.Reader) ([]byte, error) {
if command[0] == "rbd" && command[1] == "snap" && command[2] == "ls" {
return []byte(fmt.Sprintf("[{\"id\":1000,\"name\":\"%s\"}]", test.backupName)), nil
return []byte(fmt.Sprintf("[{\"id\":1000,\"name\":\"%s\",\"timestamp\":\"Thu Aug 29 07:49:13 2024\"}]", test.backupName)), nil
}
return nil, nil
}
Expand Down

0 comments on commit 3dc47d7

Please sign in to comment.