From 663a3c21b3811c086d7c7a7e61db37a3830a9c6a Mon Sep 17 00:00:00 2001 From: Harrison Katz Date: Thu, 19 Dec 2024 11:26:07 -0500 Subject: [PATCH] With status as patch and get --- internal/controller/base_controller.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/controller/base_controller.go b/internal/controller/base_controller.go index cb538477..3124f093 100644 --- a/internal/controller/base_controller.go +++ b/internal/controller/base_controller.go @@ -141,7 +141,14 @@ func (self *BaseController[T]) handleErr(op BaseControllerOp, obj T, err error) func (self *BaseController[T]) ReconcileStatus(ctx context.Context, obj T, origErr error) error { log := ctrl.LoggerFrom(ctx).WithValues("originalError", origErr) - if err := self.Kube.Status().Patch(ctx, obj, client.MergeFrom(obj)); err != nil { + var currentObj T + if err := self.Kube.Get(ctx, client.ObjectKeyFromObject(obj), currentObj); err != nil { + self.Recorder.Event(obj, v1.EventTypeWarning, "StatusError", fmt.Sprintf("Failed to retrieve existing object for status update: %s", err.Error())) + log.V(1).Error(err, "Failed to retrieve existing object for status update") + return StatusError{origErr, err} + } + + if err := self.Kube.Status().Patch(ctx, obj, client.MergeFrom(currentObj)); err != nil { self.Recorder.Event(obj, v1.EventTypeWarning, "StatusError", fmt.Sprintf("Failed to reconcile status: %s", err.Error())) log.V(1).Error(err, "Failed to patch status") return StatusError{origErr, err}