@@ -412,16 +412,62 @@ func (m *MutationReconcileLooper) performLocalization(
412412 refPath []ocmmetav1.Identity ,
413413 compvers ocmcore.ComponentVersionAccess ,
414414) error {
415+ pRef , err := resolveReference (l , refPath , compvers , octx )
416+ if err != nil {
417+ return err
418+ }
419+
420+ if l .Registry != "" {
421+ if err := localizations .Add ("registry" , l .File , l .Registry , pRef .Context ().Registry .Name ()); err != nil {
422+ return fmt .Errorf ("failed to add registry: %w" , err )
423+ }
424+ }
425+
426+ if l .Repository != "" {
427+ if err := localizations .Add ("repository" , l .File , l .Repository , pRef .Context ().RepositoryStr ()); err != nil {
428+ return fmt .Errorf ("failed to add repository: %w" , err )
429+ }
430+ }
431+
432+ if l .FullyQualifiedRepository != "" {
433+ ctxt := pRef .Context ()
434+ if err := localizations .Add ("fullyQualifiedRepository" , l .File , l .FullyQualifiedRepository ,
435+ ctxt .Registry .Name ()+ "/" + ctxt .RepositoryStr ()); err != nil {
436+ return fmt .Errorf ("failed to add repository: %w" , err )
437+ }
438+ }
439+
440+ if l .Image != "" {
441+ if err := localizations .Add ("image" , l .File , l .Image , pRef .Name ()); err != nil {
442+ return fmt .Errorf ("failed to add image ref name: %w" , err )
443+ }
444+ }
445+
446+ if l .Tag != "" {
447+ if err := localizations .Add ("tag" , l .File , l .Tag , pRef .Identifier ()); err != nil {
448+ return fmt .Errorf ("failed to add identifier: %w" , err )
449+ }
450+ }
451+
452+ return nil
453+ }
454+
455+ func resolveReference (
456+ l configdata.LocalizationRule ,
457+ refPath []ocmmetav1.Identity ,
458+ compvers ocmcore.ComponentVersionAccess ,
459+ octx ocmcore.Context ,
460+ ) (name.Reference , error ) {
415461 resourceRef := ocmmetav1 .NewNestedResourceRef (ocmmetav1 .NewIdentity (l .Resource .Name ), refPath )
416462
417463 resource , _ , err := resourcerefs .ResolveResourceReference (compvers , resourceRef , compvers .Repository ())
418464 if err != nil {
419- return fmt .Errorf ("failed to fetch resource from component version: %w" , err )
465+ return nil , fmt .Errorf ("failed to fetch resource from component version: %w" , err )
420466 }
421467
422468 accSpec , err := resource .Access ()
423469 if err != nil {
424- return err
470+ return nil , err
425471 }
426472
427473 var (
@@ -447,39 +493,15 @@ func (m *MutationReconcileLooper) performLocalization(
447493 }
448494
449495 if refErr != nil {
450- return fmt .Errorf ("failed to parse access reference: %w" , refErr )
496+ return nil , fmt .Errorf ("failed to parse access reference: %w" , refErr )
451497 }
452498
453499 pRef , err := name .ParseReference (ref )
454500 if err != nil {
455- return fmt .Errorf ("failed to parse access reference: %w" , err )
501+ return nil , fmt .Errorf ("failed to parse access reference: %w" , err )
456502 }
457503
458- if l .Registry != "" {
459- if err := localizations .Add ("registry" , l .File , l .Registry , pRef .Context ().Registry .Name ()); err != nil {
460- return fmt .Errorf ("failed to add registry: %w" , err )
461- }
462- }
463-
464- if l .Repository != "" {
465- if err := localizations .Add ("repository" , l .File , l .Repository , pRef .Context ().RepositoryStr ()); err != nil {
466- return fmt .Errorf ("failed to add repository: %w" , err )
467- }
468- }
469-
470- if l .Image != "" {
471- if err := localizations .Add ("image" , l .File , l .Image , pRef .Name ()); err != nil {
472- return fmt .Errorf ("failed to add image ref name: %w" , err )
473- }
474- }
475-
476- if l .Tag != "" {
477- if err := localizations .Add ("tag" , l .File , l .Tag , pRef .Identifier ()); err != nil {
478- return fmt .Errorf ("failed to add identifier: %w" , err )
479- }
480- }
481-
482- return nil
504+ return pRef , nil
483505}
484506
485507func (m * MutationReconcileLooper ) createSubstitutionRulesForConfigurationValues (
0 commit comments