Skip to content

Commit 5c50ea9

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 4d837e7 commit 5c50ea9

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
@@ -634,6 +634,16 @@ func (r *resourceReconciler) createResource(
634634
latest, err = rm.Create(ctx, desired)
635635
rlog.Exit("rm.Create", err)
636636
if err != nil {
637+
// Here we're deciding to set a resource as unmanaged
638+
// if the error is an AWS API Error. This will ensure
639+
// that we're only managing (put finalizer) the resources
640+
// that actually exist in AWS.
641+
if _, ok := ackerr.AWSError(err); ok {
642+
mErr := r.setResourceUnmanaged(ctx, rm, desired)
643+
if mErr != nil {
644+
return latest, err
645+
}
646+
}
637647
return latest, err
638648
}
639649

0 commit comments

Comments
 (0)