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

Do not create tags for manifests when pushing by digest #884

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/852.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug that caused untagged manifests to be tagged by their digest during the push operation.
30 changes: 19 additions & 11 deletions pulp_container/app/registry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,23 +988,31 @@ def put(self, request, path, pk=None):
objs=thru, ignore_conflicts=True, batch_size=1000
)

tag = models.Tag(name=pk, tagged_manifest=manifest)
try:
tag.save()
except IntegrityError:
tag = models.Tag.objects.get(name=tag.name, tagged_manifest=manifest)
tag.touch()
# a manifest cannot tagged by its digest - an identifier specified in the 'pk' parameter
if not pk.startswith("sha256:"):
tag = models.Tag(name=pk, tagged_manifest=manifest)
try:
tag.save()
except IntegrityError:
tag = models.Tag.objects.get(name=tag.name, tagged_manifest=manifest)
tag.touch()

tags_to_remove = models.Tag.objects.filter(
pk__in=repository.latest_version().content.all(), name=tag
).exclude(tagged_manifest=manifest)
add_content_units = [str(tag.pk), str(manifest.pk)]
Copy link
Member

@ipanova ipanova Jul 1, 2022

Choose a reason for hiding this comment

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

how about you define add_content_units = [str(manifest.pk)] and remove_content_units= [] empty lists before line 992 and then you just append tag.pk

Copy link
Member

Choose a reason for hiding this comment

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

this way you will avoid the else block

remove_content_units = [str(pk) for pk in tags_to_remove.values_list("pk")]
else:
add_content_units = [str(manifest.pk)]
remove_content_units = []

tags_to_remove = models.Tag.objects.filter(
pk__in=repository.latest_version().content.all(), name=tag
).exclude(tagged_manifest=manifest)
dispatched_task = dispatch(
add_and_remove,
exclusive_resources=[repository],
kwargs={
"repository_pk": str(repository.pk),
"add_content_units": [str(tag.pk), str(manifest.pk)],
"remove_content_units": [str(pk) for pk in tags_to_remove.values_list("pk")],
"add_content_units": add_content_units,
"remove_content_units": remove_content_units,
},
)

Expand Down
12 changes: 10 additions & 2 deletions pulp_container/tests/functional/api/test_push_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,11 @@ def test_push_manifest_list_v2s2(self):
self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

repo_version = self.pushrepository_api.read(distribution.repository).latest_version_href
latest_tag = self.tags_api.list(repository_version_added=repo_version).results[0]

tags = self.tags_api.list(repository_version=repo_version).results
assert len(tags) == 1

latest_tag = tags[0]
assert latest_tag.name == self.v2s2_tag

manifest_list = self.manifests_api.read(latest_tag.tagged_manifest)
Expand Down Expand Up @@ -500,7 +504,11 @@ def test_push_manifest_list_oci(self):
self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

repo_version = self.pushrepository_api.read(distribution.repository).latest_version_href
latest_tag = self.tags_api.list(repository_version_added=repo_version).results[0]

tags = self.tags_api.list(repository_version=repo_version).results
assert len(tags) == 1

latest_tag = tags[0]
assert latest_tag.name == self.oci_tag

manifest_list = self.manifests_api.read(latest_tag.tagged_manifest)
Expand Down