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

Refactor NewImageSource to add a manifest type abstraction #5743

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aaronlehmann
Copy link
Contributor

What type of PR is this?

/kind cleanup

What this PR does / why we need it:

Currently, NewImageSource creates a Docker schema2 manifest and an OCI manifest at the same time. This precludes functionality that isn't supported by both manifest types, for example zstd compression. Refactoring this to create only the desired manifest type solves this and also cleans up the code by separating manifest-type-specific code into distinct implementations of a "manifest builder".

How to verify it

Existing tests should suffice since this does not change any semantics, it only cleans up the implementation.

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

See discussion in #5452.

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 17, 2024
@aaronlehmann aaronlehmann force-pushed the refactor-manifest-types branch 2 times, most recently from 9f1c553 to 81fea1d Compare September 17, 2024 23:39
@aaronlehmann
Copy link
Contributor Author

@mtrmac: PTAL - thanks!

@aaronlehmann
Copy link
Contributor Author

@rhatdan @mtrmac: Would it be possible to get some eyes on this when you have a moment? I was asked to do this to unblock #5452, so I would really appreciate if we could avoid letting it sit too long.

@aaronlehmann
Copy link
Contributor Author

Any possibility of moving this forward? It's a bit frustrating that I was asked to come back and do this refactor, but the PR is not getting reviewed.

@TomSweeneyRedHat
Copy link
Member

@mtrmac have you had a chance to look at this?

@TomSweeneyRedHat
Copy link
Member

@aaronlehmann sorry for the delay. Many of the maintainers are Red Hat based, and we've all been under a big crunch the past few weeks.

@mtrmac
Copy link
Contributor

mtrmac commented Nov 4, 2024

@Honny1 Do you happen to have the time to take a look?

Copy link

github-actions bot commented Dec 5, 2024

A friendly reminder that this PR had no activity for 30 days.

@aaronlehmann
Copy link
Contributor Author

@TomSweeneyRedHat @mtrmac @Honny1: Would any of you be able to look at this? I've been trying to get this through for a very long time.

@mtrmac
Copy link
Contributor

mtrmac commented Feb 27, 2025

@flouthoc do you happen to have time for this?

@github-actions github-actions bot removed the stale-pr label Feb 28, 2025
@flouthoc
Copy link
Collaborator

I will review this thanks.

@flouthoc flouthoc self-assigned this Feb 28, 2025
@flouthoc
Copy link
Collaborator

@aaronlehmann Could you please rebase this first, just to be sure if every thing is good.

@aaronlehmann aaronlehmann force-pushed the refactor-manifest-types branch from 81fea1d to b962939 Compare February 28, 2025 21:24
@aaronlehmann
Copy link
Contributor Author

Rebased.

@flouthoc flouthoc added the No New Tests Allow PR to proceed without adding regression tests label Feb 28, 2025
@aaronlehmann
Copy link
Contributor Author

Hi @flouthoc, have you had a chance to look at this yet?

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some duplication but PR LGTM. Could you please rebase again.

@aaronlehmann aaronlehmann force-pushed the refactor-manifest-types branch from b962939 to 72ea5a8 Compare March 18, 2025 17:47
@aaronlehmann
Copy link
Contributor Author

Rebased again.

@aaronlehmann
Copy link
Contributor Author

@flouthoc: Hoping I can get this merged before it needs yet another rebase 😄

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM @nalind any comments ?

Copy link
Contributor

openshift-ci bot commented Mar 19, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aaronlehmann, flouthoc
Once this PR has been reviewed and has the lgtm label, please assign rhatdan for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

image.go Outdated

type dockerSchema2ManifestBuilder struct {
i *containerImageRef
mediaType string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layerMediaType, please.

image.go Outdated
// without making unintended changes to the original Builder.
func (i *containerImageRef) createConfigsAndManifests() (v1.Image, v1.Manifest, docker.V2Image, docker.V2S2Manifest, error) {
// without making unintended changes to the original Builder (Docker schema 2).
func newDockerSchema2ManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just as well be a method of containerImageRef.

image.go Outdated
}

func (mb *dockerSchema2ManifestBuilder) buildHistory(extraImageContentDiff string, extraImageContentDiffDigest digest.Digest) error {
// Build history notes in the image configurations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one configuration, this comment needs an update.

image.go Outdated
// Build history notes in the image configurations.
appendHistory := func(history []v1.History, empty bool) {
for i := range history {
var created *time.Time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be slightly shorter if created wasn't a pointer here.

image.go Outdated

type ociManifestBuilder struct {
i *containerImageRef
mediaType string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layerMediaType, please.

image.go Outdated

// Build fresh copies of the container configuration structures so that we can edit them
// without making unintended changes to the original Builder (OCI manifest).
func newOCIManifestBuilder(i *containerImageRef) (manifestBuilder, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could just as well be a method of containerImageRef.

image.go Outdated
oimage.Config.ExposedPorts = nil
}

// Build empty manifest. The Layers lists will be populated later.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs an update.

case archive.Zstd:
// Until the image specs define a media type for zstd-compressed layers, even if we know
// how to decompress them, we can't try to compress layers with zstd.
return errors.New("media type for zstd-compressed layers is not defined")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could set omediaType to v1.MediaTypeImageLayerZstd instead of returning an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #5452 I was asked not to support zstd in Docker manifests because the spec doesn't officially support it. That was the impetus for this refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, this is for the OCI manifest. The idea was to make this change in #5452 once this PR is merged, but I could unify the two PRs if you prefer.

image.go Outdated
return nil, fmt.Errorf("no supported manifest types (attempted to use %q, only know %q and %q)",
manifestType, v1.MediaTypeImageManifest, manifest.DockerV2Schema2MediaType)
func (mb *ociManifestBuilder) buildHistory(extraImageContentDiff string, extraImageContentDiffDigest digest.Digest) error {
// Build history notes in the image configurations.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one configuration, this comment needs an update.

image.go Outdated
@@ -720,187 +1027,19 @@ func (i *containerImageRef) NewImageSource(_ context.Context, _ *types.SystemCon
}
// Add a note in the manifest about the layer. The blobs are identified by their possibly-
// compressed blob digests.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a comment that addLayer() should have in it, or as part of its godoc.

image.go Outdated
MediaType: v1.MediaTypeImageManifest,
Config: v1.Descriptor{
MediaType: v1.MediaTypeImageConfig,
// Build empty manifest. The Layers lists will be populated later.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment needs an update.

@aaronlehmann
Copy link
Contributor Author

@nalind: Thanks for the review - updated based on your feedback.

@aaronlehmann aaronlehmann force-pushed the refactor-manifest-types branch from 5686f79 to 7fbdf26 Compare March 19, 2025 19:48
@aaronlehmann
Copy link
Contributor Author

@nalind @flouthoc: Any further comments?

@aaronlehmann
Copy link
Contributor Author

@nalind @flouthoc: Can we please move ahead with merging this? Thanks!

@flouthoc
Copy link
Collaborator

PR LGTM I am waiting for @nalind to ack on his last remarks.

@aaronlehmann
Copy link
Contributor Author

@nalind: Sorry to be so persistent here, but I'd really like to get this merged, since it has been dragging on for so long, and it's hard to keep coming back to this after long pauses.

Currently, NewImageSource creates a Docker schema2 manifest and an OCI
manifest at the same time. This precludes functionality that isn't
supported by both manifest types, for example zstd compression.
Refactoring this to create only the desired manifest type solves this
and also cleans up the code by separating manifest-type-specific code
into distinct implementations of a "manifest builder".

See discussion in containers#5452.

Signed-off-by: Aaron Lehmann <[email protected]>
Signed-off-by: Aaron Lehmann <[email protected]>
@aaronlehmann aaronlehmann force-pushed the refactor-manifest-types branch from 7fbdf26 to 8008e9c Compare March 31, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. No New Tests Allow PR to proceed without adding regression tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants