From 36afb28f500403bfc8b46283b3d2bcfcbc1d1da8 Mon Sep 17 00:00:00 2001 From: Ryotaro Banno Date: Thu, 5 Dec 2024 06:19:03 +0000 Subject: [PATCH] use Patch to update .Status.CreatedAt in CreateOrUpdateMantleBackup rpc Signed-off-by: Ryotaro Banno --- internal/controller/replication.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/internal/controller/replication.go b/internal/controller/replication.go index eaee182c..57023d09 100644 --- a/internal/controller/replication.go +++ b/internal/controller/replication.go @@ -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