-
Notifications
You must be signed in to change notification settings - Fork 116
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
Protect distributed repo versions from deletion #4750
Conversation
435d8a2
to
ae25495
Compare
b257111
to
acc380f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code does not work with plugins that do not have publications and repository/version can be served directly from distribution. Please update the code so it accounts for such plugins.
$ http DELETE https://puffy.example.com/pulp/api/v3/repositories/container/container/018bfb9a-ffa4-72e3-a9f4-f884f8719305/versions/1/ --auth admin:password
HTTP/1.1 500 Internal Server Error
Access-Control-Expose-Headers: Correlation-ID
Connection: keep-alive
Content-Length: 145
Content-Type: text/html; charset=utf-8
Correlation-ID: 0d33ccdcae8e431fbb34871ae3436d05
Cross-Origin-Opener-Policy: same-origin
Date: Mon, 27 Nov 2023 15:59:02 GMT
Referrer-Policy: same-origin
Server: nginx
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
<!doctype html>
<html lang="en">
<head>
<title>Server Error (500)</title>
</head>
<body>
<h1>Server Error (500)</h1><p></p>
</body>
</html>
pulpcore-api[92257]: if version in version.repository.protected_versions():
pulpcore-api[92257]: File "/pulpcore/pulpcore/app/models/repository.py", line 333, in protected_versions
pulpcore-api[92257]: latest_publication = publications.select_related("repository_version").latest(
pulpcore-api[92257]: File "/usr/local/lib/pulp/lib64/python3.10/site-packages/django/db/models/query.py", line 1045, in latest
pulpcore-api[92257]: return self.reverse()._earliest(*fields)
pulpcore-api[92257]: File "/usr/local/lib/pulp/lib64/python3.10/site-packages/django/db/models/query.py", line 1028, in _earliest
pulpcore-api[92257]: return obj.get()
pulpcore-api[92257]: File "/usr/local/lib/pulp/lib64/python3.10/site-packages/django/db/models/query.py", line 637, in get
pulpcore-api[92257]: raise self.model.DoesNotExist(
pulpcore-api[92257]: pulpcore.app.models.publication.Publication.DoesNotExist: Publication matching query does not exist.
^C
@ipanova done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@daviddavis Left some linguistic suggestions to account for plugins that do not have publications and one technical one. Otherwise it looks good, thank you!
90ed9c1
to
63fd180
Compare
I believe this prevents the content app from serving unpublished content when a repo is set on a distribution: pulp/pulpcore@27a0dc7 Also, this setting will be used to protect repo versions once the repo version protection work is merged: pulp/pulpcore#4750 fixes pulp#976
I don't know if this is strictly required since pulp_python defines its own content handler function but SERVE_FROM_PUBLICATION ought to be set from a technical correctness standpoint. Also future work might expect it to be set such as the repo version protection PR I have open against pulpcore: pulp/pulpcore#4750
I don't know if this is strictly required since pulp_python defines its own content handler function but SERVE_FROM_PUBLICATION ought to be set from a technical correctness standpoint. Also future work might expect it to be set such as the repo version protection PR I have open against pulpcore: pulp/pulpcore#4750 [noissue]
pulpcore/app/models/repository.py
Outdated
) | ||
|
||
if distro := Distribution.objects.filter(repository=self.pk).first(): | ||
if distro.cast().SERVE_FROM_PUBLICATION: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if distro.cast().SERVE_FROM_PUBLICATION: | |
if distro.detail_model().SERVE_FROM_PUBLICATION: |
This change protects repo versions from being deleted if they are being used to distribute content. It also protects repo versions from being cleaned up by the retain repo versions code. fixes pulp#2705
]: | ||
# Consider only completed versions that aren't protected for cleanup | ||
versions = self.versions.complete().exclude(pk__in=self.protected_versions()) | ||
for version in versions.order_by("-number")[self.retain_repo_versions :]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my understanding. This logic will not only protect these versions, but also not consider them for counting when selecting the last retain_repo_versions
for not deleting.
So if retain_repo_versions
unprotected versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, as I would say, protected repo versions are excluded fromretain_repo_versions
.
And I think this makes sense. Otherwise, if retain_repo_versions
was 1 and you already had 1 protected version, then if you created another version, it would immediately get cleaned up.
I believe this prevents the content app from serving unpublished content when a repo is set on a distribution: pulp/pulpcore@27a0dc7 Also, this setting will be used to protect repo versions once the repo version protection work is merged: pulp/pulpcore#4750 fixes pulp#976
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750.
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750.
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750.
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750.
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750.
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750. (cherry picked from commit 4972e62)
[noissue] The workflow had to be adjusted because of the breaking change introduced in pulp/pulpcore#4750. (cherry picked from commit 4972e62)
This change protects repo versions from being deleted up if their content is being served by distributions.
fixes #2705