From ae86b1a011cab790806d09cba4b0259368b9f95f Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Tue, 22 Nov 2022 12:09:24 +0900 Subject: [PATCH] Use the patch API instead to prevent unnecessary field updates (#1998) Fixes #1916 --- controllers/horizontal_runner_autoscaler_batch_scale.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controllers/horizontal_runner_autoscaler_batch_scale.go b/controllers/horizontal_runner_autoscaler_batch_scale.go index f6317ba5..e797da34 100644 --- a/controllers/horizontal_runner_autoscaler_batch_scale.go +++ b/controllers/horizontal_runner_autoscaler_batch_scale.go @@ -190,7 +190,7 @@ func (s *batchScaler) batchScale(ctx context.Context, batch batchScaleOperation) after := len(copy.Spec.CapacityReservations) s.Log.V(1).Info( - fmt.Sprintf("Updating hra %s for capacityReservations update", hra.Name), + fmt.Sprintf("Patching hra %s for capacityReservations update", hra.Name), "before", before, "expired", expired, "added", added, @@ -198,8 +198,8 @@ func (s *batchScaler) batchScale(ctx context.Context, batch batchScaleOperation) "after", after, ) - if err := s.Client.Update(ctx, copy); err != nil { - return fmt.Errorf("updating horizontalrunnerautoscaler to add capacity reservation: %w", err) + if err := s.Client.Patch(ctx, copy, client.MergeFrom(&hra)); err != nil { + return fmt.Errorf("patching horizontalrunnerautoscaler to add capacity reservation: %w", err) } return nil