Skip to content

Commit

Permalink
use Patch to update .Status.CreatedAt in CreateOrUpdateMantleBackup rpc
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <[email protected]>
  • Loading branch information
ushitora-anqou committed Dec 5, 2024
1 parent 1b5e375 commit 36afb28
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions internal/controller/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,11 @@ func (s *SecondaryServer) CreateOrUpdateMantleBackup(
return nil, fmt.Errorf("CreateOrUpdate failed: %w", err)
}

// Update the status here because ctrl.CreateOrUpdate doesn't change the status.
if err := updateStatus(ctx, s.client, &backup, func() error {
backup.Status.CreatedAt = backupReceived.Status.CreatedAt
return nil
}); err != nil {
return nil, fmt.Errorf("updateStatus failed: %w", err)
// Use Patch here because updateStatus is likely to fail due to "the object has been modified" error.
newBackup := backup.DeepCopy()
newBackup.Status.CreatedAt = backupReceived.Status.CreatedAt
if err := s.client.Status().Patch(ctx, newBackup, client.MergeFrom(&backup)); err != nil {
return nil, fmt.Errorf("status patch failed: %w", err)
}

return &proto.CreateOrUpdateMantleBackupResponse{}, nil
Expand Down

0 comments on commit 36afb28

Please sign in to comment.