-
Notifications
You must be signed in to change notification settings - Fork 807
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
base: main
Are you sure you want to change the base?
Refactor NewImageSource to add a manifest type abstraction #5743
Conversation
9f1c553
to
81fea1d
Compare
@mtrmac: PTAL - thanks! |
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. |
@mtrmac have you had a chance to look at this? |
@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. |
@Honny1 Do you happen to have the time to take a look? |
A friendly reminder that this PR had no activity for 30 days. |
@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. |
@flouthoc do you happen to have time for this? |
I will review this thanks. |
@aaronlehmann Could you please rebase this first, just to be sure if every thing is good. |
81fea1d
to
b962939
Compare
Rebased. |
Hi @flouthoc, have you had a chance to look at this yet? |
There was a problem hiding this 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.
b962939
to
72ea5a8
Compare
Rebased again. |
@flouthoc: Hoping I can get this merged before it needs yet another rebase 😄 |
There was a problem hiding this 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 ?
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: aaronlehmann, flouthoc 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 |
image.go
Outdated
|
||
type dockerSchema2ManifestBuilder struct { | ||
i *containerImageRef | ||
mediaType string |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
@nalind: Thanks for the review - updated based on your feedback. |
5686f79
to
7fbdf26
Compare
PR LGTM I am waiting for @nalind to ack on his last remarks. |
@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]>
7fbdf26
to
8008e9c
Compare
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?