Skip to content

Commit 40f2bbb

Browse files
committed
fix: Remove Finalizer from resource if create returns error
The reason marking a resource as managed (putting the finalizer) before attempting a create is a general practice in kubernetes. The main reason we do it is to protect against deletion protection. If we don't put the finalizer, there is no deletion protection against the resource. The current adoption logic expects the resource to not be managed (no finalizer) to trigger an adoption. If the initial creation attempt of a resource fails due to any AWS error, any subsequent reconciliations attempting to adopt an existing resource will not succeed. These changes set the resource as unmanaged if for any reason there is an error during the create call, which will allow the adoption logic to run in subsequent reconciliations.
1 parent dc7be0d commit 40f2bbb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/runtime/reconciler.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,16 @@ func (r *resourceReconciler) createResource(
638638
latest, err = rm.Create(ctx, desired)
639639
rlog.Exit("rm.Create", err)
640640
if err != nil {
641+
// Here we're deciding to set a resource as unmanaged
642+
// if the error is an AWS API Error. This will ensure
643+
// that we're only managing (put finalizer) the resources
644+
// that actually exist in AWS.
645+
if _, ok := ackerr.AWSError(err); ok {
646+
mErr := r.setResourceUnmanaged(ctx, rm, desired)
647+
if mErr != nil {
648+
return latest, err
649+
}
650+
}
641651
return latest, err
642652
}
643653

0 commit comments

Comments
 (0)