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

Catalog content discovery #2782

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

Conversation

eusebiu-constantin-petu-dbk
Copy link
Collaborator

What type of PR is this?

Which issue does this PR fix:

What does this PR do / Why do we need it:

If an issue # is not available please add repro steps and logs showing the issue:

Testing done on this change:

Automation added to e2e:

Will this break upgrades or downgrades?

Does this PR introduce any user-facing change?:


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 77.90698% with 38 lines in your changes missing coverage. Please review.

Project coverage is 91.86%. Comparing base (403fd4e) to head (6619b7b).
Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
pkg/extensions/sync/remote.go 27.77% 12 Missing and 1 partial ⚠️
pkg/api/routes.go 87.67% 6 Missing and 3 partials ⚠️
pkg/storage/imagestore/imagestore.go 86.44% 6 Missing and 2 partials ⚠️
pkg/storage/storage_controller.go 20.00% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2782      +/-   ##
==========================================
- Coverage   92.07%   91.86%   -0.22%     
==========================================
  Files         169      170       +1     
  Lines       30054    30260     +206     
==========================================
+ Hits        27672    27797     +125     
- Misses       1762     1833      +71     
- Partials      620      630      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

return catalog.Repositories, nil
repos := catalog.Repositories

link := header.Get("Link")
Copy link
Contributor

@andaaron andaaron Nov 15, 2024

Choose a reason for hiding this comment

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

So these repos return the "Link" even if we don't specify the query parameters in the request?

Copy link

@uvegla uvegla Nov 15, 2024

Choose a reason for hiding this comment

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

According to the specification: https://github.com/opencontainers/distribution-spec/blob/v1.1.0/spec.md#content-discovery

When n is zero, this endpoint MUST return an empty list, and MUST NOT include a Link header.

Since we are not setting it to 0, its probably not an issue. However it also states further down that:

A Link header MUST be included in the response when the descriptor list cannot be returned in a single manifest. Each response is an image index with different descriptors in the manifests field. The Link header MUST be set according to RFC5988 with the Relation Type rel="next".

So technically if there is only 1 page, it is not required to be in the response if I get it right. But according to https://pkg.go.dev/net/http#Header.Get an empty string is returned when there is no value associated with the requested header - or it does not exist. So I kinda guess this is safe.

@uvegla
Copy link

uvegla commented Nov 15, 2024

I gave it a try and found some problem I think. I updated the original issue: #2715 (comment) and will take a deeper look.

constants.RoutePrefix, constants.ExtCatalogPrefix)
if err != nil {
return []string{}, err
}

return catalog.Repositories, nil
repos := catalog.Repositories
Copy link

Choose a reason for hiding this comment

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

I think the problem of duplicating the 2nd page in place of the 1st page in the final list starts here. Further down catalog is passed down as a reference as well and the Repositories property is overwritten with the 2nd page result, thus repos get "overwritten" as well. Further iterations in the loop work, because at append(...) the list capacity need to expand and a new list is reserved in memory after that.

This way the behaviour is flaky. Its just a matter of luck to some extent when the list gets expanded and which page get lost or overwritten.

constants.RoutePrefix, constants.ExtCatalogPrefix)
if err != nil {
return []string{}, err
}

return catalog.Repositories, nil
repos := catalog.Repositories
Copy link

Choose a reason for hiding this comment

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

I think simply constructing an empty array and keep appending to that should do the trick:

Suggested change
repos := catalog.Repositories
var repos []string
repos = append(repos, catalog.Repositories...)

@rchincha
Copy link
Contributor

Also be mindful about access control - one may not have read access to all repos.

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.

4 participants