Skip to content

Commit

Permalink
Do not create tags for manifests when pushing by digest
Browse files Browse the repository at this point in the history
closes pulp#852
  • Loading branch information
lubosmj committed Jun 29, 2022
1 parent e54b7b8 commit 9637aa1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
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)]
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

0 comments on commit 9637aa1

Please sign in to comment.