Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable/v0.7] converter: support OCI reference type #431

Merged
merged 1 commit into from
Mar 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/converter/convert_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ func ConvertHookFunc(opt MergeOption) converter.ConvertHookFunc {
case images.IsIndexType(newDesc.MediaType):
return convertIndex(ctx, cs, orgDesc, newDesc)
case images.IsManifestType(newDesc.MediaType):
return convertManifest(ctx, cs, newDesc, opt)
return convertManifest(ctx, cs, orgDesc, newDesc, opt)
default:
return newDesc, nil
}
Expand Down Expand Up @@ -869,6 +869,13 @@ func convertIndex(ctx context.Context, cs content.Store, orgDesc ocispec.Descrip
manifest.Platform.OSFeatures = append(manifest.Platform.OSFeatures, ManifestOSFeatureNydus)
index.Manifests[i] = manifest
}

// If the converted manifest list contains only one manifest,
// convert it directly to manifest.
if len(index.Manifests) == 1 {
return &index.Manifests[0], nil
}

// Update image index in content store.
newIndexDesc, err := writeJSON(ctx, cs, index, *newDesc, indexLabels)
if err != nil {
Expand All @@ -893,7 +900,7 @@ func isNydusImage(manifest *ocispec.Manifest) bool {
// convertManifest merges all the nydus blob layers into a
// nydus bootstrap layer, update the image config,
// and modify the image manifest.
func convertManifest(ctx context.Context, cs content.Store, newDesc *ocispec.Descriptor, opt MergeOption) (*ocispec.Descriptor, error) {
func convertManifest(ctx context.Context, cs content.Store, oldDesc ocispec.Descriptor, newDesc *ocispec.Descriptor, opt MergeOption) (*ocispec.Descriptor, error) {
var manifest ocispec.Manifest
manifestDesc := *newDesc
manifestLabels, err := readJSON(ctx, cs, &manifest, manifestDesc)
Expand Down Expand Up @@ -972,6 +979,11 @@ func convertManifest(ctx context.Context, cs content.Store, newDesc *ocispec.Des
// Update the config gc label
manifestLabels[configGCLabelKey] = newConfigDesc.Digest.String()

// Associate a reference to the original OCI manifest.
// See the `subject` field description in
// https://github.com/opencontainers/image-spec/blob/main/manifest.md#image-manifest-property-descriptions
manifest.Subject = &oldDesc

// Update image manifest in content store.
newManifestDesc, err := writeJSON(ctx, cs, manifest, manifestDesc, manifestLabels)
if err != nil {
Expand Down