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

Add DockerHub implementation for send_tags #6580

Merged
merged 2 commits into from Aug 9, 2023
Merged

Add DockerHub implementation for send_tags #6580

merged 2 commits into from Aug 9, 2023

Conversation

absoludity
Copy link
Contributor

@absoludity absoludity commented Aug 7, 2023

Description of the change

Adds the implementation for retrieving and sending tags for dockerhub repositories.

Benefits

Enables an initial integration to be tested.

Possible drawbacks

Applicable issues

Additional information

IRL test:

grpcurl -plaintext -proto ./proto/ocicatalog.proto -d '{ "repository": {"registry": "registry-1.docker.io", "namespace": "bitnamicharts", "name": "zookeeper" }}' 0.0.0.0:50001 ocicatalog.OCICatalog.ListTagsForRepository
{
  "name": "11.4.10"
}
{
  "name": "11.4.9"
}
{
  "name": "11.4.8"
}
{
  "name": "11.4.7"
}
{
  "name": "11.4.6"
}
{
  "name": "11.4.5"
}
{
  "name": "11.4.4"
}
{
  "name": "11.4.3"
}
{
  "name": "11.4.2"
}
{
  "name": "11.4.1"
}
{
  "name": "11.3.2"
}
{
  "name": "11.3.1"
}
{
  "name": "11.2.1"
}
{
  "name": "11.1.6"
}
{
  "name": "11.1.5"
}
{
  "name": "11.1.4"
}
{
  "name": "11.1.3"
}
{
  "name": "11.1.2"
}
{
  "name": "11.1.1"
}
{
  "name": "11.0.3"
}
{
  "name": "11.0.2"
}
{
  "name": "11.0.1"
}
{
  "name": "11.0.0"
}
{
  "name": "10.2.5"
}
{
  "name": "10.2.4"
}
{
  "name": "10.2.3"
}

Signed-off-by: Michael Nelson <minelson@vmware.com>
@netlify
Copy link

netlify bot commented Aug 7, 2023

Deploy Preview for kubeapps-dev ready!

Name Link
🔨 Latest commit 0add7d4
🔍 Latest deploy log https://app.netlify.com/sites/kubeapps-dev/deploys/64d2a694b9e5a100094b7cb0
😎 Deploy Preview https://deploy-preview-6580--kubeapps-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@absoludity absoludity marked this pull request as ready for review August 7, 2023 20:43
Copy link
Contributor

@antgamdia antgamdia left a comment

Choose a reason for hiding this comment

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

Thanks!

Comment on lines +227 to +229
// For now we use a default page size.
url.query_pairs_mut()
.append_pair("page_size", &format!("{}", DEFAULT_PAGE_SIZE));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to confirm, are we only fetching (DEFAULT_PAGE_SIZE=100) elements for now, aren't we? I mean, there I don't see any pagination logic here. It seems Docker is using a Link header to let the client know about the next page (source), but we are not using it at the moment. No?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just the current default pagesize for the requests we make to dockerhub (ie. how big are the batches that we request), so will affect performance only (number of requests required to exhaust the result). It's not limiting how many results we get at all (ie. if I set this to 10, then the loop will fetch the results in batches of 10).

The gRPC API that we provide streams the result back, so no pagination required.

}))
.await
.unwrap();
async fn send_tags(&self, tx: mpsc::Sender<Result<Tag, Status>>, request: &ListTagsRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

For what is worth, (I guess you already know it, but just in case), here is the "official" (albeit tagged as experimental) DockerHub client: https://github.com/docker/hub-tool/blob/main/pkg/hub/tags.go#L61

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, as you can see in their (go) client, they need to collect all the page results (appending to the array) before returning the result. In our case, we're wanting to stream the results back (via gRPC stream) while they're collected, which is why I'm using these send_tags and send_repositories, to show the results down a channel (which we can buffer as needed) and continue fetching.

BTW: interesting to see they use the same default page size :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Neat! Thanks for the explanation!

Comment on lines +178 to +179
if response.next.is_some() {
url = reqwest::Url::parse(&response.next.unwrap()).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah - reading it twice, perhaps this is the pagination logic? If so, I would add some comments just for our future ourselves to understand 😅

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 is us using the pagination of the dockerhub API, yes - requesting the next page if response.next is defined. I'll add a comment to that effect.

@@ -44,7 +60,7 @@ impl OCICatalogSender for DockerHubAPI {
tx: mpsc::Sender<Result<Repository, Status>>,
request: &ListRepositoriesRequest,
) {
let mut url = url_for_request(request);
let mut url = url_for_request_repositories(request);

let client = reqwest::Client::builder().build().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Not now, but given the DockerHub rate limits, perhaps it is worthwhile adding sth like: https://crates.io/crates/governor for better handling it on the client side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that'd be great to add in the future if we find we're hitting rate limits (I'll be testing this using the bitnami catalog, which is probably on the larger side of OCI helm registries).

Signed-off-by: Michael Nelson <minelson@vmware.com>
@absoludity absoludity merged commit 1abcbc4 into main Aug 9, 2023
39 checks passed
@absoludity absoludity deleted the 6263-tag-list branch August 9, 2023 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants