@@ -140,10 +140,10 @@ func (r *adoptionReconciler) reconcile(req ctrlrt.Request) error {
140140		return  nil 
141141	}
142142
143- 	return  r .sync (ctx , targetDescriptor , rm , res )
143+ 	return  r .Sync (ctx , targetDescriptor , rm , res )
144144}
145145
146- func  (r  * adoptionReconciler ) sync (
146+ func  (r  * adoptionReconciler ) Sync (
147147	ctx  context.Context ,
148148	targetDescriptor  acktypes.AWSResourceDescriptor ,
149149	rm  acktypes.AWSResourceManager ,
@@ -171,7 +171,10 @@ func (r *adoptionReconciler) sync(
171171		GenerateName :    rmo .GetGenerateName (),
172172	}
173173
174- 	desiredMetadata  :=  desired .Spec .Kubernetes .Metadata 
174+ 	var  desiredMetadata  * ackv1alpha1.PartialObjectMeta 
175+ 	if  desired .Spec .Kubernetes  !=  nil  {
176+ 		desiredMetadata  =  desired .Spec .Kubernetes .Metadata 
177+ 	}
175178
176179	// Attempt to use metadata values from the adopted resource target metadata 
177180	if  desiredMetadata  !=  nil  {
@@ -235,6 +238,7 @@ func (r *adoptionReconciler) sync(
235238		}
236239	}
237240
241+ 	// TODO(vijtrip2@): Should adopted resource be marked as managed earlier ? 
238242	if  err  :=  r .markManaged (ctx , desired ); err  !=  nil  {
239243		return  r .onError (ctx , desired , err )
240244	}
@@ -489,7 +493,7 @@ func (r *adoptionReconciler) getRegion(
489493// patchMetadataAndSpec patches the Metadata and Spec for AdoptedResource into 
490494// k8s. The adopted resource 'res' also gets updated with content returned from 
491495// apiserver. 
492- // TODO(vijat @): Refactor this and use single 'patchMetadataAndSpec' method 
496+ // TODO(vijtrip2 @): Refactor this and use single 'patchMetadataAndSpec' method 
493497// for reconciler and adoptionReconciler 
494498func  (r  * adoptionReconciler ) patchMetadataAndSpec (
495499	ctx  context.Context ,
@@ -511,7 +515,7 @@ func (r *adoptionReconciler) patchMetadataAndSpec(
511515
512516// patchStatus patches the Status for AdoptedResource into k8s. The adopted 
513517// resource 'res' also gets updated with the content returned from apiserver. 
514- // TODO(vijat@ ): Refactor this and use single 'patchStatus' method 
518+ // TODO(vijtrip2 ): Refactor this and use single 'patchStatus' method 
515519// for reconciler and adoptionReconciler 
516520func  (r  * adoptionReconciler ) patchStatus (
517521	ctx  context.Context ,
@@ -533,13 +537,31 @@ func NewAdoptionReconciler(
533537	metrics  * ackmetrics.Metrics ,
534538	cache  ackrtcache.Caches ,
535539) acktypes.Reconciler  {
540+ 	return  NewAdoptionReconcilerWithClient (sc , log , cfg , metrics , cache , nil , nil )
541+ }
542+ 
543+ // NewAdoptionReconcilerWithClient returns a new adoptionReconciler object with 
544+ // specified k8s client and Reader. Currently this function is used for testing 
545+ // purpose only because "adoptionReconciler" struct is not available outside 
546+ // 'runtime' package for dependency injection. 
547+ func  NewAdoptionReconcilerWithClient (
548+ 	sc  acktypes.ServiceController ,
549+ 	log  logr.Logger ,
550+ 	cfg  ackcfg.Config ,
551+ 	metrics  * ackmetrics.Metrics ,
552+ 	cache  ackrtcache.Caches ,
553+ 	kc  client.Client ,
554+ 	apiReader  client.Reader ,
555+ ) acktypes.AdoptedResourceReconciler  {
536556	return  & adoptionReconciler {
537557		reconciler : reconciler {
538- 			sc :      sc ,
539- 			log :     log .WithName ("adopted-reconciler" ),
540- 			cfg :     cfg ,
541- 			metrics : metrics ,
542- 			cache :   cache ,
558+ 			sc :        sc ,
559+ 			log :       log .WithName ("adopted-reconciler" ),
560+ 			cfg :       cfg ,
561+ 			metrics :   metrics ,
562+ 			cache :     cache ,
563+ 			kc :        kc ,
564+ 			apiReader : apiReader ,
543565		},
544566	}
545567}
0 commit comments