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

Protect distributed repo versions from deletion #4750

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

daviddavis
Copy link
Contributor

@daviddavis daviddavis commented Nov 21, 2023

This change protects repo versions from being deleted up if their content is being served by distributions.

fixes #2705

@daviddavis daviddavis changed the title Protect distributed repo versions from cleanup Protect distributed repo versions from deletion Nov 27, 2023
mdellweg
mdellweg previously approved these changes Nov 27, 2023
pulpcore/app/models/repository.py Show resolved Hide resolved
Copy link
Member

@ipanova ipanova left a 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

@daviddavis
Copy link
Contributor Author

@ipanova done.

Copy link
Member

@ipanova ipanova left a 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!

@daviddavis daviddavis force-pushed the fix2705 branch 2 times, most recently from 90ed9c1 to 63fd180 Compare December 5, 2023 13:51
@daviddavis
Copy link
Contributor Author

@ipanova @dralley thanks for the review. I think I've addressed everything.

daviddavis added a commit to daviddavis/pulp_deb that referenced this pull request Dec 6, 2023
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
ipanova
ipanova previously approved these changes Dec 6, 2023
daviddavis added a commit to daviddavis/pulp_python that referenced this pull request Dec 6, 2023
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
daviddavis added a commit to daviddavis/pulp_python that referenced this pull request Dec 6, 2023
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]
@ipanova ipanova self-requested a review December 7, 2023 12:04
ipanova
ipanova previously approved these changes Dec 7, 2023
)

if distro := Distribution.objects.filter(repository=self.pk).first():
if distro.cast().SERVE_FROM_PUBLICATION:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 :]:
Copy link
Member

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 $$N_{\textrm{rrv}} = 3$$ and $$RV_{n-2}$$ is protected, this will also protect $$RV_{n-3}$$. Or in other words, we aim to keep retain_repo_versions unprotected versions.

Copy link
Contributor Author

@daviddavis daviddavis Dec 7, 2023

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.

@ipanova ipanova merged commit c4e842c into pulp:main Dec 7, 2023
16 checks passed
daviddavis added a commit to daviddavis/pulp_deb that referenced this pull request Dec 11, 2023
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
lubosmj added a commit to lubosmj/pulp_ostree that referenced this pull request Jan 17, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.
lubosmj added a commit to lubosmj/pulp_ostree that referenced this pull request Jan 17, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.
lubosmj added a commit to lubosmj/pulp_ostree that referenced this pull request Jan 17, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.
lubosmj added a commit to lubosmj/pulp_ostree that referenced this pull request Jan 17, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.
lubosmj added a commit to pulp/pulp_ostree that referenced this pull request Jan 17, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.
patchback bot pushed a commit to pulp/pulp_ostree that referenced this pull request Jan 18, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.

(cherry picked from commit 4972e62)
lubosmj added a commit to pulp/pulp_ostree that referenced this pull request Jan 18, 2024
[noissue]

The workflow had to be adjusted because of the breaking change
introduced in pulp/pulpcore#4750.

(cherry picked from commit 4972e62)
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.

Protect (published) repository versions from deletion
5 participants