Skip to content

Commit 30afbb6

Browse files
authored
attempt to patchStatus regardless of finalizer (#64)
Description of changes: * ACK reconciler marks a resource as `Managed` before performing the `CREATE` call * ResourceReference in ACK reconciler is resolved before `READ_ONE` call which precedes `CREATE` call * When ResourceReference resolution fails, ACK reconciler needs to set `Status.Condition` indicating reference resolution failed * Hence the status patching needs to be done for unmanaged resources too * `NotFound` error while status patching of deleted resource is caught and not logged in controller logs By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent dff8696 commit 30afbb6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pkg/runtime/reconciler.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -507,12 +507,15 @@ func (r *resourceReconciler) patchResourceStatus(
507507
latest.RuntimeObject(),
508508
client.MergeFrom(desired.DeepCopy().RuntimeObject()),
509509
)
510-
rlog.Exit("kc.Patch (status)", err)
511-
if err != nil {
512-
return err
510+
if err == nil {
511+
rlog.Debug("patched resource status")
512+
} else if apierrors.IsNotFound(err) {
513+
// reset the NotFound error so it is not printed in controller logs
514+
// providing false positive error
515+
err = nil
513516
}
514-
rlog.Debug("patched resource status", "latest", latest)
515-
return nil
517+
rlog.Exit("kc.Patch (status)", err)
518+
return err
516519
}
517520

518521
// deleteResource ensures that the supplied AWSResource's backing API resource
@@ -714,15 +717,17 @@ func (r *resourceReconciler) HandleReconcileError(
714717
latest acktypes.AWSResource,
715718
err error,
716719
) (ctrlrt.Result, error) {
717-
if ackcompare.IsNotNil(latest) && r.rd.IsManaged(latest) {
720+
if ackcompare.IsNotNil(latest) {
718721
// The reconciliation loop may have returned an error, but if latest is
719722
// not nil, there may be some changes available in the CR's Status
720723
// struct (example: Conditions), and we want to make sure we save those
721724
// changes before proceeding
722725
//
723-
// Attempt to patch the status only if the resource is managed.
724-
// Otherwise, the underlying K8s resource gets deleted and
725-
// patchStatus call will return NotFound error
726+
// PatchStatus even when resource is unmanaged. This helps in setting
727+
// conditions when resolving resource-reference fails, which happens
728+
// before resource is marked as managed.
729+
// It is okay to patch status when resource is not present due to deletion
730+
// because a NotFound error is thrown which will be ignored.
726731
//
727732
// TODO(jaypipes): We ignore error handling here but I don't know if
728733
// there is a more robust way to handle failures in the patch operation

0 commit comments

Comments
 (0)