-
Notifications
You must be signed in to change notification settings - Fork 45
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
Distinguish between the nature of images #1532
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Incorporated a notion of container images' characteristics. Users can now filter manifests by their | ||
nature using the ``is_flatpak`` or ``is_bootable`` field on the corresponding Manifest endpoint. | ||
In addition to that, manifest's annotations and configuration labels were exposed on the same | ||
endpoint too. |
61 changes: 61 additions & 0 deletions
61
pulp_container/app/management/commands/init-image-nature.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from json.decoder import JSONDecodeError | ||
|
||
from gettext import gettext as _ | ||
|
||
from contextlib import suppress | ||
|
||
from django.core.exceptions import ObjectDoesNotExist | ||
from django.core.management import BaseCommand | ||
from django.core.paginator import Paginator | ||
|
||
from pulp_container.app.models import Manifest | ||
|
||
from pulp_container.constants import MEDIA_TYPE | ||
|
||
PAGE_CHUNK_SIZE = 1000 | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
A django management command to initialize flags describing the image nature. | ||
|
||
Manifests stored inside Pulp are of various natures. The nature of an image can be determined | ||
from JSON-formatted image manifest annotations or image configuration labels. These data are | ||
stored inside artifacts. | ||
|
||
This command reads data from the storage backend and populates the 'annotations', 'labels', | ||
'is_bootable', and 'is_flatpak' fields on the Manifest model. | ||
""" | ||
|
||
help = _(__doc__) | ||
|
||
def handle(self, *args, **options): | ||
manifests = Manifest.objects.exclude( | ||
media_type__in=[MEDIA_TYPE.MANIFEST_LIST, MEDIA_TYPE.INDEX_OCI] | ||
).order_by("pulp_id") | ||
self.update_manifests(manifests) | ||
|
||
manifest_lists = Manifest.objects.filter( | ||
media_type__in=[MEDIA_TYPE.MANIFEST_LIST, MEDIA_TYPE.INDEX_OCI] | ||
).order_by("pulp_id") | ||
self.update_manifests(manifest_lists) | ||
|
||
def update_manifests(self, manifests_qs): | ||
paginator = Paginator(manifests_qs, PAGE_CHUNK_SIZE) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can safely go to 1000 |
||
for page_num in paginator.page_range: | ||
manifests_to_update = [] | ||
|
||
page = paginator.page(page_num) | ||
for manifest in page.object_list: | ||
# suppress non-existing/already migrated artifacts and corrupted JSON files | ||
with suppress(ObjectDoesNotExist, JSONDecodeError): | ||
has_metadata = manifest.init_metadata() | ||
if has_metadata: | ||
manifests_to_update.append(manifest) | ||
|
||
if manifests_to_update: | ||
fields_to_update = ["annotations", "labels", "is_bootable", "is_flatpak"] | ||
manifests_qs.model.objects.bulk_update( | ||
manifests_to_update, | ||
fields_to_update, | ||
) |
46 changes: 46 additions & 0 deletions
46
pulp_container/app/migrations/0038_add_manifest_metadata_fields.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Generated by Django 4.2.10 on 2024-02-29 16:04 | ||
import warnings | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def print_warning_for_initializing_image_nature(apps, schema_editor): | ||
warnings.warn( | ||
"Run 'pulpcore-manager init-image-nature' to initialize and expose metadata (i.e., " | ||
"annotations and labels) for all manifests." | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('container', '0037_create_pull_through_cache_models'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='annotations', | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='is_bootable', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='is_flatpak', | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AddField( | ||
model_name='manifest', | ||
name='labels', | ||
field=models.JSONField(default=dict), | ||
), | ||
migrations.RunPython( | ||
code=print_warning_for_initializing_image_nature, | ||
reverse_code=migrations.RunPython.noop, | ||
elidable=True, | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please mention that you've exposed labels and annotations