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

referenceutil cleanup #3542

Merged
merged 2 commits into from
Oct 17, 2024
Merged

referenceutil cleanup #3542

merged 2 commits into from
Oct 17, 2024

Conversation

apostasie
Copy link
Contributor

@apostasie apostasie commented Oct 14, 2024

This is a first step at enhancing and fixing issues in imgutil (#3531) - focusing specifically on referenceutil.

We currently use a mix of nerdctl/referenceutil and github.com/distribution/reference as far as I can tell without much consistency.

We obviously introduced our own "helpers" in referenceutil (primarily to accommodate for ipfs images), sometimes with identical names to the upstream API:

  • ParseDockerRef
  • ParseAny
  • ParseAnyReference
  • ParseIPFSRefWithScheme

... in addition to the existing:

  • ParseNormalizedNamed
  • ParseDockerRef
  • ParseAnyReference
  • etc

This abundance of methods that are doing almost exactly the same thing - with subtle differences - seems hard to justify - be it on our side, or on the distribution side.
The distribution ref code was designed ten years ago now (fall 2014), with different notions about images names, backward compatibility requirements with the old python registry (prior to the go implem), and quite frankly, a questionable design (the whole "cast it to XYZ if you want to access properties"), and a number of embarrassing bugs (specifically around tags+digests), that IIRC have been creeping far out (into buildkit), causing hard-to-figure-out caching issues.
It seems like reference has been barely touched since then.

At this point, it is doubtful that anyone could say top of the head what are the differences between all of these or what are the ramifications if you use one rather than the other.

While this is challenging already for long-timers (I certainly do need to read the source multiple times every time I touch these), it is just plain bad for newcomers.

Add to that normalization concerns, the familiarization mechanisms that work only post normalization. This is just not a good API.

Finally, we seem to parse these references multiples times during the same flow as we pass strings around - in a context where distribution/reference is notoriously hungry for memory.

This PR is suggesting that we stop using distributionref entirely (eg: except inside referenceutil obviously), and replace all of our stuff with a new, single method - Parse - and one struct.

The first commit is the implementation of the new referenceutil + tests.
The second commit adapts the codebase - this is not too aggressive of a refactor, and we might want to further clean this up to reduce duplicate parsing - but that would require changing methods signatures, which this PR tries to avoid.

Let me know your thoughts - especially if I am missing something here that would not be in the tests, and that would justify specialized parsing in certain cases.

@apostasie apostasie force-pushed the rewrite-refutils branch 2 times, most recently from 91b69c4 to 0e9f388 Compare October 15, 2024 00:23
Signed-off-by: apostasie <[email protected]>
@apostasie apostasie force-pushed the rewrite-refutils branch 2 times, most recently from 3b5eac2 to c937f3b Compare October 15, 2024 01:13
@apostasie apostasie changed the title [IGNORE] referenceutil testing referenceutil cleanup Oct 15, 2024
@@ -235,19 +235,19 @@ func generateBuildctlArgs(ctx context.Context, client *containerd.Client, option
}
if tags = strutil.DedupeStrSlice(options.Tag); len(tags) > 0 {
ref := tags[0]
named, err := distributionref.ParseNormalizedNamed(ref)
parsedReference, err := referenceutil.Parse(ref)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Harmonizing variables names from named, canonicalRef, etc, to just the same parsedReference.

if err != nil {
return nil, "", "", fmt.Errorf("invalid identifier %s: %w", identifier, err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Useless. The underlying implementation does return that already.

@@ -70,49 +70,47 @@ Properties:
return imagesCommand
}

func processImageListOptions(cmd *cobra.Command, args []string) (types.ImageListOptions, error) {
func processImageListOptions(cmd *cobra.Command, args []string) (*types.ImageListOptions, 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.

Change the signature here so that we can return nil instead of types.ImageListOptions{}.

}
filters = append(filters, fmt.Sprintf("name==%s", canonicalRef.String()))
filters = append(filters, fmt.Sprintf("name==%s", args[0]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This does not seem to serve a purpose.
Am I missing something here?

@apostasie apostasie marked this pull request as ready for review October 15, 2024 01:56
@@ -61,7 +61,7 @@ type PullMode = string
// GetExistingImage returns the specified image if exists in containerd. Return errdefs.NotFound() if not exists.
func GetExistingImage(ctx context.Context, client *containerd.Client, snapshotter, rawRef string, platform ocispec.Platform) (*EnsuredImage, error) {
var res *EnsuredImage
imagewalker := &imagewalker.ImageWalker{
imgwalker := &imagewalker.ImageWalker{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not shadowing import.

@AkihiroSuda AkihiroSuda requested a review from ktock October 15, 2024 04:25
@AkihiroSuda AkihiroSuda added this to the v2.0.0 milestone Oct 15, 2024
@AkihiroSuda AkihiroSuda requested a review from a team October 17, 2024 05:57
@ktock ktock merged commit f240e58 into containerd:main Oct 17, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants