Skip to content

Commit 09af909

Browse files
authored
Fully qualified repo ( issue 764 ) (#775)
<!-- markdownlint-disable MD041 --> #### What this PR does / why we need it See issue [764](open-component-model/ocm-project#764) #### Which issue(s) this PR is related to Issue [764](open-component-model/ocm-project#764) --------- Signed-off-by: [email protected] <[email protected]>
1 parent d4deb3f commit 09af909

File tree

2 files changed

+59
-36
lines changed

2 files changed

+59
-36
lines changed

controllers/mutation_reconcile_looper.go

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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

485507
func (m *MutationReconcileLooper) createSubstitutionRulesForConfigurationValues(

pkg/configdata/configdata.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,14 @@ type ConfigRule struct {
8686
}
8787

8888
type LocalizationRule struct {
89-
Resource ResourceItem `json:"resource"`
90-
File string `json:"file"`
91-
Registry string `json:"registry,omitempty"`
92-
Mapping *Mapping `json:"mapping,omitempty"`
93-
Repository string `json:"repository,omitempty"`
94-
Image string `json:"image,omitempty"`
95-
Tag string `json:"tag,omitempty"`
89+
Resource ResourceItem `json:"resource"`
90+
File string `json:"file"`
91+
Registry string `json:"registry,omitempty"`
92+
Mapping *Mapping `json:"mapping,omitempty"`
93+
Repository string `json:"repository,omitempty"`
94+
FullyQualifiedRepository string `json:"fullyQualifiedRepository,omitempty"`
95+
Image string `json:"image,omitempty"`
96+
Tag string `json:"tag,omitempty"`
9697
}
9798

9899
type Mapping struct {

0 commit comments

Comments
 (0)