@@ -366,7 +366,7 @@ func (cs CompositeLayerSource) GetBlob(ctx context.Context, spec *api.ImageSpec,
366
366
}
367
367
368
368
// RefSource extracts an image reference from an image spec
369
- type RefSource func (* api.ImageSpec ) (ref string , err error )
369
+ type RefSource func (* api.ImageSpec ) (ref [] string , err error )
370
370
371
371
// NewSpecMappedImageSource creates a new spec mapped image source
372
372
func NewSpecMappedImageSource (resolver ResolverProvider , refSource RefSource ) (* SpecMappedImagedSource , error ) {
@@ -392,71 +392,104 @@ type SpecMappedImagedSource struct {
392
392
393
393
// Envs returns the list of env modifiers
394
394
func (src * SpecMappedImagedSource ) Envs (ctx context.Context , spec * api.ImageSpec ) ([]EnvModifier , error ) {
395
- lsrc , err := src .getDelegate (ctx , spec )
395
+ lsrcs , err := src .getDelegate (ctx , spec )
396
396
if err != nil {
397
397
return nil , err
398
398
}
399
- if lsrc == nil {
400
- return []EnvModifier {}, nil
399
+ var res []EnvModifier
400
+ for _ , lsrc := range lsrcs {
401
+ if lsrc == nil {
402
+ continue
403
+ }
404
+ envs , err := lsrc .Envs (ctx , spec )
405
+ if err != nil {
406
+ return nil , err
407
+ }
408
+ res = append (res , envs ... )
401
409
}
402
- return lsrc . Envs ( ctx , spec )
410
+ return res , nil
403
411
}
404
412
405
413
// GetLayer returns the list of all layers from this source
406
414
func (src * SpecMappedImagedSource ) GetLayer (ctx context.Context , spec * api.ImageSpec ) ([]AddonLayer , error ) {
407
- lsrc , err := src .getDelegate (ctx , spec )
415
+ lsrcs , err := src .getDelegate (ctx , spec )
408
416
if err != nil {
409
417
return nil , err
410
418
}
411
- if lsrc == nil {
412
- return []AddonLayer {}, nil
419
+ var res []AddonLayer
420
+ for _ , lsrc := range lsrcs {
421
+ if lsrc == nil {
422
+ continue
423
+ }
424
+ ls , err := lsrc .GetLayer (ctx , spec )
425
+ if err != nil {
426
+ return nil , err
427
+ }
428
+ res = append (res , ls ... )
413
429
}
414
- return lsrc . GetLayer ( ctx , spec )
430
+ return res , nil
415
431
}
416
432
417
433
// HasBlob checks if a digest can be served by this blob source
418
434
func (src * SpecMappedImagedSource ) HasBlob (ctx context.Context , spec * api.ImageSpec , dgst digest.Digest ) bool {
419
- lsrc , err := src .getDelegate (ctx , spec )
435
+ lsrcs , err := src .getDelegate (ctx , spec )
420
436
if err != nil {
421
437
return false
422
438
}
423
- if lsrc == nil {
424
- return false
439
+ for _ , lsrc := range lsrcs {
440
+ if lsrc == nil {
441
+ continue
442
+ }
443
+ if lsrc .HasBlob (ctx , spec , dgst ) {
444
+ return true
445
+ }
425
446
}
426
- return lsrc . HasBlob ( ctx , spec , dgst )
447
+ return false
427
448
}
428
449
429
450
// GetBlob provides access to a blob. If a ReadCloser is returned the receiver is expected to
430
451
// call close on it eventually.
431
452
func (src * SpecMappedImagedSource ) GetBlob (ctx context.Context , spec * api.ImageSpec , dgst digest.Digest ) (dontCache bool , mediaType string , url string , data io.ReadCloser , err error ) {
432
- lsrc , err := src .getDelegate (ctx , spec )
453
+ lsrcs , err := src .getDelegate (ctx , spec )
433
454
if err != nil {
434
455
return
435
456
}
436
- return lsrc .GetBlob (ctx , spec , dgst )
457
+ for _ , lsrc := range lsrcs {
458
+ if lsrc == nil {
459
+ continue
460
+ }
461
+ if lsrc .HasBlob (ctx , spec , dgst ) {
462
+ return lsrc .GetBlob (ctx , spec , dgst )
463
+ }
464
+ }
465
+ err = errdefs .ErrNotFound
466
+ return
437
467
}
438
468
439
469
// getDelegate returns the cached layer source delegate computed from the image spec
440
- func (src * SpecMappedImagedSource ) getDelegate (ctx context.Context , spec * api.ImageSpec ) (LayerSource , error ) {
441
- ref , err := src .RefSource (spec )
470
+ func (src * SpecMappedImagedSource ) getDelegate (ctx context.Context , spec * api.ImageSpec ) ([] LayerSource , error ) {
471
+ refs , err := src .RefSource (spec )
442
472
if err != nil {
443
473
return nil , err
444
474
}
445
- if ref == "" {
446
- return nil , nil
447
- }
448
-
449
- if s , ok := src .cache .Get (ref ); ok {
450
- return s .(LayerSource ), nil
451
- }
475
+ layers := make ([]LayerSource , len (refs ))
452
476
453
- lsrc , err := NewStaticSourceFromImage (ctx , src .Resolver (), ref )
454
- if err != nil {
455
- return nil , err
477
+ for i , ref := range refs {
478
+ if ref == "" {
479
+ continue
480
+ }
481
+ if s , ok := src .cache .Get (ref ); ok {
482
+ layers [i ] = s .(LayerSource )
483
+ continue
484
+ }
485
+ lsrc , err := NewStaticSourceFromImage (ctx , src .Resolver (), ref )
486
+ if err != nil {
487
+ return nil , err
488
+ }
489
+ src .cache .Add (ref , lsrc )
490
+ layers [i ] = lsrc
456
491
}
457
- src .cache .Add (ref , lsrc )
458
-
459
- return lsrc , nil
492
+ return layers , nil
460
493
}
461
494
462
495
// NewContentLayerSource creates a new layer source providing the content layer of an image spec
0 commit comments