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

Enable filtering by content #2992

Merged
merged 1 commit into from
Aug 22, 2022

Conversation

lubosmj
Copy link
Member

@lubosmj lubosmj commented Jul 20, 2022

closes #2952

lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 20, 2022
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 20, 2022
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 20, 2022
@lubosmj lubosmj force-pushed the distributions-content-in-2952 branch from 9288ada to eeeb3ae Compare July 20, 2022 14:53
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 20, 2022
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 20, 2022
Comment on lines 363 to 364
for dist in qs.exclude(repository=None).prefetch_related("repository__versions"):
versions_distributions[dist.repository.latest_version().pk].append(dist.pk)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this doesn't handle the auto-distribute feature properly. For plugins that serve directly from a repository it'll work fine, but for plugins that use a publication it might be incorrect. When a repository is set on the distribution and that plugin uses publications, the distribution will serve the latest and highest repo-version publication. So technically you could have a repository with 10 versions, but only one publication on version 5 and that would be the version served. There is also a constant on the distribution class that is used to determine if serving from the publication is appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha, I was not aware of that. Good to know.

@dkliban dkliban marked this pull request as draft July 26, 2022 13:08
@lubosmj lubosmj force-pushed the distributions-content-in-2952 branch from eeeb3ae to 8ee5667 Compare July 27, 2022 20:42
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 27, 2022
@lubosmj lubosmj marked this pull request as ready for review July 27, 2022 20:47
@lubosmj lubosmj requested a review from gerrod3 July 27, 2022 20:47
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 27, 2022
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 27, 2022
@lubosmj lubosmj force-pushed the distributions-content-in-2952 branch from 8ee5667 to 315aeee Compare July 28, 2022 07:47
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Jul 28, 2022


class DistributionWithContentFilter(Filter):
"""A Filter class enabling filtering by content units exposed by distributions."""
Copy link
Member

Choose a reason for hiding this comment

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

s/exposed/served

def __init__(self, *args, **kwargs):
"""Initialize a help message for the filter."""
kwargs.setdefault(
"help_text", _("Filter distributions based on the content present inside them")
Copy link
Member

Choose a reason for hiding this comment

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

based on the content served by them

@bmbouter
Copy link
Member

bmbouter commented Aug 9, 2022

@newswangerd please let us know what you think of this PR. Thank you!

@newswangerd
Copy link
Contributor

how do you use this? I assume it's GET /pulp/api/v3/distributions/?with_content=CONTENT_HREF, but that's returning an empty list for me.

@lubosmj lubosmj force-pushed the distributions-content-in-2952 branch from 315aeee to 390720a Compare August 12, 2022 19:07
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Aug 12, 2022
@lubosmj
Copy link
Member Author

lubosmj commented Aug 12, 2022

I have just realized that the old approach did not take into account distributions that do not serve content from publications. @newswangerd, would you mind testing your workflow once again?

Now, it should work:

(pulp) [vagrant@pulp3-source-fedora35 backup]$ http :24817/pulp/api/v3/distributions/?with_content=/pulp/api/v3/content/container/tags/39877fac-7f5b-48db-9bc1-7a80c6828174/
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, HEAD, OPTIONS
Connection: close
Content-Length: 52
Content-Type: application/json
Correlation-ID: 4b6e37dbf345415695f0d2861621f2ee
Date: Fri, 12 Aug 2022 19:10:21 GMT
Referrer-Policy: same-origin
Server: gunicorn
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "count": 0,
    "next": null,
    "previous": null,
    "results": []
}


(pulp) [vagrant@pulp3-source-fedora35 backup]$ http :24817/pulp/api/v3/distributions/?with_content=/pulp/api/v3/content/container/tags/4186495f-4fa9-4d7d-bab5-7fc379df7a03/
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, HEAD, OPTIONS
Connection: close
Content-Length: 563
Content-Type: application/json
Correlation-ID: 72250cf544a346d683c2680e5741514c
Date: Fri, 12 Aug 2022 19:10:32 GMT
Referrer-Policy: same-origin
Server: gunicorn
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "base_path": "repo-version",
            "base_url": "https://pulp3-source-fedora35.localhost.example.com/pulp/content/repo-version/",
            "content_guard": "/pulp/api/v3/contentguards/core/content_redirect/0470f5f0-6b9b-46c2-a4db-2205859c11b7/",
            "name": "rhel7-repository",
            "pulp_created": "2022-08-12T19:08:59.458302Z",
            "pulp_href": "/pulp/api/v3/distributions/container/container/1df93922-416e-44f3-a835-6d9276bb8991/",
            "pulp_labels": {},
            "repository": "/pulp/api/v3/repositories/container/container/d607ffc3-e695-4543-80e0-7386637574db/"
        }
    ]
}

Copy link
Contributor

@newswangerd newswangerd left a comment

Choose a reason for hiding this comment

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

Looks like it's working! Are you going to write functional tests for this?

@lubosmj
Copy link
Member Author

lubosmj commented Aug 15, 2022

Looks like it's working! Are you going to write functional tests for this?

Thanks! 🪂 There are functional tests written for this feature in pulp_file (pulp/pulp_file#778).

I am still worried about the performance implications of doing so many queries under the hood. Would anyone from the @pulp/core team take a look at this PR?

@bmbouter
Copy link
Member

I looked at this PR. Yes this could probably be optimized more, but I generally recommend to write it simple first and then come back later after the runtime is demonstrated to be an issue in practice for our users.

lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Aug 16, 2022
Copy link
Member

@bmbouter bmbouter left a comment

Choose a reason for hiding this comment

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

This looks good to me. We can optimize later. Thanks!

@ipanova
Copy link
Member

ipanova commented Aug 18, 2022

@lubosmj what i am doing wrong?

$ podman push  pulp3-source-fedora36.puffy.example.com/ipanova/busybox 
Getting image source signatures
Copying blob 7ad00cd55506 done  
Copying config 62aedd01bd done  
Writing manifest to image destination
Storing signatures
(pulp) [vagrant@pulp3-source-fedora36 docs]$ http "https://PULP3-SOURCE-FEDORA36.puffy.example.com/pulp/api/v3/distributions/" --auth admin:password
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, POST, HEAD, OPTIONS
Connection: keep-alive
Content-Length: 569
Content-Type: application/json
Correlation-ID: d67886553ab746e9b72cfb896170c24b
Date: Thu, 18 Aug 2022 11:35:05 GMT
Referrer-Policy: same-origin
Server: nginx
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "base_path": "ipanova/busybox",
            "base_url": "https://pulp3-source-fedora36.puffy.example.com/pulp/content/ipanova/busybox/",
            "content_guard": "/pulp/api/v3/contentguards/core/content_redirect/942a79d4-c1a0-4d0b-a81b-2446ec0a01c3/",
            "name": "ipanova/busybox",
            "pulp_created": "2022-08-18T11:34:48.284401Z",
            "pulp_href": "/pulp/api/v3/distributions/container/container/92fb9e64-a760-4be5-b2c9-6065db90a526/",
            "pulp_labels": {},
            "repository": "/pulp/api/v3/repositories/container/container-push/db20312f-4796-4b8f-81ec-189997fca558/"
        }
    ]
}


(pulp) [vagrant@pulp3-source-fedora36 docs]$ http "https://PULP3-SOURCE-FEDORA36.puffy.example.com/pulp/api/v3/content/container/manifests/?media_type=application/vnd.docker.distribution.manifest.v2%2Bjson" --auth admin:password
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, HEAD, OPTIONS
Connection: keep-alive
Content-Length: 635
Content-Type: application/json
Correlation-ID: 2a2d89462a7f407aa9512be3c29c60d7
Date: Thu, 18 Aug 2022 11:35:13 GMT
Referrer-Policy: same-origin
Server: nginx
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "artifact": "/pulp/api/v3/artifacts/ded44334-44db-43be-a16f-1a34170ab109/",
            "blobs": [
                "/pulp/api/v3/content/container/blobs/2fa53240-0411-4e48-bc51-accb58232265/"
            ],
            "config_blob": "/pulp/api/v3/content/container/blobs/33985973-9678-4d3d-af18-ddf2fe5a7b42/",
            "digest": "sha256:7989ac99935ab357c08d5a2b10c732ad1724477a9db27a056fd341d99c16f59a",
            "listed_manifests": [],
            "media_type": "application/vnd.docker.distribution.manifest.v2+json",
            "pulp_created": "2022-08-18T11:34:51.223190Z",
            "pulp_href": "/pulp/api/v3/content/container/manifests/9c312afd-13ea-40c3-b030-c79f1235cf6a/",
            "schema_version": 2
        }
    ]
}


(pulp) [vagrant@pulp3-source-fedora36 docs]$ http "https://PULP3-SOURCE-FEDORA36.puffy.example.com/pulp/api/v3/distributions/?with_content=/pulp/api/v3/content/container/manifests/9c312afd-13ea-40c3-b030-c79f1235cf6a/" --auth admin:password
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, POST, HEAD, OPTIONS
Connection: keep-alive
Content-Length: 52
Content-Type: application/json
Correlation-ID: 638fd27c6e38450fbfc761b99d0377e9
Date: Thu, 18 Aug 2022 11:35:24 GMT
Referrer-Policy: same-origin
Server: nginx
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "count": 0,
    "next": null,
    "previous": null,
    "results": []
}



(pulp) [vagrant@pulp3-source-fedora36 docs]$ http "https://PULP3-SOURCE-FEDORA36.puffy.example.com/pulp/api/v3/distributions/container/container/?with_content=/pulp/api/v3/content/container/manifests/9c312afd-13ea-40c3-b030-c79f1235cf6a/" --auth admin:password
HTTP/1.1 200 OK
Access-Control-Expose-Headers: Correlation-ID
Allow: GET, POST, HEAD, OPTIONS
Connection: keep-alive
Content-Length: 52
Content-Type: application/json
Correlation-ID: beaf7213f89646debcd41451f2ea4cbe
Date: Thu, 18 Aug 2022 11:35:58 GMT
Referrer-Policy: same-origin
Server: nginx
Vary: Accept, Cookie
X-Content-Type-Options: nosniff
X-Frame-Options: DENY

{
    "count": 0,
    "next": null,
    "previous": null,
    "results": []
}


@ipanova
Copy link
Member

ipanova commented Aug 18, 2022

@lubosmj i had old version of the PR, false alarm :)

lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Aug 22, 2022
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Aug 22, 2022
@lubosmj lubosmj force-pushed the distributions-content-in-2952 branch from 390720a to 16b40d5 Compare August 22, 2022 10:44
@lubosmj lubosmj marked this pull request as draft August 22, 2022 10:44
@lubosmj lubosmj marked this pull request as ready for review August 22, 2022 10:45
lubosmj added a commit to lubosmj/pulp_file that referenced this pull request Aug 22, 2022
@lubosmj lubosmj force-pushed the distributions-content-in-2952 branch from 16b40d5 to a5fd27a Compare August 22, 2022 12:47
@mdellweg mdellweg merged commit e6a42a9 into pulp:main Aug 22, 2022
mdellweg pushed a commit to pulp/pulp_file that referenced this pull request Aug 22, 2022
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.

As a user, I want to know which distributions some content is in.
6 participants