Skip to content

Commit

Permalink
Remove the manifest schema conversion machinery
Browse files Browse the repository at this point in the history
closes: pulp#1509
  • Loading branch information
git-hyagi committed Feb 29, 2024
1 parent 710ca3f commit 8958ff7
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 526 deletions.
4 changes: 4 additions & 0 deletions CHANGES/1509.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Removed the manifest schema conversion machinery. If the manifest is stored locally in the newer
format and old clients request v2 schema1 manifest they will receive 404. v2 schema1 manifest is
still going to be mirrored from remote source during sync if available and passed to the old clients
on the request.
6 changes: 2 additions & 4 deletions docs/workflows/host.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ Docker Output::

.. note::
When using a container client that cannot handle requested manifests in the new format
(schema 2), the manifests are rewritten into the old format (schema 1) on-the-fly by Pulp.
In general, the automatic conversion cannot be performed when the content is not available
in the storage. Therefore, it may be successful only if the content was previously synced
with the ``immediate`` policy.
(schema 2), the manifests will **not** be rewritten into the old format (schema 1) and Pulp will
raise a 404 (HTTPNOTFOUND) error.


Pull-Through Caching
Expand Down
14 changes: 11 additions & 3 deletions pulp_container/app/redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.http import Http404
from django.shortcuts import redirect

from pulp_container.app.exceptions import ManifestNotFound
from pulp_container.app.utils import get_accepted_media_types
from pulp_container.constants import BLOB_CONTENT_TYPE, MEDIA_TYPE

Expand Down Expand Up @@ -38,6 +39,13 @@ def issue_tag_redirect(self, tag):
"""
Issue a redirect for the passed tag.
"""
manifest_media_type = tag.tagged_manifest.media_type
if (
manifest_media_type not in get_accepted_media_types(self.request.headers)
and manifest_media_type != MEDIA_TYPE.MANIFEST_V1
):
raise ManifestNotFound(reference=tag.name)

return self.redirect_to_content_app("manifests", tag.name)

def issue_manifest_redirect(self, manifest):
Expand All @@ -60,7 +68,8 @@ class S3StorageRedirects(CommonRedirects):

def issue_tag_redirect(self, tag):
"""
Issue a redirect or perform a schema conversion if an accepted media type requires it.
Issue a redirect if an accepted media type requires it or return not found if manifest
version is not supported.
"""
manifest_media_type = tag.tagged_manifest.media_type
if manifest_media_type in get_accepted_media_types(self.request.headers):
Expand All @@ -70,8 +79,7 @@ def issue_tag_redirect(self, tag):
tag.name, tag.tagged_manifest, MEDIA_TYPE.MANIFEST_V1_SIGNED
)
else:
# execute the schema conversion
return self.redirect_to_content_app("manifests", tag.name)
raise ManifestNotFound(reference=tag.name)

def issue_manifest_redirect(self, manifest):
"""
Expand Down
39 changes: 2 additions & 37 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

from pulp_container.app.cache import RegistryContentCache
from pulp_container.app.models import ContainerDistribution, Tag, Blob, Manifest, BlobManifest
from pulp_container.app.schema_convert import Schema2toSchema1ConverterWrapper
from pulp_container.app.tasks import download_image_data
from pulp_container.app.utils import (
calculate_digest,
Expand Down Expand Up @@ -212,8 +211,8 @@ async def get_tag(self, request):
}
return await self.dispatch_tag(request, tag, response_headers)

# convert if necessary
return await Registry.dispatch_converted_schema(tag, accepted_media_types, path)
# return 404 in case the client is requesting docker manifest v2 schema 1
raise PathNotResolved(tag_name)

async def dispatch_tag(self, request, tag, response_headers):
"""
Expand All @@ -239,40 +238,6 @@ async def dispatch_tag(self, request, tag, response_headers):
else:
return await Registry._dispatch(artifact, response_headers)

@staticmethod
async def dispatch_converted_schema(tag, accepted_media_types, path):
"""
Convert a manifest from the format schema 2 to the format schema 1.
The format is converted on-the-go and created resources are not stored for further uses.
The conversion is made after each request which does not accept the format for schema 2.
Args:
tag: A tag object which contains reference to tagged manifests and config blobs.
accepted_media_types: Accepted media types declared in the accept header.
path: A path of a repository.
Raises:
PathNotResolved: There was not found a valid conversion for the specified tag.
Returns:
:class:`aiohttp.web.StreamResponse` or :class:`aiohttp.web.Response`: The response
streamed back to the client.
"""
schema1_converter = Schema2toSchema1ConverterWrapper(tag, accepted_media_types, path)
try:
result = await sync_to_async(schema1_converter.convert)()
except RuntimeError:
raise PathNotResolved(tag.name)

response_headers = {
"Docker-Content-Digest": result.digest,
"Content-Type": result.content_type,
"Docker-Distribution-API-Version": "registry/2.0",
}
return web.Response(text=result.text, headers=response_headers)

@RegistryContentCache(
base_key=lambda req, cac: Registry.find_base_path_cached(req, cac),
auth=lambda req, cac, bk: Registry.auth_cached(req, cac, bk),
Expand Down
Loading

0 comments on commit 8958ff7

Please sign in to comment.