@@ -140,6 +140,8 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile
140140 if apierrors .IsNotFound (err ) {
141141 // Object not found, return. Created objects are automatically garbage collected.
142142 // For additional cleanup logic use finalizers.
143+ log .Info ("Provider not found, skipping reconciliation" )
144+
143145 return ctrl.Result {}, nil
144146 }
145147 // Error reading the object - requeue the request.
@@ -167,12 +169,16 @@ func (r *GenericProviderReconciler) Reconcile(ctx context.Context, req reconcile
167169
168170 // Add finalizer first if not exist to avoid the race condition between init and delete
169171 if ! controllerutil .ContainsFinalizer (r .Provider , operatorv1 .ProviderFinalizer ) {
172+ log .Info ("Adding finalizer, requeueing" )
170173 controllerutil .AddFinalizer (r .Provider , operatorv1 .ProviderFinalizer )
174+
171175 return ctrl.Result {}, nil
172176 }
173177
174178 // Handle deletion reconciliation loop.
175179 if ! r .Provider .GetDeletionTimestamp ().IsZero () {
180+ log .Info ("Provider marked for deletion, entering delete reconciliation" )
181+
176182 res , err := r .reconcileDelete (ctx , r .Provider )
177183 if err != nil {
178184 return reconcile.Result {}, err
@@ -381,25 +387,17 @@ func addObjectToHash(hash hash.Hash, object interface{}) error {
381387
382388// providerHash calculates hash for provider and referenced objects.
383389func providerHash (ctx context.Context , client client.Client , hash hash.Hash , provider genericprovider.GenericProvider ) error {
384- log := log .FromContext (ctx )
385-
386390 err := addObjectToHash (hash , provider .GetSpec ())
387391 if err != nil {
388- log .Error (err , "failed to calculate provider hash" )
389-
390- return err
392+ return fmt .Errorf ("failed to calculate provider hash: %w" , err )
391393 }
392394
393395 if err := addConfigSecretToHash (ctx , client , hash , provider ); err != nil {
394- log .Error (err , "failed to calculate secret hash" )
395-
396- return err
396+ return fmt .Errorf ("failed to calculate secret hash: %w" , err )
397397 }
398398
399399 if err := addConfigMapToHash (ctx , client , hash , provider ); err != nil {
400- log .Error (err , "failed to calculate configmap hash" )
401-
402- return err
400+ return fmt .Errorf ("failed to calculate configmap hash: %w" , err )
403401 }
404402
405403 return nil
@@ -444,23 +442,17 @@ func (p *PhaseReconciler) ApplyFromCache(ctx context.Context) (*Result, error) {
444442 // secret does not exist, nothing to apply
445443 return & Result {}, nil
446444 } else if err != nil {
447- log .Error (err , "failed to get provider cache" )
448-
449445 return & Result {}, fmt .Errorf ("failed to get provider cache: %w" , err )
450446 }
451447
452448 // calculate combined hash for provider and config map cache
453449 hash := sha256 .New ()
454450 if err := providerHash (ctx , p .ctrlClient , hash , p .provider ); err != nil {
455- log .Error (err , "failed to calculate provider hash" )
456-
457451 return & Result {}, err
458452 }
459453
460454 if err := addObjectToHash (hash , secret .Data ); err != nil {
461- log .Error (err , "failed to calculate config map hash" )
462-
463- return & Result {}, err
455+ return & Result {}, fmt .Errorf ("failed to calculate config map hash: %w" , err )
464456 }
465457
466458 data , err := os .ReadFile (configPath )
@@ -471,9 +463,7 @@ func (p *PhaseReconciler) ApplyFromCache(ctx context.Context) (*Result, error) {
471463 }
472464
473465 if err := addObjectToHash (hash , data ); err != nil {
474- log .Error (err , "failed to calculate clusterctl.yaml file hash" )
475-
476- return & Result {}, nil
466+ return & Result {}, err
477467 }
478468
479469 cacheHash := fmt .Sprintf ("%x" , hash .Sum (nil ))
@@ -499,8 +489,6 @@ func (p *PhaseReconciler) ApplyFromCache(ctx context.Context) (*Result, error) {
499489 compressed := secret .GetAnnotations ()[operatorv1 .CompressedAnnotation ] == operatorv1 .TrueValue
500490
501491 if err := p .applyManifestsFromData (ctx , secret .Data , compressed ); err != nil {
502- log .Error (err , "failed to apply objects from cache" )
503-
504492 return & Result {}, err
505493 }
506494
@@ -514,6 +502,8 @@ func (p *PhaseReconciler) ApplyFromCache(ctx context.Context) (*Result, error) {
514502func (p * PhaseReconciler ) applyManifestsFromData (ctx context.Context , data map [string ][]byte , compressed bool ) error {
515503 log := log .FromContext (ctx )
516504
505+ log .V (2 ).Info ("Applying manifests from cache" , "entries" , len (data ), "compressed" , compressed )
506+
517507 var errs []error
518508
519509 for _ , raw := range data {
@@ -524,18 +514,14 @@ func (p *PhaseReconciler) applyManifestsFromData(ctx context.Context, data map[s
524514
525515 manifest , err = decompressData (raw )
526516 if err != nil {
527- log .Error (err , "failed to decompress yaml" )
528-
529- return err
517+ return fmt .Errorf ("failed to decompress yaml: %w" , err )
530518 }
531519 }
532520
533521 var manifests []unstructured.Unstructured
534522
535523 if err := json .Unmarshal (manifest , & manifests ); err != nil {
536- log .Error (err , "failed to convert yaml to unstructured" )
537-
538- return err
524+ return fmt .Errorf ("failed to convert yaml to unstructured: %w" , err )
539525 }
540526
541527 for i := range manifests {
@@ -550,6 +536,8 @@ func (p *PhaseReconciler) applyManifestsFromData(ctx context.Context, data map[s
550536
551537// setCacheHash calculates current provider and secret hash, and updates it on the secret.
552538func setCacheHash (ctx context.Context , cl client.Client , provider genericprovider.GenericProvider ) error {
539+ log := log .FromContext (ctx )
540+
553541 secret := & corev1.Secret {}
554542 if err := cl .Get (ctx , client.ObjectKey {Name : ProviderCacheName (provider ), Namespace : provider .GetNamespace ()}, secret ); err != nil {
555543 return fmt .Errorf ("failed to get cache secret: %w" , err )
@@ -583,6 +571,8 @@ func setCacheHash(ctx context.Context, cl client.Client, provider genericprovide
583571
584572 cacheHash := fmt .Sprintf ("%x" , hash .Sum (nil ))
585573
574+ log .V (2 ).Info ("Setting cache hash" , "hash" , cacheHash , "provider" , provider .GetName ())
575+
586576 annotations := secret .GetAnnotations ()
587577 if annotations == nil {
588578 annotations = map [string ]string {}
0 commit comments