@@ -511,7 +511,76 @@ func ProcessManifestList(ctx context.Context, srcDigest digest.Digest, srcManife
511
511
default :
512
512
return childManifests , manifestList , manifestDigest , nil
513
513
}
514
+ case * ocischema.DeserializedImageIndex :
515
+ manifestDigest := srcDigest
516
+ manifestList := t
514
517
518
+ filtered := make ([]distribution.Descriptor , 0 , len (t .Manifests ))
519
+ for _ , manifest := range t .Manifests {
520
+ // NOTE: We create a temporary ManifestDescriptor here so we can use the same `filterFn` as for ManifestList
521
+ // and avoid duplicating functionality.
522
+ m := manifestlist.ManifestDescriptor {
523
+ Descriptor : manifest .Descriptor (),
524
+ Platform : manifestlist.PlatformSpec {
525
+ Architecture : manifest .Platform .Architecture ,
526
+ OS : manifest .Platform .OS ,
527
+ OSVersion : manifest .Platform .OSVersion ,
528
+ OSFeatures : manifest .Platform .OSFeatures ,
529
+ Variant : manifest .Platform .Variant ,
530
+ },
531
+ }
532
+ if ! filterFn (& m , len (t .Manifests ) > 1 ) {
533
+ klog .V (5 ).Infof ("Skipping image %s for %#v from %s" , manifest .Digest , manifest .Platform , ref )
534
+ continue
535
+ }
536
+ klog .V (5 ).Infof ("Including image %s for %#v from %s" , manifest .Digest , manifest .Platform , ref )
537
+ filtered = append (filtered , manifest )
538
+ }
539
+
540
+ if len (filtered ) == 0 && ! keepManifestList {
541
+ return nil , nil , "" , nil
542
+ }
543
+
544
+ // if we're not keeping manifest lists and this one has been filtered, make a new one with
545
+ // just the filtered platforms.
546
+ if len (filtered ) != len (t .Manifests ) && ! keepManifestList {
547
+ var err error
548
+ t , err = ocischema .FromDescriptors (filtered , nil )
549
+ if err != nil {
550
+ return nil , nil , "" , fmt .Errorf ("unable to filter source image %s image index: %v" , ref , err )
551
+ }
552
+ _ , body , err := t .Payload ()
553
+ if err != nil {
554
+ return nil , nil , "" , fmt .Errorf ("unable to filter source image %s image index (bad payload): %v" , ref , err )
555
+ }
556
+ manifestList = t
557
+ manifestDigest , err = registryclient .ContentDigestForManifest (t , srcDigest .Algorithm ())
558
+ if err != nil {
559
+ return nil , nil , "" , err
560
+ }
561
+ klog .V (5 ).Infof ("Filtered image index to new digest %s:\n %s" , manifestDigest , body )
562
+ }
563
+
564
+ for i , manifest := range filtered {
565
+ childManifest , err := manifests .Get (ctx , manifest .Digest , PreferManifestList )
566
+ if err != nil {
567
+ return nil , nil , "" , fmt .Errorf ("unable to retrieve source image %s manifest #%d from image index: %v" , ref , i + 1 , err )
568
+ }
569
+ childManifests = append (childManifests , childManifest )
570
+ }
571
+
572
+ switch {
573
+ case len (childManifests ) == 1 && ! keepManifestList :
574
+ // Just return the single platform specific image
575
+ manifestDigest , err := registryclient .ContentDigestForManifest (childManifests [0 ], srcDigest .Algorithm ())
576
+ if err != nil {
577
+ return nil , nil , "" , err
578
+ }
579
+ klog .V (2 ).Infof ("Chose %s/%s manifest from the image index." , t .Manifests [0 ].Platform .OS , t .Manifests [0 ].Platform .Architecture )
580
+ return nil , childManifests [0 ], manifestDigest , nil
581
+ default :
582
+ return childManifests , manifestList , manifestDigest , nil
583
+ }
515
584
default :
516
585
return nil , srcManifest , srcDigest , nil
517
586
}
0 commit comments