Skip to content

Commit

Permalink
With status as patch and get
Browse files Browse the repository at this point in the history
  • Loading branch information
hjkatz committed Dec 19, 2024
1 parent da0caa7 commit 663a3c2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/controller/base_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 663a3c2

Please sign in to comment.