Skip to content

Commit 568b70b

Browse files
authored
OCPBUGS-44103: handle DeserializedImageIndex manifests (#2)
This fixes the following error: ``` stats: shared=0 unique=0 size=0Berror: the manifest type *ocischema.DeserializedImageIndex is not supported error: an error occurred during planning ``` by parsing the DeserializedImageIndex as we do with DeserializedManifestList.
1 parent 810ebec commit 568b70b

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

pkg/cli/image/manifest/manifest.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,76 @@ func ProcessManifestList(ctx context.Context, srcDigest digest.Digest, srcManife
511511
default:
512512
return childManifests, manifestList, manifestDigest, nil
513513
}
514+
case *ocischema.DeserializedImageIndex:
515+
manifestDigest := srcDigest
516+
manifestList := t
514517

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+
}
515584
default:
516585
return nil, srcManifest, srcDigest, nil
517586
}

pkg/cli/image/mirror/mirror.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,9 @@ func (o *MirrorImageOptions) plan() (*plan, error) {
611611
case *schema2.DeserializedManifest:
612612
case *schema1.SignedManifest:
613613
case *ocischema.DeserializedManifest:
614+
case *ocischema.DeserializedImageIndex:
615+
// we do not need to upload layers in an image index
616+
return
614617
case *manifestlist.DeserializedManifestList:
615618
// we do not need to upload layers in a manifestlist
616619
return

0 commit comments

Comments
 (0)