diff --git a/pkg/runtime/reconciler.go b/pkg/runtime/reconciler.go index cc77b1f..169aff6 100644 --- a/pkg/runtime/reconciler.go +++ b/pkg/runtime/reconciler.go @@ -507,12 +507,15 @@ func (r *resourceReconciler) patchResourceStatus( latest.RuntimeObject(), client.MergeFrom(desired.DeepCopy().RuntimeObject()), ) - rlog.Exit("kc.Patch (status)", err) - if err != nil { - return err + if err == nil { + rlog.Debug("patched resource status") + } else if apierrors.IsNotFound(err) { + // reset the NotFound error so it is not printed in controller logs + // providing false positive error + err = nil } - rlog.Debug("patched resource status", "latest", latest) - return nil + rlog.Exit("kc.Patch (status)", err) + return err } // deleteResource ensures that the supplied AWSResource's backing API resource @@ -714,15 +717,17 @@ func (r *resourceReconciler) HandleReconcileError( latest acktypes.AWSResource, err error, ) (ctrlrt.Result, error) { - if ackcompare.IsNotNil(latest) && r.rd.IsManaged(latest) { + if ackcompare.IsNotNil(latest) { // The reconciliation loop may have returned an error, but if latest is // not nil, there may be some changes available in the CR's Status // struct (example: Conditions), and we want to make sure we save those // changes before proceeding // - // Attempt to patch the status only if the resource is managed. - // Otherwise, the underlying K8s resource gets deleted and - // patchStatus call will return NotFound error + // PatchStatus even when resource is unmanaged. This helps in setting + // conditions when resolving resource-reference fails, which happens + // before resource is marked as managed. + // It is okay to patch status when resource is not present due to deletion + // because a NotFound error is thrown which will be ignored. // // TODO(jaypipes): We ignore error handling here but I don't know if // there is a more robust way to handle failures in the patch operation