Repository navigation
Conversation
|
The PR size is probably quite a bit smaller if I added a IsManifest field to the Descriptor field rather than split References() into BlobReferences() and ManifestReferences() if that seems like a better approach. |
@msg555 What I would recommend is keeping |
Signed-off-by: Mark Gordon <[email protected]>
Signed-off-by: Mark Gordon <[email protected]>
Signed-off-by: Mark Gordon <[email protected]>
0b5ac95 to
69c1079
Compare
|
Updated to not remove the existing References() and AppendReference() interface methods. Also left all uses of these methods alone except within the manifest implementation and test code and within the GC fix (should I just submit this as a follow up PR?) |
@msg555 I would say they're so closely related that they should stick together in this single PR. I'm interested in giving this a more in-depth review now that the noise has been reduced (thanks for that!!), but it will probably take me a fair amount of time due to the complexity of garbage collection. |
msg555
left a comment
There was a problem hiding this comment.
Left some comments about the implementation fwiw
| return nil | ||
| }) | ||
| for _, descriptor := range manifest.ManifestReferences() { | ||
| if _, ok := unmarkedManifests[descriptor.Digest]; ok { |
There was a problem hiding this comment.
For manifest references add it to the manifestList for processing if we haven't done so already.
There was a problem hiding this comment.
Seems like we would need to go through and find any potential manifests which are referenced by tagged manifests and add them to the list of referenced manifests since we need to account for their manifest blob and their layer blobs like normal, right?
There was a problem hiding this comment.
I'm not 100% on what you're asking here so apologies if I'm addressing the wrong concrn.
The manifestEnumerator.Enumerate loop at line 66 computes the initial reachable set of manifests. If RemoveUntagged is set this is only manifests that are directly tagged, otherwise it trivially just includes all manifests.
Then this loop starting at line 91 is computing the transitive closure on that initial set of manifests. Each iteration we process a reachable manifest list and mark all its blobs and manifests. If it has any manifest dependencies that have not already been marked we add it to the end of the list we're iterating over. Logically we're just executing a breadth first search.
In this way all manifests and blobs that are directly or indirectly referenced by a manifest are eventually marked.
There was a problem hiding this comment.
we add it to the end of the list we're iterating over. Logically we're just executing a breadth first search.
In this way all manifests and blobs that are directly or indirectly referenced by a manifest are eventually marked.
I see this now, it's pretty elegant. Sorry for missing it at first 👍
Could you add a comment above line 111 bringing attention to the fact that manifests which are referenced by manifest lists are being appended to the end of the list so that they're processed before the loop ends?
There was a problem hiding this comment.
@msg555 I went through and hit some of the high points. There's a bit of an open question as you'll see below, but while that's being resolved, I left some feedback on testing that should hold true for whatever outcome that discussion ultimately has.
Thanks for taking on this work! In general, garbage collection is one of the more complex aspects of this project.
|
|
||
| // BlobReferences returns blob descriptors referenced by this manifest. | ||
| func (sm ManifestList) BlobReferences() []distribution.Descriptor { | ||
| return nil |
There was a problem hiding this comment.
@msg555 What I'm seeing here is that distribution.Manifests either have blob references or manifest references and there is nothing that would return both (at least for now). So at least in terms of garbage collection, we're only trying to know if we're dealing with a blob referencing thing or a manifest referencing thing.
With that in mind, we expect the only things that reference manifests are OCI Image indexes and Manifest Lists. These are represented by the same concrete type, so I'm wondering if we're better off doing a cast to a manifestlist.ManifestList in the garbage collector, rather than implementing these interfaces given that there's only one concrete implementation that will return anything but nil when its ManifestReferences method is called.
This is somewhat complicated by the code here which suggests that schema 2 manifests may contain schema 1 and schema 2 manifests as references, and OCI images may contain OCI images as refernces: https://github.com/distribution/distribution/blob/main/registry/storage/schema2manifesthandler.go#L109, https://github.com/distribution/distribution/blob/main/registry/storage/ocimanifesthandler.go#L103. I've never actually seen this, but I'm curious if @justincormack and/or @SteveLasker know anything about this?
If this turns out that these manifest types can reference other manifests then we should keep these interfaces, but we'll need to correct the implementations so that they'll properly return these referenced manifests when the ManifestReferences method is called.
There was a problem hiding this comment.
Part of the reason I was interested in this codebase and looking at how it handled more generic dependency graphs was because I have an interest in having my own custom manifest type that has more complex dependencies. So it's definitely my preference this is written in a generic way.
Interesting point about some other types of manifests having manifest dependencies. I agree it does look like e.g. schema2 can have references to schema1 or schema2 manifets according to the implementation of verifyManifest. However I don't see anything that explains that in https://docs.docker.com/registry/spec/manifest-v2-2/ and I'm not sure what it would mean. Maybe it's just a copy-paste from the manifest list implementation?
There was a problem hiding this comment.
Maybe it's just a copy-paste from the manifest list implementation?
Gosh, I would hope not 😓
Part of the reason I was interested in this codebase and looking at how it handled more generic dependency graphs was because I have an interest in having my own custom manifest type that has more complex dependencies. So it's definitely my preference this is written in a generic way.
@msg555 gotcha, I'm hesitant to include those changes along with this MR. Downstream projects use us a library and making changes to these types here needs to be preceded by an in-depth, dedicated discussion and probably shouldn't be included without a major version bump.
My feelings on this is that we should split this work up by:
- keeping the garbage collection related changes in this MR, using type casting to discover the manifest lists, and updating the title to fit this, as the GC removing manifests removed by a manifest list is a serious bug
- You opening an issue to discuss the generic dependency graphs and discuss your use case and implementation
- Me opening an issue to investigate the mysterious validation code
WDYT?
| return nil | ||
| }) | ||
| for _, descriptor := range manifest.ManifestReferences() { | ||
| if _, ok := unmarkedManifests[descriptor.Digest]; ok { |
There was a problem hiding this comment.
Seems like we would need to go through and find any potential manifests which are referenced by tagged manifests and add them to the list of referenced manifests since we need to account for their manifest blob and their layer blobs like normal, right?
| } | ||
|
|
||
| unmarkedManifests := make(map[digest.Digest]struct{}) | ||
| var manifestList []digest.Digest |
There was a problem hiding this comment.
I think could probably be called referencedManifests or so, right now the name isn't very descriptive, it collides with the package/type manifestList and in general, it's good to avoid naming variables after their types
|
|
||
| // Create random layers | ||
| randomLayers1, err := testutil.CreateRandomLayers(3) | ||
| randomLayers, err := testutil.CreateRandomLayers(12) |
There was a problem hiding this comment.
Rather than expanding this test, can we leave it as is and write new tests? I think we'd need new tests which ensure at least the following are covered:
- untagged manifests which are referenced by a tagged manifest list are kept when
RemoveUntagged:true- blobs which are uniquely referenced by an untagged manifest which are referenced by a tagged manifest list are kept when
RemoveUntagged:true
- blobs which are uniquely referenced by an untagged manifest which are referenced by a tagged manifest list are kept when
- untagged manifests which are referenced by an untagged manifest list are removed when
RemoveUntagged:true- blobs which are uniquely referenced by an untagged manifest which are referenced by an untagged manifest list are removed when
RemoveUntagged:true
- blobs which are uniquely referenced by an untagged manifest which are referenced by an untagged manifest list are removed when
- tagged manifests which are referenced by an untagged manifest list are kept when
RemoveUntagged:true
Also, we should use schema 2 manifests and manifest lists in these tests. Schema 1 is very deprecated and isn't realistic in the scenario. testutil has functions for schema 2 manifests and manifest lists already.
There was a problem hiding this comment.
Also, we need to try to ensure that there are no ordering issues: ensuring that an untagged manifest referenced by a tagged manifest list is handled correctly regardless of whether it is encountered by the manifest enumerator before or after the manifest list which references it.
For example, we need to be sure to avoid deleting a manifest (or not marking its blobs, ect), only later to find it was referenced by another manifest list that was tagged.
There was a problem hiding this comment.
Agreed we should make those updates to the tests.
As far as ordering goes is there some easy way I can control what order manifests are enumerated?
There was a problem hiding this comment.
As far as ordering goes is there some easy way I can control what order manifests are enumerated?
Not really 😅
I think as long as we provide several randomly created lists with randomly created manifests per test we'll have this covered, otherwise the test will flake, or maybe even only occasionally pass (reverse-flake?). It's not perfect, but it should get caught relatively soon.
To test for this every time always, you'd need to manually build out a list and manifests that happen to produce digests that lexicographically sort before and after the lists digests. It's a little extra to be honest, but it's fine if you chose to have a test like this or not.
|
The distinction between blobs and manifests is pretty key for many scenarios. To grab some eyes, folks MAY, 😃 want to review opencontainers/artifacts#29 for some work on enabling Reference Types, supporting secure supply chain efforts like SBoMs and signatures. We have a branch of CNCF Distribtuion that works against a slightly older version of PR29 here: https://github.com/notaryproject/distribution/tree/prototype-2 Docs for the layout are described here: https://github.com/notaryproject/distribution/blob/prototype-2/docs/reference-types.md And, an ORAS implementation that demonstrates how to push, discover, pull reference types Apologies if this spams folks just trying to get this PR completed. |
| return nil | ||
| }) | ||
| for _, descriptor := range manifest.ManifestReferences() { | ||
| if _, ok := unmarkedManifests[descriptor.Digest]; ok { |
There was a problem hiding this comment.
we add it to the end of the list we're iterating over. Logically we're just executing a breadth first search.
In this way all manifests and blobs that are directly or indirectly referenced by a manifest are eventually marked.
I see this now, it's pretty elegant. Sorry for missing it at first 👍
Could you add a comment above line 111 bringing attention to the fact that manifests which are referenced by manifest lists are being appended to the end of the list so that they're processed before the loop ends?
|
|
||
| // Create random layers | ||
| randomLayers1, err := testutil.CreateRandomLayers(3) | ||
| randomLayers, err := testutil.CreateRandomLayers(12) |
There was a problem hiding this comment.
As far as ordering goes is there some easy way I can control what order manifests are enumerated?
Not really 😅
I think as long as we provide several randomly created lists with randomly created manifests per test we'll have this covered, otherwise the test will flake, or maybe even only occasionally pass (reverse-flake?). It's not perfect, but it should get caught relatively soon.
To test for this every time always, you'd need to manually build out a list and manifests that happen to produce digests that lexicographically sort before and after the lists digests. It's a little extra to be honest, but it's fine if you chose to have a test like this or not.
@SteveLasker good points, I think we should break up the work: #3402 (comment) |
|
@milosgajdos do you these changes could/should make it into the 2.8 milestone? |
|
Closing as this is pretty old by now. No idea if the original issue is still a thing |
Updates the Manifest and ManifestBuilder to distinguish between blob and manifest references. Uses this new interface to fix the garbage collection logic to do a proper transitive closure on references so that untagged sub manifests referenced by (tagged) manifest lists do not get removed even if remove-untagged is given to the garbage collector.
PR implementing the proposal in #3401
Resolves #3178