@@ -37,7 +37,8 @@ const Realm = "repository/component/fallback"
3737// Deprecated: FallbackRepository is an implementation for the deprecated config
3838// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
3939// and only added for backwards compatibility.
40- // New concepts will likely be introduced in the future (contributions welcome!).
40+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
41+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
4142type FallbackRepository struct {
4243 // GoRoutineLimit limits the number of active goroutines for concurrent
4344 // operations.
@@ -78,7 +79,8 @@ type FallbackRepositoryOptions struct {
7879// Deprecated: FallbackRepository is an implementation for the deprecated config
7980// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
8081// and only added for backwards compatibility.
81- // New concepts will likely be introduced in the future (contributions welcome!).
82+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
83+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
8284func NewFallbackRepository (_ context.Context , repositoryProvider repository.ComponentVersionRepositoryProvider , credentialsResolver credentials.Resolver , res []* resolverruntime.Resolver , opts ... FallbackRepositoryOption ) (* FallbackRepository , error ) {
8385 options := & FallbackRepositoryOptions {}
8486 for _ , opt := range opts {
@@ -111,7 +113,8 @@ func NewFallbackRepository(_ context.Context, repositoryProvider repository.Comp
111113// Deprecated: FallbackRepository is an implementation for the deprecated config
112114// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
113115// and only added for backwards compatibility.
114- // New concepts will likely be introduced in the future (contributions welcome!).
116+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
117+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
115118func (f * FallbackRepository ) AddComponentVersion (ctx context.Context , descriptor * descriptor.Descriptor ) error {
116119 repos := f .RepositoriesForComponentIterator (ctx , descriptor .Component .Name )
117120 for repo , err := range repos {
@@ -130,7 +133,8 @@ func (f *FallbackRepository) AddComponentVersion(ctx context.Context, descriptor
130133// Deprecated: FallbackRepository is an implementation for the deprecated config
131134// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
132135// and only added for backwards compatibility.
133- // New concepts will likely be introduced in the future (contributions welcome!).
136+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
137+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
134138func (f * FallbackRepository ) GetComponentVersion (ctx context.Context , component , version string ) (* descriptor.Descriptor , error ) {
135139 repos := f .RepositoriesForComponentIterator (ctx , component )
136140 for repo , err := range repos {
@@ -157,7 +161,8 @@ func (f *FallbackRepository) GetComponentVersion(ctx context.Context, component,
157161// Deprecated: FallbackRepository is an implementation for the deprecated config
158162// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
159163// and only added for backwards compatibility.
160- // New concepts will likely be introduced in the future (contributions welcome!).
164+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
165+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
161166func (f * FallbackRepository ) ListComponentVersions (ctx context.Context , component string ) ([]string , error ) {
162167 repos := f .RepositoriesForComponentIterator (ctx , component )
163168
@@ -207,7 +212,8 @@ func (f *FallbackRepository) ListComponentVersions(ctx context.Context, componen
207212// Deprecated: FallbackRepository is an implementation for the deprecated config
208213// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
209214// and only added for backwards compatibility.
210- // New concepts will likely be introduced in the future (contributions welcome!).
215+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
216+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
211217func (f * FallbackRepository ) AddLocalResource (ctx context.Context , component , version string , res * descriptor.Resource , content blob.ReadOnlyBlob ) (* descriptor.Resource , error ) {
212218 repos := f .RepositoriesForComponentIterator (ctx , component )
213219 for repo , err := range repos {
@@ -226,7 +232,8 @@ func (f *FallbackRepository) AddLocalResource(ctx context.Context, component, ve
226232// Deprecated: FallbackRepository is an implementation for the deprecated config
227233// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
228234// and only added for backwards compatibility.
229- // New concepts will likely be introduced in the future (contributions welcome!).
235+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
236+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
230237func (f * FallbackRepository ) GetLocalResource (ctx context.Context , component , version string , identity runtime.Identity ) (blob.ReadOnlyBlob , * descriptor.Resource , error ) {
231238 repos := f .RepositoriesForComponentIterator (ctx , component )
232239 for repo , err := range repos {
@@ -252,7 +259,8 @@ func (f *FallbackRepository) GetLocalResource(ctx context.Context, component, ve
252259// Deprecated: FallbackRepository is an implementation for the deprecated config
253260// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
254261// and only added for backwards compatibility.
255- // New concepts will likely be introduced in the future (contributions welcome!).
262+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
263+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
256264func (f * FallbackRepository ) AddLocalSource (ctx context.Context , component , version string , source * descriptor.Source , content blob.ReadOnlyBlob ) (* descriptor.Source , error ) {
257265 repos := f .RepositoriesForComponentIterator (ctx , component )
258266 for repo , err := range repos {
@@ -271,7 +279,8 @@ func (f *FallbackRepository) AddLocalSource(ctx context.Context, component, vers
271279// Deprecated: FallbackRepository is an implementation for the deprecated config
272280// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
273281// and only added for backwards compatibility.
274- // New concepts will likely be introduced in the future (contributions welcome!).
282+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
283+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
275284func (f * FallbackRepository ) GetLocalSource (ctx context.Context , component , version string , identity runtime.Identity ) (blob.ReadOnlyBlob , * descriptor.Source , error ) {
276285 repos := f .RepositoriesForComponentIterator (ctx , component )
277286 for repo , err := range repos {
@@ -299,7 +308,8 @@ func (f *FallbackRepository) GetLocalSource(ctx context.Context, component, vers
299308// Deprecated: FallbackRepository is an implementation for the deprecated config
300309// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
301310// and only added for backwards compatibility.
302- // New concepts will likely be introduced in the future (contributions welcome!).
311+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
312+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
303313func (f * FallbackRepository ) RepositoriesForComponentIterator (ctx context.Context , component string ) iter.Seq2 [repository.ComponentVersionRepository , error ] {
304314 return func (yield func (repository.ComponentVersionRepository , error ) bool ) {
305315 for _ , resolver := range f .resolvers {
@@ -324,7 +334,8 @@ func (f *FallbackRepository) RepositoriesForComponentIterator(ctx context.Contex
324334// Deprecated: FallbackRepository is an implementation for the deprecated config
325335// type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
326336// and only added for backwards compatibility.
327- // New concepts will likely be introduced in the future (contributions welcome!).
337+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
338+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
328339func (f * FallbackRepository ) GetResolvers () []* resolverruntime.Resolver {
329340 // Return a copy of the resolvers to ensure immutability
330341 return deepCopyResolvers (f .resolvers )
@@ -358,10 +369,52 @@ func (f *FallbackRepository) getRepositoryForSpecification(ctx context.Context,
358369 return repo , nil
359370}
360371
372+ // GetComponentVersionRepositoryForSpecification returns a repository for the given specification.
373+ //
374+ // Deprecated: FallbackRepository is an implementation for the deprecated config
375+ // type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
376+ // and only added for backwards compatibility.
377+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
378+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
361379func (f * FallbackRepository ) GetComponentVersionRepositoryForSpecification (ctx context.Context , specification runtime.Typed ) (repository.ComponentVersionRepository , error ) {
362380 return f .getRepositoryFromCache (ctx , specification )
363381}
364382
383+ // GetRepositorySpecificationForComponent probes repositories in priority order and returns
384+ // the spec of the first repository that contains the component version.
385+ // Note: This does NOT cache results to maintain consistency with the existing
386+ // non-deterministic fallback behavior.
387+ //
388+ // Deprecated: FallbackRepository is an implementation for the deprecated config
389+ // type "ocm.config.ocm.software/v1". This concept of fallback resolvers is deprecated
390+ // and only added for backwards compatibility.
391+ // Use the path matcher resolver (ocm.software/open-component-model/bindings/go/repository/component/pathmatcher)
392+ // with "resolvers.ocm.software/v1alpha1" configuration instead.
393+ func (f * FallbackRepository ) GetRepositorySpecificationForComponent (ctx context.Context , component , version string ) (runtime.Typed , error ) {
394+ for _ , resolver := range f .resolvers {
395+ if resolver .Prefix != "" && resolver .Prefix != component &&
396+ ! strings .HasPrefix (component , strings .TrimSuffix (resolver .Prefix , "/" )+ "/" ) {
397+ continue
398+ }
399+ repo , err := f .getRepositoryFromCache (ctx , resolver .Repository )
400+ if err != nil {
401+ return nil , fmt .Errorf ("getting repository for resolver %v failed: %w" , resolver , err )
402+ }
403+ _ , err = repo .GetComponentVersion (ctx , component , version )
404+ if errors .Is (err , repository .ErrNotFound ) {
405+ slog .DebugContext (ctx , "component version not found in repository during spec resolution" ,
406+ "realm" , Realm , "repository" , resolver .Repository , "component" , component , "version" , version )
407+ continue
408+ }
409+ if err != nil {
410+ return nil , fmt .Errorf ("probing component version %s/%s in repository %v failed: %w" ,
411+ component , version , resolver .Repository , err )
412+ }
413+ return resolver .Repository , nil
414+ }
415+ return nil , fmt .Errorf ("component version %s/%s not found in any repository" , component , version )
416+ }
417+
365418func (f * FallbackRepository ) getRepositoryFromCache (ctx context.Context , specification runtime.Typed ) (repository.ComponentVersionRepository , error ) {
366419 specdata , err := json .Marshal (specification )
367420 if err != nil {
0 commit comments