@@ -303,18 +303,21 @@ func (r *resourceReconciler) handleCacheError(
303303 return r .HandleReconcileError (ctx , desired , latest , requeue .NeededAfter (err , roleARNNotAvailableRequeueDelay ))
304304}
305305
306+ // Handles the population of ACK Resource fields from annotation.
306307func (r * resourceReconciler ) handlePopulation (
307308 rlog acktypes.Logger ,
308309 desired acktypes.AWSResource ,
309310 adoptionPolicy AdoptionPolicy ,
310311) (acktypes.AWSResource , error ) {
311312 // If the resource is being adopted by force, we need to access
312313 // the required field passed by annotation and attempt a read.
313-
314- rlog .Info ("Adopting Resource" )
314+ rlog .Debug ("Populating Resource" )
315315 adoptionFields , err := ExtractAdoptionFields (desired )
316316 if err != nil {
317- if adoptionPolicy == AdoptOrCreatePolicy {
317+ // if the user does not provide adoption fields and the policy
318+ // is adopt-or-create, we will assume the adoption fields are passed
319+ // in Spec
320+ if adoptionPolicy == AdoptionPolicy_AdoptOrCreate {
318321 return desired , nil
319322 }
320323 return desired , ackerr .NewTerminalError (err )
@@ -323,9 +326,10 @@ func (r *resourceReconciler) handlePopulation(
323326 populated := desired .DeepCopy ()
324327 err = populated .PopulateResourceFromAnnotation (adoptionFields )
325328 // maybe don't return errors when it's adopt-or-create?
329+ //
326330 // TODO (michaelhtm) change PopulateResourceFromAnnotation to understand
327331 // adopt-or-create, and validate Spec fields are not nil...
328- if err != nil && adoptionPolicy != AdoptOrCreatePolicy {
332+ if err != nil && adoptionPolicy != AdoptionPolicy_AdoptOrCreate {
329333 return nil , err
330334 }
331335
@@ -398,7 +402,8 @@ func (r *resourceReconciler) Sync(
398402 isAdopted := IsAdopted (desired )
399403 rlog .WithValues ("is_adopted" , isAdopted )
400404
401- // find out if we need to adopt early on
405+ // If AdoptionAnnotation feature gate is enabled, and the resource has an adoption
406+ // annotation and doesn't hold an ACK finalizer, trigger the adoption path.
402407 needAdoption := NeedAdoption (desired ) && ! r .rd .IsManaged (desired ) && r .cfg .FeatureGates .IsEnabled (featuregate .ResourceAdoption )
403408 adoptionPolicy , err := GetAdoptionPolicy (desired )
404409 if err != nil {
@@ -430,7 +435,7 @@ func (r *resourceReconciler) Sync(
430435 if err != nil {
431436 return nil , err
432437 }
433- if adoptionPolicy == AdoptOrCreatePolicy {
438+ if adoptionPolicy == AdoptionPolicy_AdoptOrCreate {
434439 // here we assume the spec fields are provided in the spec.
435440 resolved .SetStatus (populated )
436441 } else {
@@ -454,7 +459,7 @@ func (r *resourceReconciler) Sync(
454459 if err != ackerr .NotFound {
455460 return latest , err
456461 }
457- if adoptionPolicy == AdoptPolicy || isAdopted {
462+ if adoptionPolicy == AdoptionPolicy_Adopt || isAdopted {
458463 return nil , ackerr .AdoptedResourceNotFound
459464 }
460465 if isReadOnly {
@@ -463,7 +468,7 @@ func (r *resourceReconciler) Sync(
463468 if latest , err = r .createResource (ctx , rm , resolved ); err != nil {
464469 return latest , err
465470 }
466- } else if adoptionPolicy == AdoptPolicy {
471+ } else if adoptionPolicy == AdoptionPolicy_Adopt {
467472 rm .FilterSystemTags (latest )
468473 if err = r .setResourceManaged (ctx , rm , latest ); err != nil {
469474 return latest , err
@@ -473,7 +478,9 @@ func (r *resourceReconciler) Sync(
473478 return latest , err
474479 }
475480 } else if ! isReadOnly {
476- if adoptionPolicy == AdoptOrCreatePolicy {
481+ if adoptionPolicy == AdoptionPolicy_AdoptOrCreate {
482+ // set adopt-or-create resource as managed before attempting
483+ // update
477484 if err = r .setResourceManaged (ctx , rm , latest ); err != nil {
478485 return latest , err
479486 }
0 commit comments